Repository navigation
fix(sandbox): make the unlink daemon route async - #5372
Merged
Merged
Conversation
pedrofrxncx
enabled auto-merge (squash)
July 29, 2026 14:11
decocms Bot
pushed a commit
that referenced
this pull request
Jul 29, 2026
PR: #5372 fix(sandbox): make the unlink daemon route async Bump type: patch - @decocms/sandbox (packages/sandbox/package.json): 1.25.3 -> 1.25.4 - deploy/helm/sandbox-env (chart 0.9.40) (deploy/helm/sandbox-env/values.yaml deploy/helm/sandbox-env/Chart.yaml): image.tag/appVersion -> 1.25.4 Deploy-Scope: both
This was referenced Jul 29, 2026
pedrofrxncx
added a commit
that referenced
this pull request
Jul 30, 2026
The /read route's file stat, open/read/close, and readFile calls used the sync fs API, blocking the daemon's single-threaded event loop for the duration of every file read (including large text/image reads) and risking a missed health probe under load. Switch to node:fs/promises equivalents. Follows the same conversion already applied to mkdir/unlink/edit routes (#5372, #5375, #5391).
This was referenced Jul 31, 2026
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 the same sync-to-async cleanup already applied to the daemon's write-file route (#5370), the daemon.json read path (#5336), and the org-fs config relay (#5367), per CONTRIBUTING.md rule #1 / CLAUDE.md gotcha #8: the sandbox daemon runs on a single-threaded Bun event loop, and any sync fs call in a request handler blocks every other in-flight request — including the health probe Studio polls to decide whether the sandbox is alive. A single missed probe marks the sandbox dead and tears it down / triggers recovery.
makeUnlinkHandlerinpackages/sandbox/daemon/routes/fs.ts— the handler backing every file/directory delete from the editor/agent — still calledfs.statSync/fs.rmSync/fs.unlinkSyncdirectly inside the request handler.Fix: swapped the three sync
node:fscalls for theirnode:fs/promisesequivalents (stat/rm/unlink). Same behavior (still stat-then-branch-on-directory, same ENOENT handling for idempotency), just off the event loop. Net diff: -5/+13 (mostly the import list reflow), all pre-existing logic (recursive-delete gate,.gitprotection,onWorkingTreeWritesignal, idempotent-on-missing response shape) untouched.Reviewer check:
cd packages/sandbox && bunx tsc --noEmitandbun test packages/sandbox/daemon/routes/fs.test.ts(existing suite, including severalunlink:cases, unmodified and still passing).Locally verified:
bun run fmt,bunx tsc --noEmitinpackages/sandbox, and the targeted test file above — all green (56 pass / 9 skip / 0 fail). Full CI validates the rest.Note:
routes/fs.tsstill has other handlers (mkdir/rename/edit/glob) with the same sync-fs pattern — left out of this PR to keep it to one handler/one concern; worth further follow-ups.Summary by cubic
Make the sandbox unlink route async to avoid blocking the single-threaded Bun event loop and missing health probes. Replaces sync
node:fscalls withnode:fs/promiseswhile keeping behavior the same.makeUnlinkHandlerinpackages/sandbox/daemon/routes/fs.tsto usestat,rm, andunlinkfromnode:fs/promises..gitprotection, idempotent ENOENT handling, andonWorkingTreeWritesignal.Written for commit 70fb80f. Summary will update on new commits.