Skip to content

fix(sandbox): surface terminal claim failure so preview stops spinning forever - #5207

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/sandbox-preview-terminal-claim-failure
Jul 24, 2026
Merged

pedrofrxncx merged 1 commit into
mainfrom
fix/sandbox-preview-terminal-claim-failure

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 24, 2026 •

Copy link
Copy Markdown
Collaborator

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.

reported bug: infinite sandbox loading

Root cause

A terminal sandbox claim failure — a real K8s failure (scheduling-timeout, image-pull-backoff, crash-loop-backoff, …) or the synthetic failed: "lifecycle watcher ended unexpectedly" emitted by apps/api/src/sandbox/lifecycle.ts — arrives on the SSE lifecycle stream as a claim-failed phase (events.phase.kind === "failed"). It never rejects the SANDBOX_START mutation.

But computePreviewState only escaped "starting" via startError, which was populated solely from a rejected mutation. So a boot that failed after SANDBOX_START already returned (async provision) left the preview pinned to "starting" indefinitely — the infinite spinner. The starting card has no retry/new-chat affordance (only the errored/othersThread cards do), so the user is trapped. This gap was already flagged as a follow-up in claim-phase-copy.ts.

Fix

Route the terminal claim-failed phase into startError via a small pure helper deriveStartError(). computePreviewState then returns errored, which renders the existing errored card with its Retry button (Retry re-fires SANDBOX_START — the correct recovery). resolvePreviewDisplay already suppresses the booting overlay for errored, 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_sessions on prod: every row with desired_state='running' + status='missing' (4 of them) has preview_url IS NULL and failure_reason IS NULL — the exact stuck signature (no URL, no recorded failure → frontend spins forever).

Tests

Added deriveStartError unit tests (co-located, pure — no mocks): terminal failed → errored; failed while pending → null (keep overlay); non-terminal / ready → null; mutation rejection still wins. bun test (44 pass), tsc --noEmit, and bun run fmt all 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”.

  • Bug Fixes
    • Introduced deriveStartError to map claim failed phases to startError when no start is in flight, enabling Retry.
    • Kept the booting overlay during in‑flight retries/self-heal to avoid flashing errored.
    • Added unit tests for deriveStartError.

Written for commit b602ec8. Summary will update on new commits.

Review in cubic

…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
pedrofrxncx enabled auto-merge (squash) July 24, 2026 17:29
@pedrofrxncx
pedrofrxncx merged commit 338cd9c into main Jul 24, 2026
14 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/sandbox-preview-terminal-claim-failure branch July 24, 2026 17:34
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant