Skip to content

fix(sandbox): make the daemon discard route async - #5471

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/sandbox-discard-route-async-w2
Jul 31, 2026
Merged

pedrofrxncx merged 1 commit into
mainfrom
fix/sandbox-discard-route-async-w2

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 31, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Convert the discard() helper function from synchronous to asynchronous, replacing fs.unlinkSync() with await unlink(). This eliminates a blocking filesystem call that stalls the daemon's single-threaded event loop and can cause missed health probes, triggering sandbox teardown.

Why

Daemon filesystem operations must not block the event loop (see CONTRIBUTING.md rule #1). The /git/discard HTTP handler was calling a synchronous function that deleted files using fs.unlinkSync(), which could block the health probe Studio polls at ~500ms intervals. A missed probe triggers sandbox destruction.

Testing

Behavior-preserving change: error handling and file deletion order unchanged, only async conversion. All 51 tests in daemon/routes/git.test.ts pass, including 5 discard-specific tests covering:

  • Path traversal validation
  • Renamed file restoration (original restored before new path deleted)
  • Error handling for missing files
  • Request validation

To verify locally:

bun test ./packages/sandbox/daemon/routes/git.test.ts
bunx tsc --noEmit -p packages/sandbox/tsconfig.json

CI runs the full suite.


Summary by cubic

Make the /git/discard route non-blocking by converting discard() to async. This prevents event loop stalls that could cause missed health probes and sandbox teardown.

  • Bug Fixes
    • Replaced fs.unlinkSync() with await unlink() and made discard() async.
    • Updated the HTTP handler to await discard(); behavior and error handling unchanged.

Written for commit 3198d9f. Summary will update on new commits.

Review in cubic

The discard() helper called fs.unlinkSync() while being invoked from an async HTTP handler, blocking the daemon's single-threaded event loop. Convert to async unlink so file deletion no longer stalls the health probe Studio polls (CONTRIBUTING.md rule #1). Behavior-preserving: same error handling and file deletion order, just async.
@pedrofrxncx
pedrofrxncx enabled auto-merge (squash) July 31, 2026 01:18
@pedrofrxncx
pedrofrxncx merged commit f91ce5f into main Jul 31, 2026
24 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/sandbox-discard-route-async-w2 branch July 31, 2026 01:24
decocms Bot pushed a commit that referenced this pull request Jul 31, 2026
PR: #5471 fix(sandbox): make the daemon discard route async
Bump type: patch

- @decocms/sandbox (packages/sandbox/package.json): 1.28.4 -> 1.28.5
- deploy/helm/sandbox-env (chart 0.9.52) (deploy/helm/sandbox-env/values.yaml deploy/helm/sandbox-env/Chart.yaml): image.tag/appVersion -> 1.28.5

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