3.4 KiB
id, title, status, wave, parallelism, depends_on, plan, spec
| id | title | status | wave | parallelism | depends_on | plan | spec | |
|---|---|---|---|---|---|---|---|---|
| 02-queue-prompt-on-failed-launch | Queue the auto-start prompt when a CREATED launch fails | done | 2 | sequential |
|
plan.md | ../../specs/tasks/requirements/workflow-step-agent-start-ownership.md |
Task 02: Queue the auto-start prompt when a CREATED launch fails
Scope corrected during implementation. The incident's failure is asynchronous —
startAgentOnExistingWorkspacecallsstartAgentProcessAsyncand returnsnil, soStartCreatedSessionreturned no error and this branch was never reached in production. The synchronous branch is still reachable and still drops prompts, but only when there is no in-memory execution (the post-restart shape) and the fullLaunchAgentpath runs. This task closes that case; the async gap is recorded under the spec's Known gap and needs its own cycle.
Acceptance
- When
autoStartStepPrompt'sCREATEDbranch gets a busy or already-running error fromStartCreatedSession, the already-recorded prompt is queued for the session viaqueueAutoStartPrompt, passinguserMsgRecordedso the drain does not duplicate the chat row. - Permanent rejections (Office scheduler guard, missing agent profile) are not queued — nothing would drain them.
- The existing
requeueTaken()restoration of a taken handoff message is preserved. - The original error is still returned, so session
FAILEDtransition, error surfacing, and the caller's behavior are unchanged. - A failure to queue is logged and does not mask the original launch error.
- The queued prompt is recoverable by the existing
handleAgentBootReadydrain — no new drain path is introduced.
Regression test
Add to apps/backend/internal/orchestrator/event_handlers_duplicate_autostart_test.go,
alongside TestAutoStartTransientError_BootReadyDrainsOrphanedQueue:
- Red first. A
CREATEDsession whoseStartCreatedSessionfails; assert a queued message exists for the session afterward. Before the fix the queue is empty and the prompt is only a chat row. - Assert the returned error is the launch error, unchanged.
- Extend through the existing boot-ready drain to show the prompt is delivered once the session becomes promptable, mirroring the sibling test's end-to-end shape.
Verification
(cd apps/backend && go test ./internal/orchestrator/ -race -run 'TestAutoStart|TestProcessOnEnterResetAgentContext')
(cd apps/backend && go test ./internal/orchestrator/... -race)
(cd apps/backend && golangci-lint run ./... --new-from-rev=origin/main --timeout=5m)
Files Likely Touched
apps/backend/internal/orchestrator/event_handlers_workflow.goapps/backend/internal/orchestrator/event_handlers_duplicate_autostart_test.go
Dependencies
Task 01 (same file; edit ordering only).
Inputs
- Spec scenario 5 and the matching failure mode.
- The
CREATEDbranch atevent_handlers_workflow.go:1680. - The precedent in the same function's
PromptTaskretry loop: theisAgentAlreadyRunningErrorbranch callsqueueAutoStartPromptwith a comment describing this exact situation. handleAgentBootReady's drain, pinned byTestAutoStartTransientError_BootReadyDrainsOrphanedQueue.
Output Contract
The CREATED branch queues before returning its error. No signature change, no
new queue mechanism.