4.8 KiB
4.8 KiB
id, title, status, wave, depends_on, plan, spec
| id | title | status | wave | depends_on | plan | spec |
|---|---|---|---|---|---|---|
| 01-fifo-send-now-arbitration | Arbitrate FIFO and Send Now handoff | done | 1 | plan.md | ../../specs/ui/requirements/message-queue-send-now.md |
Task 01: Arbitrate FIFO and Send Now handoff
Acceptance
- A normal FIFO drain registers a per-session handoff with an explicit pre-acceptance phase and an accepted/terminal phase.
- Send Now, under the existing cancellation guard, can supersede only the pre-acceptance FIFO handoff, restore its exact ordinary or durable source, and claim the requested exact row or all-scope snapshot without partial mutation.
- With two queued ordinary messages at the ready boundary, header Send Now produces one aggregate replacement prompt containing both bodies in FIFO order; the losing FIFO worker produces no duplicate visible message, workflow turn-start effect, or prompt.
- An accepted FIFO handoff returns the existing
send_now_conflictbehavior; it does not cancel or duplicate the successor, and remaining queue entries remain authoritative. - Existing normal FIFO, explicit Cancel, peer-interrupt, lifecycle reservation, retry, captured-turn, and cancellation-progress behavior remains unchanged outside the new pre-acceptance arbitration window.
Verification
cd apps/backend
go test -race ./internal/orchestrator -run 'Test(SendNow|QueuedDispatch|ExecuteQueuedMessage)' -count=1
go test -race ./internal/orchestrator/messagequeue -run 'Test.*SendNow' -count=1
Files Likely Touched
apps/backend/internal/orchestrator/service.goapps/backend/internal/orchestrator/event_handlers_workflow.goapps/backend/internal/orchestrator/event_handlers_agent.goapps/backend/internal/orchestrator/task_operations.goapps/backend/internal/orchestrator/queue_send_now.goapps/backend/internal/orchestrator/queue_send_now_test.goapps/backend/internal/orchestrator/event_handlers_queue_test.goor a new focusedqueued_dispatch_arbitration_test.go
Dependencies
None.
Parallelism
Sequential. The task changes the shared per-session dispatch ownership mechanism and must be implemented and verified as one concurrency surface.
Inputs
- Amended spec scenarios: FIFO reservation superseded before prompt acceptance, and accepted FIFO handoff failing closed.
apps/backend/internal/orchestrator/queue_send_now.gocurrent conflict gate.dispatchTakenQueuedMessageandexecuteQueuedMessageinevent_handlers_workflow.go/event_handlers_agent.go.claimSessionRunningForPromptand the existing dispatch token checks intask_operations.go.- Existing queue lifecycle and cancellation tests that use
markQueuedDispatchInFlight.
TDD Sequence
- Add a deterministic test barrier after the FIFO source is reserved but before the worker claims prompt ownership. Trigger header Send Now with two queued sources and assert the current implementation returns the conflict or otherwise fails the new expected one-prompt invariant (RED).
- Add the accepted-handoff race case and assert the existing fail-closed contract, plus a baseline normal FIFO case so the arbitration does not turn every automatic drain into a Send Now claim.
- Introduce the reservation state/ownership transition and move ordinary message recording and turn-start effects behind the worker's guarded ownership claim.
- Implement Send Now supersession/restoration for only the pre-acceptance state, then route the winner through the existing exact claim and aggregate dispatch path.
- Add durable lifecycle and stale-worker assertions, run the focused
-racecommands, and confirm no marker cleanup path can remove a newer owner.
Output Contract
Report the deterministic RED failure, the reservation states and guarded
ownership boundary, restoration behavior for ordinary/durable rows, exact
focused command results, files changed, and any remaining race or blocker.
Mark this task done and update its plan checkbox only after the tests pass.
Results
- RED reproduced the reported conflict before the fix: the pending FIFO
handoff test returned
send-now operation is already in progress. - Added a typed per-session reservation with pending, accepted, and superseded
phases. The FIFO worker claims the reservation under
cancelInFlightbefore transcript or workflow side effects; Send Now can supersede only pending FIFO work and restores its exact source first. - Durable lifecycle restoration clears only the transient reservation; the aggregate Send Now claim remains responsible for final acknowledgement. The stale FIFO worker is covered by a synchronous no-requeue assertion.
- Focused command results: 25 orchestrator tests passed with
-race, and 11 messagequeue Send Now tests passed with-race. - Broader queue/cancellation command result: 179 tests passed with
-race.