Repository navigation
fix(sandbox): make the write-file daemon route async - #5370
Merged
Merged
Conversation
Any sync fs call in the daemon blocks its single-threaded event loop for every other in-flight request, including the health probe Studio polls to decide whether the sandbox is alive — a missed probe marks the sandbox dead and triggers recovery (CONTRIBUTING.md rule #1). The write route (the daemon's most frequently hit fs handler, backing every file save from the editor) still used mkdirSync/writeFileSync. Follows the same async cleanup already applied to daemon.json (#5336) and the org-fs config relay (#5367).
pedrofrxncx
enabled auto-merge (squash)
July 29, 2026 13:35
decocms Bot
pushed a commit
that referenced
this pull request
Jul 29, 2026
PR: #5370 fix(sandbox): make the write-file daemon route async Bump type: patch - @decocms/sandbox (packages/sandbox/package.json): 1.25.2 -> 1.25.3 - deploy/helm/sandbox-env (chart 0.9.39) (deploy/helm/sandbox-env/values.yaml deploy/helm/sandbox-env/Chart.yaml): image.tag/appVersion -> 1.25.3 Deploy-Scope: both
This was referenced Jul 29, 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.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.
makeWriteHandlerinpackages/sandbox/daemon/routes/fs.ts— the handler backing every file save from the editor/agent, and the most frequently hit fs route — still calledfs.mkdirSync/fs.writeFileSyncdirectly inside the request handler.Fix: swapped the two sync
node:fscalls for theirnode:fs/promisesequivalents (mkdir/writeFile). Same behavior (still create-parent-then-write), just off the event loop. Net diff: -3/+3, all pre-existing logic (JSON validation,onWorkingTreeWritesignal, response shape) untouched.Reviewer check:
cd packages/sandbox && bunx tsc --noEmitandbun test packages/sandbox/daemon/routes/fs.test.ts(existing suite, including severalwrite: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.tshas several other handlers (read/unlink/mkdir/rename/glob/grep) with the same sync-fs pattern — left out of this PR to keep it to one handler/one concern; worth a follow-up sweep.Summary by cubic
Made the sandbox write-file route async to avoid blocking the Bun event loop and prevent missed health probes. Replaced
node:fssync calls (mkdirSync,writeFileSync) withnode:fs/promises(mkdir,writeFile); behavior and response remain the same.Written for commit 6aa0f10. Summary will update on new commits.