Skip to content

fix(sandbox): make the daemon URL-transfer routes async - #5413

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/sandbox-url-transfer-routes-async-w1
Jul 30, 2026
Merged

fix(sandbox): make the daemon URL-transfer routes async#5413
pedrofrxncx merged 1 commit into
mainfrom
fix/sandbox-url-transfer-routes-async-w1

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Follows #5403/#5406, which converted the daemon's read and rename routes off blocking sync fs calls. write_from_url and upload_to_url in packages/sandbox/daemon/routes/fs.ts still called fs.mkdirSync/fs.rmSync/fs.statSync directly in the request handler.

Per CONTRIBUTING.md rule #1, the sandbox daemon runs on a single-threaded Bun event loop — any sync fs call blocks it from answering its HTTP health probe, and Studio tears down / recovers a sandbox on a single missed probe. mkdirSync/statSync ran on every call to these routes, and rmSync ran on every failed transfer.

The fix swaps each sync call for its already-imported node:fs/promises equivalent (mkdir/rm/stat were already imported and used elsewhere in the file) — a straight 1:1 behavior-preserving substitution, same as the prior read/rename PRs. Renamed the local stat variable to fileStat to avoid shadowing the imported stat function.

To verify: cd packages/sandbox && bunx tsc --noEmit, then bun test packages/sandbox/daemon/routes/fs.test.ts (56 pass, 0 fail — existing coverage of this file passes unchanged since behavior is identical).

Locally ran: bun run fmt, bunx tsc --noEmit (packages/sandbox workspace), and the targeted test file above. Full CI validates the rest.


Summary by cubic

Make the sandbox daemon’s URL-transfer routes async to avoid blocking the single-threaded event loop and prevent health probe timeouts. Replaced sync fs calls in write_from_url and upload_to_url with node:fs/promises to keep behavior the same while non-blocking.

  • Bug Fixes
    • Swapped mkdirSync/rmSync/statSync for mkdir/rm/stat in packages/sandbox/daemon/routes/fs.ts.
    • Renamed local stat to fileStat to avoid shadowing the imported stat function.

Written for commit 10874d9. Summary will update on new commits.

Review in cubic

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
pedrofrxncx merged commit 0b09c2f into main Jul 30, 2026
23 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/sandbox-url-transfer-routes-async-w1 branch July 30, 2026 15:31
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