Commit emergency insert + cascade reschedule
commitEmergencyRescheduleAtomically commit an emergency reschedule by inserting a priority job into a technician's route and rescheduling displaced jobs as previewed.
Instructions
Commit emergency insert + cascade reschedule
Applies the cascade previewed by /emergency/preview: assigns the emergency job to the technician and pushes the displaced jobs back (or, with displacement_mode=reassign, re-staffs them onto their previewed alternates first), atomically. Supports Idempotency-Key. The server recomputes the plan under a lock and fences each job on its status_version — if anything changed since the preview it returns 409 EMERGENCY_RESCHEDULE_PLAN_DRIFTED (re-preview). Same body as preview + optional emergency_expected_version. Isolated feature (see EMERGENCY_RESCHEDULE_DESIGN.md).
409 NEXT STEPS: EMERGENCY_RESCHEDULE_PLAN_DRIFTED — the schedule changed between your preview and this commit (another booking/move won a lane): call /preview again, show the fresh plan, then commit. EMERGENCY_RESCHEDULE_SLOT_OCCUPIED — landing window blocked by an immovable anchor (P0/crew/multi-day): another tech or time. Other codes — same remedies as /candidates.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| mode | Yes | Cascade mode: overtime | next_day (must match the preview). | |
| start_at | Yes | Desired start — business-local naive datetime, no offset. Must be in the future and match the preview. | |
| technician_id | Yes | Target technician (must belong to the business). | |
| idempotency_key | No | Unique key making retries safe: a repeat send with the same key replays the original response (header Idempotent-Replayed: true) instead of re-running the operation. Reusing a key with a different body returns 422 IDEMPOTENCY_KEY_REUSE. (sent as the Idempotency-Key header) | |
| emergency_job_id | Yes | ID of the P0 job to insert. | |
| displacement_mode | No | Fate of displaced jobs: reschedule (default) or reassign — must match the preview. | |
| expected_move_ids | No | ExpectedMoveIDs — the displaced job IDs the preview returned (echo BOTH data.days[].moves[].job_id AND data.reassignments[].job_id). RECOMMENDED: if the recomputed cascade would touch a different set (a job booked onto the lane since the preview), the commit is rejected with EMERGENCY_RESCHEDULE_PLAN_DRIFTED instead of displacing a job the coordinator never saw. Omit to opt out. | |
| emergency_expected_version | No | Optimistic-lock fence from the previewed job (0 = fence on the server-read version). |