Skip to content

fix(sandbox): make the org-fs config relay write async - #5367

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

pedrofrxncx merged 1 commit into
mainfrom
fix/orgfs-config-async-fs-w1

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 29, 2026 •

Copy link
Copy Markdown
Collaborator

Follows the CONTRIBUTING.md rule #1 sync-to-async cleanup already applied to the daemon.json read path (#5336) and the docs comment on the sandbox daemon's single-threaded event loop.

The daemon's POST /_sandbox/orgfs-config route handler (packages/sandbox/daemon/routes/orgfs-config.ts) wrote its relay file with mkdirSync/writeFileSync/renameSync directly inside the request handler. Any sync fs call in the daemon blocks its single-threaded event loop for every other in-flight request while it runs — 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 (see CLAUDE.md gotcha #8 and CONTRIBUTING.md rule #1).

Fix: swapped the three sync node:fs calls for their node:fs/promises equivalents (mkdir/writeFile/rename), same behavior (still an atomic write-then-rename), just off the event loop.

Reviewer check: cd packages/sandbox && bunx tsc --noEmit and bun test packages/sandbox/daemon/routes/orgfs-config.test.ts (existing 3 tests, unmodified, still cover the write/parent-creation/reject/no-op paths and pass unchanged).

Locally verified: bun run fmt, bunx tsc --noEmit in packages/sandbox, and the targeted test file above — all green. Full CI validates the rest.


Summary by cubic

Switch the sandbox org-fs config relay to async I/O to avoid blocking the daemon event loop and missing health probes. Keeps the same atomic write-then-rename behavior.

  • Bug Fixes
    • Replaced mkdirSync/writeFileSync/renameSync with awaited mkdir/writeFile/rename from node:fs/promises.
    • Change applies to POST /_sandbox/orgfs-config in packages/sandbox/daemon/routes/orgfs-config.ts; existing tests remain unchanged and pass.

Written for commit 750bb07. Summary will update on new commits.

Review in cubic

The daemon's /orgfs-config route wrote the relay file with sync fs calls
(mkdirSync/writeFileSync/renameSync) on the daemon's single-threaded event
loop, blocking it for every other in-flight request (including the health
probe Studio polls to decide whether to tear the sandbox down) while it
ran. Swapped for the node:fs/promises equivalents, matching the same
sync-to-async fix already applied to the daemon.json read path (#5336).
@pedrofrxncx
pedrofrxncx merged commit 4d3f226 into main Jul 29, 2026
18 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/orgfs-config-async-fs-w1 branch July 29, 2026 13:23
decocms Bot pushed a commit that referenced this pull request Jul 29, 2026
PR: #5367 fix(sandbox): make the org-fs config relay write async
Bump type: patch

- @decocms/sandbox (packages/sandbox/package.json): 1.25.1 -> 1.25.2
- deploy/helm/sandbox-env (chart 0.9.38) (deploy/helm/sandbox-env/values.yaml deploy/helm/sandbox-env/Chart.yaml): image.tag/appVersion -> 1.25.2

Deploy-Scope: both
pedrofrxncx added a commit that referenced this pull request Jul 29, 2026
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 added a commit that referenced this pull request Jul 30, 2026
…5442)

walkRepoWithinMaxDepth used fs.readdirSync, and makeGlobHandler's
Bun.Glob branch used fs.statSync, both blocking the daemon's
single-threaded event loop on every glob call. Swap in the
already-imported readdir/stat promises, mirroring the read/rename/
unlink/mkdir/write route fixes (#5403, #5406, #5336, #5367).
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