Skip to content

fix(sandbox): make installProtectedBranchHook async - #4452

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/sandbox-async-protected-branch-hook
Jul 11, 2026
Merged

pedrofrxncx merged 1 commit into
mainfrom
fix/sandbox-async-protected-branch-hook

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 11, 2026 •

Copy link
Copy Markdown
Collaborator

Source

Bug found reading recently-changed sandbox daemon code (#4440 added a second call site to installProtectedBranchHook).

Why

installProtectedBranchHook used mkdirSync/writeFileSync/chmodSync (packages/sandbox/daemon/git/protect-branch.ts). The daemon runs on a single Bun event loop, and this repo's own CONTRIBUTING.md rule #4 (and CLAUDE.md gotcha #8) calls out sync fs in this package as a hard rule, not a style nit: a single missed health probe flips a healthy sandbox to "crashed" and tears the pod down mid-session. #4440 just added a second call site for this same function (reinstalling the hook right after every real install completes, in addition to the existing gitSetup() call), doubling how often this sync work runs on the hot path.

Fix

Switch installProtectedBranchHook to node:fs/promises (mkdir/writeFile/chmod) and await it at both call sites in orchestrator.ts (both are already inside async methods with try/catch, so this is a drop-in change).

Test plan

Full CI will validate the rest (typecheck across the monorepo needs bun install, which I didn't run since this diff touches no dependencies).


Summary by cubic

Make branch-protection hook installation async to stop blocking the sandbox daemon’s event loop. This prevents missed health probes and improves reliability during setup and post-install.

  • Bug Fixes
    • Converted installProtectedBranchHook to use node:fs/promises and made it async (mkdir/writeFile/chmod).
    • Awaited the hook install at both SetupOrchestrator call sites so reinstalling happens without blocking.
    • Updated tests to await installProtectedBranchHook.

Written for commit 6515f8b. Summary will update on new commits.

Review in cubic

mkdirSync/writeFileSync/chmodSync block the daemon's single event loop
(CONTRIBUTING.md rule #4) — a single missed health probe flips a healthy
sandbox to crashed and tears the pod down mid-session. #4440 just added a
second call site for this function (after every real install), doubling
the exposure. Switch to node:fs/promises and await both call sites.
@pedrofrxncx
pedrofrxncx merged commit 6780f93 into main Jul 11, 2026
14 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/sandbox-async-protected-branch-hook branch July 11, 2026 02:14
decocms Bot pushed a commit that referenced this pull request Jul 11, 2026
PR: #4452 fix(sandbox): make installProtectedBranchHook async
Bump type: patch

- @decocms/sandbox (packages/sandbox/package.json): 1.14.0 -> 1.14.1

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