Skip to content

fix(sandbox): make the daemon read route async - #5403

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

pedrofrxncx merged 1 commit into
mainfrom
fix/daemon-read-route-async-w1

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 30, 2026 •

Copy link
Copy Markdown
Collaborator

Continues the sync-fs-to-async cleanup in the sandbox daemon (CONTRIBUTING.md rule #1) started by #5372 (unlink), #5375 (mkdir), and #5391 (edit) — the daemon runs on a single-threaded Bun event loop and Studio tears down a sandbox on a single missed health probe.

Why a maintainer wants it: makeReadHandler (the /read route, the daemon's most-hit file-content endpoint) still used fs.statSync / fs.openSync / fs.readSync / fs.closeSync / fs.readFileSync — every file read (including full-file text reads and up-to-5MB image reads) blocked the event loop for the read's duration, which could stall the health probe under concurrent load.

Change: swap those for node:fs/promises equivalents (stat, open+FileHandle.read+close, readFile), matching the pattern already used by the sibling write/edit handlers in the same file. Pure mechanical async conversion — no behavior change (same error paths, same probe-then-decide-image-vs-text logic).

Verify: cd packages/sandbox && bunx tsc --noEmit and bun test packages/sandbox/daemon/routes/fs.test.ts (56 pass, 9 skip, 0 fail — pre-existing suite, no assertions changed).

Locally ran: bun run fmt, targeted tsc --noEmit in packages/sandbox, and the single fs.test.ts file. Full CI covers the rest.


Summary by cubic

Convert the sandbox daemon /read route to async I/O so it no longer blocks the event loop. This prevents stalls on large text/image reads and makes health probes more reliable.

  • Refactors
    • Replaced fs.statSync/openSync/readSync/closeSync/readFileSync with stat, open+FileHandle.read+close, and readFile from node:fs/promises.
    • No behavior change: same errors and image/text sniffing; matches the write/edit handlers.

Written for commit 2d30aa9. Summary will update on new commits.

Review in cubic

The /read route's file stat, open/read/close, and readFile calls used the
sync fs API, blocking the daemon's single-threaded event loop for the
duration of every file read (including large text/image reads) and risking
a missed health probe under load. Switch to node:fs/promises equivalents.

Follows the same conversion already applied to mkdir/unlink/edit routes
(#5372, #5375, #5391).
@pedrofrxncx
pedrofrxncx merged commit 0c7be1e into main Jul 30, 2026
23 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/daemon-read-route-async-w1 branch July 30, 2026 05:45
decocms Bot pushed a commit that referenced this pull request Jul 30, 2026
PR: #5403 fix(sandbox): make the daemon read route async
Bump type: patch

- @decocms/sandbox (packages/sandbox/package.json): 1.28.1 -> 1.28.2
- deploy/helm/sandbox-env (chart 0.9.49) (deploy/helm/sandbox-env/values.yaml deploy/helm/sandbox-env/Chart.yaml): image.tag/appVersion -> 1.28.2

Deploy-Scope: both
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