Skip to content

fix(sandbox): make the daemon's decofile-block validation read async - #5481

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/git-publish-async-readfile-w3
Jul 31, 2026
Merged

pedrofrxncx merged 1 commit into
mainfrom
fix/git-publish-async-readfile-w3

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 31, 2026 •

Copy link
Copy Markdown
Collaborator

Continues the daemon's ongoing sync-fs-to-async hardening (#5333, #5336, #5367, #5370, #5372, #5375, #5413, #5442, #5471) — CONTRIBUTING.md rule #1: no blocking sync fs work on the sandbox daemon's single-threaded Bun event loop, since a stall there misses the /health probe and Studio tears the pod down.

publish() (packages/sandbox/daemon/routes/git.ts) is invoked both from the interactive POST /_sandbox/git/publish route and from the daemon's shutdown handler, and it loops over every changed decofile block reading its content with fs.readFileSync to validate the JSON before allowing a commit. That call was fully synchronous and blocked the event loop for the duration of the read on every publish.

Fix: swapped fs.readFileSync for readFile from node:fs/promises, made publish() async, and awaited its two call sites (the publish route handler in git.ts, and the shutdown-sync call in entry.ts).

Behavior is unchanged — same validation logic, same return value/thrown errors, just non-blocking. All 10 test cases that call publish() directly (routes/git.test.ts) were updated to async/await (sync-throw assertions became await expect(...).rejects.toThrow(...)); no assertions changed.

Reviewer check: cd packages/sandbox && bunx tsc --noEmit, then bun test packages/sandbox/daemon/routes/git.test.ts (51 pass).

Locally verified: bun run fmt, bunx tsc --noEmit in packages/sandbox (clean), and the single targeted test file (51/51 pass). Full CI covers the e2e git-route suite.


Summary by cubic

Switched decofile-block validation to async file reads in the sandbox daemon to avoid blocking publish(). Keeps /health responsive and prevents pod teardown; behavior is unchanged.

  • Refactors
    • Replaced fs.readFileSync with readFile from node:fs/promises in publish().
    • Made publish() async and awaited in packages/sandbox/daemon/routes/git.ts and packages/sandbox/daemon/entry.ts.
    • Updated tests to use async/await with rejects.toThrow(...); assertions unchanged.

Written for commit 217dfe9. Summary will update on new commits.

Review in cubic

publish() blocked the event loop with a synchronous readFileSync while
validating each changed decofile block, on the same single-threaded Bun
loop that answers the daemon's /health probe (CONTRIBUTING rule #1).
Continues the same conversion already done for the daemon's other
routes (discard, glob, URL-transfer).
@pedrofrxncx
pedrofrxncx merged commit 0d57a61 into main Jul 31, 2026
24 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/git-publish-async-readfile-w3 branch July 31, 2026 02:49
pedrofrxncx added a commit that referenced this pull request Jul 31, 2026
publish() called mkdtempSync while running on the daemon's single-threaded
Bun event loop, blocking it for the duration of the syscall — the same class
of bug already fixed for the discard route (#5471) and decofile-block
validation (#5481). Continue that conversion here: mkdtemp (fs/promises),
awaited from the already-async publish() path.
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