Skip to content

fix(sandbox): make the write-file daemon route async - #5370

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/async-fs-write-handler-w1
Jul 29, 2026
Merged

pedrofrxncx merged 1 commit into
mainfrom
fix/async-fs-write-handler-w1

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 29, 2026 •

Copy link
Copy Markdown
Collaborator

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.

makeWriteHandler in packages/sandbox/daemon/routes/fs.ts — the handler backing every file save from the editor/agent, and the most frequently hit fs route — still called fs.mkdirSync/fs.writeFileSync directly inside the request handler.

Fix: swapped the two sync node:fs calls for their node:fs/promises equivalents (mkdir/writeFile). Same behavior (still create-parent-then-write), just off the event loop. Net diff: -3/+3, all pre-existing logic (JSON validation, onWorkingTreeWrite signal, response shape) untouched.

Reviewer check: cd packages/sandbox && bunx tsc --noEmit and bun test packages/sandbox/daemon/routes/fs.test.ts (existing suite, including several write: cases, unmodified and still passing).

Locally verified: bun run fmt, bunx tsc --noEmit in packages/sandbox, and the targeted test file above — all green (56 pass / 9 skip / 0 fail). Full CI validates the rest.

Note: routes/fs.ts has 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:fs sync calls (mkdirSync, writeFileSync) with node:fs/promises (mkdir, writeFile); behavior and response remain the same.

Written for commit 6aa0f10. Summary will update on new commits.

Review in cubic

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
pedrofrxncx enabled auto-merge (squash) July 29, 2026 13:35
@pedrofrxncx
pedrofrxncx merged commit c7b6ea8 into main Jul 29, 2026
18 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/async-fs-write-handler-w1 branch July 29, 2026 13:40
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
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