Repository navigation
fix(sandbox): surface terminal claim failure so preview stops spinning forever - #5207
Merged
Merged
Conversation
…g forever A terminal sandbox claim failure (K8s scheduling/image-pull failure, or the synthetic 'lifecycle watcher ended unexpectedly' from lifecycle.ts) arrives on the SSE lifecycle stream as a claim-`failed` phase — it never rejects the SANDBOX_START mutation. computePreviewState only escaped "starting" via a rejected mutation (startError), so a boot that failed after SANDBOX_START returned left the preview pinned to "starting" indefinitely: the infinite 'Iniciando sandbox' spinner, with no retry/new-chat affordance (only the errored/othersThread cards offer one). Route the terminal claim-failed phase into startError via a new pure deriveStartError() helper, so it renders the existing errored card (with Retry) instead. Gate on no start in flight so an in-progress retry/self-heal reprovision keeps the booting overlay rather than flashing errored. Verified against prod: every agent_sandbox_sessions row with desired_state='running' + status='missing' has preview_url IS NULL and failure_reason IS NULL — the exact stuck signature.
pedrofrxncx
enabled auto-merge (squash)
July 24, 2026 17:29
decocms Bot
pushed a commit
that referenced
this pull request
Jul 24, 2026
PR: #5207 fix(sandbox): surface terminal claim failure so preview stops spinning forever Bump type: patch - decocms (apps/api/package.json): 4.123.6 -> 4.123.7 Deploy-Scope: web
pedrofrxncx
pushed a commit
that referenced
this pull request
Jul 27, 2026
#5240) Reverts #5112 (share agent sandboxes by branch), #5116 (always share agent sandboxes) and #5132 (use shared staging branch), restoring the pre-#5112 behaviour: hosted agent sandboxes are per-user again, and a new GitHub-backed thread gets a generated branch instead of `staging`. Reconstructed against current paths rather than reverted: #5120 split apps/mesh into apps/api + apps/web and hoisted branch-name.ts, runtime-defaults.ts and thread/schema.ts into packages/shared, and #5174 deleted vm-events.ts outright, so none of the three commits reverse-apply. Core change: SandboxId goes back to a flat `{ userId, projectRef }` and sandboxIdKey back to `userId:projectRef`, so every hosted claim handle changes. Live shared claims must be drained BEFORE this deploys. Also reverted, because they only exist inside the shared model: - #5225 withoutLegacyAgentSandboxEntries — left in place it would strip the sandboxMap entries the reverted server writes back, leaving shouldAutoStart permanently true (silent, compiles fine) - #5219 resolveSharedThreadVm and the shared-scope branch - #5183 stale-provisioning reset (lived inside the deleted storage) Deliberately preserved: - migrations 137/138 and their index.ts entries — Kysely's #ensureNoMissingMigrations runs unconditionally, so deleting an applied migration crash-loops every pod. The tables are dropped by a follow-up forward migration after the drain, not by this commit. - #5114/#5118 withClaimGitLock, #5126 org-context guard, #5143 analytics gate, #5171 owner-keyed thread graft, #5195/#5207/#5210/#5221 client auto-retry, the daemon status-code train and the settings-validation train - #5112's org-fs least-privilege narrowing and the start dedup key fix - #5116's squashed queue-tray pluralization (en + pt-br) - the remote-branch-name validations #5132 deleted, since this restores the dynamic origin/HEAD lookup that made them load-bearing Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Pedro França <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Sandbox preview gets stuck loading forever — the full-canvas "Iniciando sandbox…" spinner never resolves, and the user is left with no way to recover (no retry, no escape) on that surface.
Root cause
A terminal sandbox claim failure — a real K8s failure (
scheduling-timeout,image-pull-backoff,crash-loop-backoff, …) or the syntheticfailed: "lifecycle watcher ended unexpectedly"emitted byapps/api/src/sandbox/lifecycle.ts— arrives on the SSE lifecycle stream as a claim-failedphase (events.phase.kind === "failed"). It never rejects theSANDBOX_STARTmutation.But
computePreviewStateonly escaped"starting"viastartError, which was populated solely from a rejected mutation. So a boot that failed afterSANDBOX_STARTalready returned (async provision) left the preview pinned to"starting"indefinitely — the infinite spinner. Thestartingcard has no retry/new-chat affordance (only theerrored/othersThreadcards do), so the user is trapped. This gap was already flagged as a follow-up inclaim-phase-copy.ts.Fix
Route the terminal claim-
failedphase intostartErrorvia a small pure helperderiveStartError().computePreviewStatethen returnserrored, which renders the existing errored card with its Retry button (Retry re-firesSANDBOX_START— the correct recovery).resolvePreviewDisplayalready suppresses the booting overlay forerrored, so there's no double-render.The phase path is gated on no start in flight (
!startVm.isPending && !sharedLifecyclePending) so an in-progress retry/self-heal reprovision keeps the booting overlay instead of flashing errored.No new UI, no new dependency — reuses the errored card + Retry.
Verified against prod
Queried
agent_sandbox_sessionson prod: every row withdesired_state='running'+status='missing'(4 of them) haspreview_url IS NULLandfailure_reason IS NULL— the exact stuck signature (no URL, no recorded failure → frontend spins forever).Tests
Added
deriveStartErrorunit tests (co-located, pure — no mocks): terminalfailed→ errored;failedwhile pending → null (keep overlay); non-terminal /ready→ null; mutation rejection still wins.bun test(44 pass),tsc --noEmit, andbun run fmtall clean.Note
An unrelated working-tree change to
sections-editor/read-committed-file.ts(treat 404 as transient) was present but is not part of this PR — it was not authored in this change.Summary by cubic
Stops the sandbox preview from spinning forever by surfacing terminal claim failures as start errors, so the UI shows the existing errored card with Retry instead of staying on “starting”.
deriveStartErrorto map claimfailedphases tostartErrorwhen no start is in flight, enabling Retry.deriveStartError.Written for commit b602ec8. Summary will update on new commits.