Skip to content

v0.60.16.0 fix(persistence): bound async git children so a lost exit cannot strand consumer shutdown - #5787

Merged
capy-ai[bot] merged 2 commits into
masterfrom
fix/managed-maintenance-hang
Sep 30, 2026
Merged

capy-ai[bot] merged 2 commits into
masterfrom
fix/managed-maintenance-hang

Conversation

@garrytan

Copy link
Copy Markdown
Owner

This fixes the fleet-wide E2E hang: a few tests pass, Bun prints "killed 1 dangling process", then every remaining test in the file times out. It showed up today in managed-maintenance, persistence-reconcile and google-attachments-postgres, including on PRs based on pre-refactor master.

Root cause. This is Bun 1.3.x bug oven-sh/bun#30301, fixed in 1.4.0. When a callback re-enters the event loop, which bun:test's expect().resolves/.rejects does, Bun drops the other pidfd and pipe events in the same poll batch. The child stays a zombie, and neither execFile's callback nor its built-in timeout fires. The chain that hangs:

  • The persistence consumer's effects drain runs two async git durability probes per git effect: isDurabilityHardenedAsync, called from effects.ts.
  • One of those probes never settles, so await hardened hangs, and the effects worker with it.
  • PersistenceConsumer.stop() waits on the effects worker, so disposePersistenceConsumer hangs too.
  • Every later test fixture waits on that same dispose.

On a reproduced hang the test database had zero sessions, and the hung process had exactly two [git] <defunct> children. The async probe arrived in v0.60.10.0; refactor wave 1 did not introduce this.

Fix.

  • execFileBounded (src/core/brain-repo-durability.ts) settles from its own timer at the deadline or on abort, and SIGKILLs the child. It no longer depends on Bun delivering the exit or pipe event.
  • The durability probe (10 s) and the persistence effect git runner (20 s) now use it, with the same git_unavailable mapping as before.
  • The staged topology clone's exit wait also returns once its deadline kill fires.
  • consumer.stop() stays an unbounded barrier, because engine.close depends on it. Bounding the children is the fail-fast.

Evidence.

  • New test/bounded-child-exec.test.ts reproduces the dropped event deterministically. Against the old code the durability probe fails 2/2 and never settles; with the fix it passes on Bun 1.3.13.
  • Load loop on a 16-vCPU Ubicloud VM with 16 parallel workers: master hung 4 of 250 runs, all with git zombies; this branch hung 0 of 320.
  • bun run ci:ubicloud on bcd72973b was green: unit 2117, serial 350, slow 25, E2E 325, verify, gitleaks. bun run verify is also green after the version bump.

Follow-up (not in this PR). Moving CI to Bun ≥ 1.4 removes the whole class. Other async child waits, such as the minions supervisors, stay exposed until then.

Open in Capy

…nd consumer shutdown

Bun 1.3.x drops one-shot pidfd and pipe events when a callback re-enters the
event loop, as bun:test expect().resolves/.rejects does (oven-sh/bun#30301).
An execFile child whose exit is dropped stays a zombie and its callback, and
its own timeout, never fire. The persistence consumer's durability probe
(isDurabilityHardenedAsync, async since v0.60.10.0) spawns two git children
per git effect, so a test awaiting .rejects while effects drained could leave
the effects worker waiting forever; consumer.stop() awaits that worker, so
disposePersistenceConsumer and every later fixture in the file hung
("killed N dangling process" is Bun reporting the unreaped children at the
timeout). Seen in managed-maintenance, persistence-reconcile and
google-attachments E2E.

execFileBounded settles from its own timer at the deadline or on abort and
SIGKILLs the child. The durability probe and the persistence Git runner use
it; the topology clone's exit wait also returns once its deadline kill fires.
@trunk-io

trunk-io Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

😎 This pull request was merged.

@capy-ai
capy-ai Bot merged commit bdc36d5 into master Sep 30, 2026
110 of 112 checks passed
garrytan added a commit that referenced this pull request Sep 30, 2026
harjothkhara added a commit to harjothkhara/gbrain that referenced this pull request Sep 30, 2026
Merges master's bounded async git children fix (garrytan#5787) into this
branch. Non-absorption confirmed: master's diff between
7ef5165..bdc36d5 has no src/commands/sources.ts or
test/sources.test.ts entry. Version-lockstep files bumped from
0.60.15.1 to 0.60.16.1; derived artifacts (template repo, plugin tree)
regenerated.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
garrytan added a commit that referenced this pull request Sep 30, 2026
harjothkhara added a commit to harjothkhara/gbrain that referenced this pull request Sep 30, 2026
Merges master's bounded async git children fix (garrytan#5787) into this
branch. Non-absorption confirmed: docs/architecture/key-files/core-ai.md,
src/core/ai/errors.ts, src/core/ai/recipes/openrouter.ts, and both this
PR's test files are byte-identical between the pre-merge base and
master's new head. Version-lockstep files bumped from 0.60.15.1 to
0.60.16.1; derived artifacts (template repo, plugin tree) regenerated.

Agent-Id: agent-1ce06382-5a83-4028-99b7-7d86c5e1ed00
harjothkhara added a commit to harjothkhara/gbrain that referenced this pull request Sep 30, 2026
Merges master's bounded async git children fix (garrytan#5787) into this
branch. Non-absorption confirmed: master's diff between
7ef5165..bdc36d5 does not touch
src/commands/doctor/bootstrap-checks.ts, src/core/pglite-lock.ts,
src/core/bootstrap/uninstall.ts, or the export-surface goldens fixed in
an earlier cycle. Version-lockstep files bumped from 0.60.15.1 to
0.60.16.1; derived artifacts (template repo, plugin tree) regenerated.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
garrytan added a commit that referenced this pull request Sep 30, 2026
…t parks the page

Hosted CI's w5 "a healthy scan and contention never park" ended queued with
git_unavailable and target_failures 2 on notes/page-7. Since #5787 a bounded
git run that is aborted (consumer shutdown) or hits its deadline is SIGKILLed,
which skips git's own lock cleanup, so the .git/index.lock of an interrupted
add/commit failed every later attempt and was counted as a target failure
(probe: SIGKILL leaves the lock 2/2, SIGTERM removes it 2/2).

- A killed run removes the index lock it created (mtime at or after the run's
  start); the persistence owner runs the checkout's git under its native
  worktree lock, so that lock is its own.
- An exit-128 failure with an index lock present is git_index_locked, retried
  as contention without counting toward parking, while the lock is younger
  than 10 minutes; an older lock fails as git_unavailable naming the path and
  the fix.

test/persistence-effect-git-index-lock.test.ts fails on the previous code
(3/3) and passes now; the SIGKILL case uses a git that takes the lock and
hangs, so the abort always lands mid-write.
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