Skip to content

fix(sandbox): make the daemon rename route async - #5406

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/daemon-rename-route-async-w3
Jul 30, 2026
Merged

pedrofrxncx merged 1 commit into
mainfrom
fix/daemon-rename-route-async-w3

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 30, 2026 •

Copy link
Copy Markdown
Collaborator

Follows #5403 (async read route) — continues converting the sandbox daemon's fs routes off blocking sync I/O, one route per PR (see also #5333, #5336).

The daemon runs on a single-threaded Bun event loop and Studio tears down/recovers a sandbox on a single missed health probe. makeRenameHandler in packages/sandbox/daemon/routes/fs.ts called fs.statSync (twice), fs.mkdirSync, and fs.renameSync — each one blocks the loop for the duration of the syscall, so a rename on a large/slow filesystem (or heavy concurrent traffic) could starve the health probe and get the sandbox killed.

Swapped all four for their node:fs/promises equivalents (stat, mkdir, rename) already imported/used elsewhere in this file. Purely mechanical, behavior-preserving — same checks, same error responses, same order of operations.

Reviewer check: bun test packages/sandbox/daemon/routes/fs.test.ts (existing rename: cases cover the moved-file and destination-already-exists paths).

Locally ran: bun run fmt, cd packages/sandbox && bunx tsc --noEmit, and the targeted test file above — all green. Full CI covers the rest.


Summary by cubic

Make the sandbox daemon’s rename route async to avoid blocking the single-threaded event loop. This reduces the chance of health probe timeouts on slow filesystems and improves sandbox stability.

  • Refactors
    • Replaced fs.statSync, fs.mkdirSync, and fs.renameSync with stat, mkdir, and rename from node:fs/promises.
    • Preserved existing checks and error responses; no behavior changes.

Written for commit 92ca568. Summary will update on new commits.

Review in cubic

@pedrofrxncx
pedrofrxncx enabled auto-merge (squash) July 30, 2026 05:49
@pedrofrxncx
pedrofrxncx merged commit 96603a8 into main Jul 30, 2026
29 of 30 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/daemon-rename-route-async-w3 branch July 30, 2026 05:50
pedrofrxncx added a commit that referenced this pull request Jul 30, 2026
write_from_url and upload_to_url ran fs.mkdirSync/rmSync/statSync directly
in the request handler, blocking the daemon's single-threaded event loop
on every call (mkdirSync/statSync on every request, rmSync on failure).
This mirrors the read/rename route fixes (#5403, #5406) using the
already-imported mkdir/rm/stat promises.
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