Skip to content

fix(sandbox): make golden-cache node-local disk I/O async - #5478

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/golden-cache-async-fs-w2
Jul 31, 2026
Merged

pedrofrxncx merged 1 commit into
mainfrom
fix/golden-cache-async-fs-w2

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 31, 2026 •

Copy link
Copy Markdown
Collaborator

Follows the daemon's async-fs hardening lane (#5333, #5336, #5367, #5370, #5372, #5375) — this is the golden-cache.ts instance of the same bug class.

golden-cache.ts used readFileSync/statSync/mkdirSync/readdirSync/rmSync/renameSync/utimesSync throughout. tryRestoreGolden, publishGolden, and pruneGoldens all run from a fire-and-forget call (entry.ts's void orchestrator.publishPendingGolden(), fired off the running health transition) while the daemon's Bun.serve is already answering requests — so every sync fs call there parks the single-threaded event loop and can make the daemon miss its own health probe (CONTRIBUTING.md rule #1: a single miss gets the pod marked dead and torn down). pruneGoldens is the worst offender: it walks and stats every golden directory on the node.

Why a maintainer wants this: it closes a real, provable liveness gap on the sandbox boot path — one that has already been the subject of ~6 merged PRs elsewhere in this same daemon (routes/fs.ts, discard route, etc.) but was still open here in setup/golden-cache.ts.

Change: converts every blocking call to its node:fs/promises equivalent, matching the async style remote-golden.ts (the L2 tier) already uses. resolveRemote in remote-golden.ts now awaits the (now-async) lockfileHash it imports from golden-cache.ts. orchestrator.ts's one pruneGoldens() call site is now awaited. Behavior-preserving: identical logic, fallbacks, and log lines — only the I/O calls changed from sync to async equivalents.

Command a reviewer can run: bun test packages/sandbox/daemon/setup/golden-cache.test.ts packages/sandbox/daemon/setup/remote-golden.test.ts

Locally verified: bun run fmt, bunx tsc --noEmit in packages/sandbox (clean), and the two targeted test files above (19 + 7 pass). Also ran packages/sandbox/daemon/setup/orchestrator.test.ts — one pre-existing failure (corepack binary missing in this sandbox) reproduces identically on main before this change, so it's unrelated. Full CI validates the rest.


Summary by cubic

Make golden-cache disk I/O async to avoid event-loop blocking during sandbox boot and prevent health probe misses. Replaced sync fs calls with node:fs/promises across restore, publish, and prune paths without changing behavior.

  • Bug Fixes
    • Switched all sync fs calls to async equivalents (node:fs/promises).
    • Made lockfileHash, sameFilesystem, and internal resolvers async; updated callers.
    • orchestrator now awaits pruneGoldens(); remote-golden awaits lockfileHash in resolveRemote.
    • Updated tests to use async fs and assertions; behavior stays the same.

Written for commit 02a96aa. Summary will update on new commits.

Review in cubic

golden-cache.ts used readFileSync/statSync/mkdirSync/readdirSync/rmSync/
renameSync/utimesSync throughout. tryRestoreGolden, publishGolden, and
pruneGoldens all run from fire-and-forget calls (entry.ts's
`void orchestrator.publishPendingGolden()`, itself invoked off the
`running` health transition) while the daemon's Bun.serve is already
answering requests, so every sync fs call there parks the single-threaded
event loop and can miss the daemon's own health probe (CONTRIBUTING.md
rule #1) — pruneGoldens is the worst offender, since it walks and stats
every golden dir on the node.

Converts every call to node:fs/promises equivalents, matching the async
style remote-golden.ts (L2) already uses. resolveRemote in remote-golden.ts
awaits the now-async lockfileHash it imports from golden-cache.ts.
Behavior-preserving: same logic, same fallbacks, same log lines.
@pedrofrxncx
pedrofrxncx enabled auto-merge (squash) July 31, 2026 01:59
@pedrofrxncx
pedrofrxncx merged commit 30fe984 into main Jul 31, 2026
24 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/golden-cache-async-fs-w2 branch July 31, 2026 02:07
decocms Bot pushed a commit that referenced this pull request Jul 31, 2026
PR: #5478 fix(sandbox): make golden-cache node-local disk I/O async
Bump type: patch

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

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