Spawn: handle the long-tail failure codes (project resolution, session mode, chat driver, workspace provisioning)
Part of #3873. Closes the remaining ~9% of spawn failures not covered by #3941 / #3942 / #3943, so 100% of failure reasons are tracked.
Remaining codes (30d volumes), each should be handled with a clear pre-check or actionable message instead of a raw failure:
- [ ] PROJECT_NOT_RESOLVABLE (111) — worker spawned for a project that can't be resolved (gone/renamed). Resolve or skip with a clear reason.
- [ ] SESSION_MODE_UNSUPPORTED (144) — the chosen session mode isn't supported by that harness. Gate the mode by harness capability up front.
- [ ] CHAT_AUTH_REQUIRED (16) — chat driver needs auth. Prompt to authenticate before spawn.
- [ ] CHAT_DRIVER_INCOMPATIBLE (14) / CHAT_DRIVER_UNAVAILABLE (2) — chat driver mismatch/unavailable. Validate driver compatibility up front.
- [ ] WORKSPACE_PROVISION_FAILED (30) / WORKSPACE_CWD_MISMATCH (1) — workspace/worktree provisioning failure. Surface the reason; retry/repair where safe.
- [ ] SKILL_NOT_FOUND (4) — referenced skill missing. Clear message naming the skill.
Together with #3941 (agent/runtime), #3942 (git branch), #3943 (internal), this brings spawn-failure reason coverage to 100%.
Audited against current main (b9601f38c). All active failure classes listed here are now covered, so adding another implementation would duplicate existing behavior:
PROJECT_NOT_RESOLVABLE: project resolution happens before session creation; the service maps it to an invalid request with explicitao project addguidance. PR-claim resolution uses the same actionable code.SESSION_MODE_UNSUPPORTED: explicit Chat requests runPreflightChatbefore any durable session/worktree is created. Capability errors include missing capabilities and allowed approval modes; default (non-explicit) Chat safely falls back to TUI. Desktop preserves the structured error and offers the TUI recovery path.CHAT_AUTH_REQUIRED,CHAT_DRIVER_INCOMPATIBLE,CHAT_DRIVER_UNAVAILABLE: all run through the same pre-spawn Chat probe. Explicit Chat fails before durable state with a typed code; default Chat falls back to TUI. Auth copy tells the user to authenticate, while driver adapters retain install/version/launch detail.WORKSPACE_PROVISION_FAILED: provisioning is a named spawn stage, preserves the underlying command/path reason in the API message, and rolls back the seed row/workspace on failure.WORKSPACE_CWD_MISMATCH: runtime adapters emit the typed sentinel with actual and expected paths; the service preserves it as a conflict response.SKILL_NOT_FOUND: this code no longer exists in the current spawn architecture and no spawn path emits it. Chat skill enumeration is a separate post-spawn capability withErrSkillsUnsupported, not a referenced-skill spawn input.
Focused current-main verification:
cd backend
go test ./internal/session_manager ./internal/service/session -run "Test(ChatSpawnRejectedBeforeDurableStateWhenUnsupported|DefaultChatSpawnFallsBackToTUIWhenUnavailable|ToAPIErrorMapsWorkspaceBranchSentinels|ToSpawnAPIErrorMapsSpawnStageSentinels)" -count=1
Both packages pass. These tests cover refusal before durable state, safe default-mode fallback for all four Chat preflight failures, CWD mismatch mapping, and workspace-provision stage mapping with the underlying reason. Closing as completed by subsequent spawn/preflight/error-envelope work. If telemetry shows a new raw failure, please reopen with its current code and envelope.