Repository navigation
fix(sandbox): serialize publish/rebase per claim to stop shared-sandbox races - #5114
Merged
Merged
Conversation
…ox races The publish and rebase routes PUT an operator identity into the daemon's persisted tenant config, then trigger a commit/push that reads that config back. On a shared agent sandbox (feat(sandbox): share agent sandboxes by branch, #5112) two teammates can hit publish/rebase for the same claim concurrently: one request's operator PUT can be overwritten before its own commit runs, misattributing co-authorship, and two commit/push sequences can interleave against the same working tree. Serialize per claim in the mesh proxy so at most one publish/rebase runs against a given claim at a time.
decocms Bot
pushed a commit
that referenced
this pull request
Jul 23, 2026
PR: #5114 fix(sandbox): serialize publish/rebase per claim to stop shared-sandbox races Bump type: patch - decocms (apps/mesh/package.json): 4.109.2 -> 4.109.3 Deploy-Scope: server
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 #5112 (share agent sandboxes by branch) hardening.
Bug:
git/publishandgit/rebaseeach PUT anoperatoridentity into the daemon's persisted tenant config (patchSandboxOperator), then trigger a commit/push that reads that config back (deps.getOperator()in the daemon, used for the co-author trailer). Before #5112, a sandbox only ever had one active user, so this two-step "set then act" sequence was safe. Now that a sandbox can be shared by branch across teammates, two people can hit publish (or one publish + one rebase) for the same claim concurrently:git add/commit/pushcan also interleave against the single shared working tree, which git operations were never designed to run concurrently against.Fix: added
withClaimGitLock(claimName, fn)insandbox-proxy.ts— a small per-claim promise chain (no new dependency) that serializes the whole patch-operator-then-publish (or patch-operator-then-rebase) sequence per claim. Entries are removed once idle, so the map never grows past the number of claims currently mid-publish/rebase. This closes the race for concurrent requests hitting the same mesh process; other read-only git routes (status/diff/discard) are untouched since they don't touch the operator or commit/push.Verification:
sandbox-proxy.test.tscovering: same-claim calls run in strict order, different-claim calls don't block each other, and a rejection doesn't wedge the lock for later calls on that claim.cd apps/mesh && bunx tsc --noEmit— clean (pre-existing unrelated errors in an untrackedlink-daemon/ensure-rclone.test.tsfile are not from this change).bun test apps/mesh/src/api/routes/sandbox-proxy.test.ts— 8 pass, 0 fail.bun run fmt— no changes needed.A reviewer can confirm with
bun test apps/mesh/src/api/routes/sandbox-proxy.test.ts.Summary by cubic
Serialize
git/publishandgit/rebaseper claim to stop operator misattribution and concurrent git races in shared sandboxes. Adds a per-claim lock so only one publish/rebase runs at a time for a claim.withClaimGitLock(claimName, fn)insandbox-proxy.tsto serialize the operator patch + commit/push flow forgit/publishandgit/rebase.operatorand interleavinggit commit/pushon the same working tree.GitPushAuthErrorresponses and 404→410 mapping.Written for commit 3f092dc. Summary will update on new commits.