Skip to content

fix(sandbox): make the unlink daemon route async - #5372

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

pedrofrxncx merged 1 commit into
mainfrom
refactor/unlink-route-async-w2

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 29, 2026 •

Copy link
Copy Markdown
Collaborator

Follows the same sync-to-async cleanup already applied to the daemon's write-file route (#5370), the daemon.json read path (#5336), and the org-fs config relay (#5367), per CONTRIBUTING.md rule #1 / CLAUDE.md gotcha #8: the sandbox daemon runs on a single-threaded Bun event loop, and any sync fs call in a request handler blocks every other in-flight request — including the health probe Studio polls to decide whether the sandbox is alive. A single missed probe marks the sandbox dead and tears it down / triggers recovery.

makeUnlinkHandler in packages/sandbox/daemon/routes/fs.ts — the handler backing every file/directory delete from the editor/agent — still called fs.statSync/fs.rmSync/fs.unlinkSync directly inside the request handler.

Fix: swapped the three sync node:fs calls for their node:fs/promises equivalents (stat/rm/unlink). Same behavior (still stat-then-branch-on-directory, same ENOENT handling for idempotency), just off the event loop. Net diff: -5/+13 (mostly the import list reflow), all pre-existing logic (recursive-delete gate, .git protection, onWorkingTreeWrite signal, idempotent-on-missing response shape) untouched.

Reviewer check: cd packages/sandbox && bunx tsc --noEmit and bun test packages/sandbox/daemon/routes/fs.test.ts (existing suite, including several unlink: cases, unmodified and still passing).

Locally verified: bun run fmt, bunx tsc --noEmit in packages/sandbox, and the targeted test file above — all green (56 pass / 9 skip / 0 fail). Full CI validates the rest.

Note: routes/fs.ts still has other handlers (mkdir/rename/edit/glob) with the same sync-fs pattern — left out of this PR to keep it to one handler/one concern; worth further follow-ups.


Summary by cubic

Make the sandbox unlink route async to avoid blocking the single-threaded Bun event loop and missing health probes. Replaces sync node:fs calls with node:fs/promises while keeping behavior the same.

  • Bug Fixes
    • Updated makeUnlinkHandler in packages/sandbox/daemon/routes/fs.ts to use stat, rm, and unlink from node:fs/promises.
    • Preserves logic: stat-then-branch for directories, recursive-delete gate, .git protection, idempotent ENOENT handling, and onWorkingTreeWrite signal.

Written for commit 70fb80f. Summary will update on new commits.

Review in cubic

@pedrofrxncx
pedrofrxncx enabled auto-merge (squash) July 29, 2026 14:11
@pedrofrxncx
pedrofrxncx merged commit f292e3d into main Jul 29, 2026
18 of 19 checks passed
@pedrofrxncx
pedrofrxncx deleted the refactor/unlink-route-async-w2 branch July 29, 2026 14:36
decocms Bot pushed a commit that referenced this pull request Jul 29, 2026
PR: #5372 fix(sandbox): make the unlink daemon route async
Bump type: patch

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

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