Skip to content

fix(sandbox): make the daemon mkdir route async - #5375

Merged
pedrofrxncx merged 1 commit into
mainfrom
refactor/mkdir-route-async-w5
Jul 29, 2026
Merged

pedrofrxncx merged 1 commit into
mainfrom
refactor/mkdir-route-async-w5

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 29, 2026 •

Copy link
Copy Markdown
Collaborator

Follows #5372 (unlink daemon route made async) and #5336 — continuing the sweep of blocking sync fs calls in packages/sandbox/daemon/routes/fs.ts.

The daemon runs on a single-threaded Bun event loop (CONTRIBUTING.md rule #1). makeMkdirHandler called fs.mkdirSync, which blocks that loop for the duration of the syscall. Studio polls the daemon's HTTP health probe and tears the sandbox down on a single missed probe, so any sync fs call on this path is a latent sandbox-recovery trigger under load.

Change: swap fs.mkdirSync(dirPath, { recursive: true }) for the already-imported await mkdir(dirPath, { recursive: true }) from node:fs/promises. No behavior change — same recursive-mkdir semantics, same error handling.

To confirm: bun test packages/sandbox/daemon/routes/fs.test.ts (56 pass, covers makeMkdirHandler).

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

Remaining sync calls in the same file (statSync/readFileSync/renameSync/rmSync/readdirSync/etc. in rename, edit, glob, grep handlers) are left for follow-up PRs, one handler at a time, per the established pattern.


Summary by cubic

Make the sandbox daemon mkdir route async in packages/sandbox/daemon/routes/fs.ts to prevent blocking the Bun event loop and avoid health probe misses that can tear down the sandbox. Swapped fs.mkdirSync for await mkdir from node:fs/promises; behavior is unchanged (recursive mkdir and error handling).

Written for commit 42e6b97. Summary will update on new commits.

Review in cubic

@pedrofrxncx
pedrofrxncx merged commit c2fdc35 into main Jul 29, 2026
18 checks passed
@pedrofrxncx
pedrofrxncx deleted the refactor/mkdir-route-async-w5 branch July 29, 2026 17:19
decocms Bot pushed a commit that referenced this pull request Jul 29, 2026
PR: #5375 fix(sandbox): make the daemon mkdir route async
Bump type: patch

- @decocms/sandbox (packages/sandbox/package.json): 1.25.4 -> 1.25.5
- deploy/helm/sandbox-env (chart 0.9.41) (deploy/helm/sandbox-env/values.yaml deploy/helm/sandbox-env/Chart.yaml): image.tag/appVersion -> 1.25.5

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