Repository navigation
fix(sandbox): scope the claim auto-retry budget to the active branch - #5221
Merged
pedrofrxncx merged 2 commits intoJul 24, 2026
Merged
Conversation
SandboxLifecycleProvider lives above Chat.ActiveTaskProvider and is not remounted on a task switch, but its bounded claim-auto-retry budget (added in #5210) was tracked in plain refs shared across the whole provider lifetime. Switching to a different task/branch after one branch's boot exhausted its retry budget carried that exhausted count into the new branch's fresh boot, so a transient claim failure there skipped auto-retry and surfaced the errored card immediately instead of retrying. Replaced the two refs with a small piece of state keyed by branch, reconciled via the new pure `reconcileClaimRetryEpisode` (reset to a fresh budget whenever the branch differs from the tracked one), and added unit tests for it.
pedrofrxncx
deleted the
fix/sandbox-claim-retry-budget-cross-branch-leak-w2
branch
July 24, 2026 19:43
decocms Bot
pushed a commit
that referenced
this pull request
Jul 24, 2026
PR: #5221 fix(sandbox): scope the claim auto-retry budget to the active branch Bump type: patch - decocms (apps/api/package.json): 4.125.3 -> 4.125.4 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.
Follows #5210 (bounded claim auto-retry) hardening.
The bug:
SandboxLifecycleProviderlives aboveChat.ActiveTaskProviderin the tree (seeVmEventsBridgeinapps/web/src/layouts/agent-shell-layout/index.tsx) and is only remounted whenvirtualMcpIdchanges (Chat.Provider key={chatVirtualMcpId}) — NOT on a task/branch switch. Its claim auto-retry budget (claimRetryCountRef/claimFailureHandledRef, added in #5210) was tracked in plain refs scoped to the whole provider lifetime, not to the current branch's boot episode.Failure scenario: open task A on branch
foo, its sandbox claim fails with a retryable reason (e.g.scheduling-timeoutduring a capacity crunch) and both auto-retries are consumed (claimRetryCountRef.current === MAX_CLAIM_AUTO_RETRIES). Switch to task B on a different branchbar(same agent). Ifbar's own boot also hits a transient claim failure — plausible, sincescheduling-timeout/reconciler-errorare cluster-wide capacity issues likely to correlate across branches around the same time —claimRetryExhaustedreads the already-exhausted counter fromfoo's episode andbargets zero retries: the errored card shows immediately instead of self-healing, even though this isbar's first attempt.The fix: replaced the two refs with a small piece of React state (
claimRetryEpisodeState) keyed by branch, reconciled each render through a new pure helperreconcileClaimRetryEpisode(prev, branch)— returnsprevunchanged when the branch matches (no extra render), or a fresh{ count: 0, handled: false }budget when it doesn't. This mirrors the existing pattern in the same file (e.g.computeOthersThreadGate) of extracting the branching logic into a small tested pure function rather than reasoning about refs inline.Net effect: each branch's boot episode now gets its own 2-retry budget again, regardless of which other branch's episode last ran in this provider instance.
Regression test:
apps/web/src/components/sandbox/hooks/sandbox-lifecycle-context.test.ts— newreconcileClaimRetryEpisodedescribe block; asserts (1) same branch returns the identical reference (no needless reset/re-render), (2) a different branch resets to a fresh budget (the bug), (3)null→ a real branch also resets.Reviewer verification:
Both run clean locally (58/58 tests pass, including the 3 new ones).
bun run fmtwas run with no diffs. Full CI covers lint/build.Summary by cubic
Fixes a bug where the sandbox claim auto-retry budget leaked across branches, causing fresh boots on a different branch to skip retries. The budget is now scoped to the active branch so transient claim failures self-heal per branch.
claimRetryEpisodeState) reconciled viareconcileClaimRetryEpisode, which resets on branch change and returns the same reference for same-branch episodes to avoid extra renders.reconcileClaimRetryEpisodecovering same-branch identity, cross-branch reset, and null-to-branch reset.Written for commit c4de72b. Summary will update on new commits.