Skip to content

fix(sandbox): serialize git/discard on the same claim lock as publish/rebase - #5118

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/sandbox-discard-claim-lock
Jul 23, 2026
Merged

pedrofrxncx merged 1 commit into
mainfrom
fix/sandbox-discard-claim-lock

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 23, 2026 •

Copy link
Copy Markdown
Collaborator

Follows #5114, which added withClaimGitLock to serialize publish/rebase per claim on shared agent sandboxes so concurrent requests can't interleave git commit/push against the same working tree. discard was left unwrapped even though it also mutates the same working tree (git checkout -- to restore tracked files, plus unlinking untracked ones) — so on a sandbox shared by two teammates (#5112), a discard racing a concurrent publish can still interleave: discard's git checkout can revert files mid-way through publish's git add/commit, or a discard-driven unlink can delete a file publish just staged, either silently dropping a teammate's in-flight change or corrupting the commit.

Fix: wrap the git/discard route in the same withClaimGitLock(claimName, ...) used by publish/rebase, so only one of publish/rebase/discard runs against a given claim's working tree at a time.

No new test added — withClaimGitLock itself is already exhaustively unit-tested (serializes same-claim calls, doesn't block different claims, rejections don't wedge the queue) in sandbox-proxy.test.ts; this change is pure wiring of the existing, already-verified lock into one more route, not new locking logic.

Reviewer check: cd apps/mesh && bunx tsc --noEmit and bun test apps/mesh/src/api/routes/sandbox-proxy.test.ts (both pass locally). Full CI validates the rest.

Locally ran: bun run fmt, targeted tsc --noEmit in apps/mesh, and the single test file above.


Summary by cubic

Wrap the git/discard route with withClaimGitLock to serialize per-claim operations, matching publish/rebase. This prevents discard from racing with add/commit/push on shared sandboxes and avoids dropped files or corrupt commits.

Written for commit 52712cf. Summary will update on new commits.

Review in cubic

@pedrofrxncx
pedrofrxncx enabled auto-merge (squash) July 23, 2026 19:17
@pedrofrxncx
pedrofrxncx merged commit 1b25a76 into main Jul 23, 2026
15 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/sandbox-discard-claim-lock branch July 23, 2026 19:21
decocms Bot pushed a commit that referenced this pull request Jul 23, 2026
PR: #5118 fix(sandbox): serialize git/discard on the same claim lock as publish/rebase
Bump type: patch

- decocms (apps/mesh/package.json): 4.109.5 -> 4.109.6

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]>
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