Repository navigation
Conversation
ymichael
added a commit
that referenced
this pull request
Sep 8, 2026
## Human comments ## What was wrong The recurring [packages job failure](https://github.com/get-bb/bb/actions/runs/34275422905/job/102227127822) was triggered by package-shard CPU contention but rooted in a lifecycle mismatch in the test. The runtime started its 200 ms `thread/start` request deadline after provider initialization but before the bridge necessarily handled the request and spawned the app-server child. The test then required `spawned === 1 && exited === 1`; when cancellation retired the bridge before its request handler ran, no child could ever publish either marker. An instrumented 24-run stress reproduced 22 exact failures, all with `spawned=0`, `exited=0`, no child PID, and an expected bridge exit. The predicate-before-deadline polling fix from #2352 remains present; this was an impossible lifecycle state rather than a missed final poll. The audit of closed PR #2506 also confirmed that its adjacent child-stdin finding remains real on current `main`: a live app-server child that closes fd 0 produced an unhandled `EPIPE` and left its request pending. Current `main` has since made `kill()` awaitable in #3025, so the old patch could not be reused unchanged. The package shard's nested concurrency is systemic: CI runs four Turbo package tasks on a 4-vCPU runner, and each package's Vitest process independently schedules worker pools. That explains the reproduction condition, but it is not the root cause addressed here. The independently verified merge base is `06047280e04e6ce57554052ec788a1c5defe7d1e`. ## What changed - Pre-start the shared Codex bridge outside the construction deadline scenario, stall the fake `thread/start`, hold only the runtime's request clock until the real child publishes its spawn marker, then advance the unchanged 200 ms deadline. The test still requires the child to record its SIGTERM exit and verifies its PID is gone. - Publish the fake child's spawn marker only after its SIGTERM handler is installed, and replace the elapsed 800 ms response delay with a construction that remains pending until release. - Treat child-stdin `EPIPE` and `ERR_STREAM_DESTROYED` as terminal connection failures. New work is rejected immediately, the unusable child is force-stopped, and pending work still finalizes on the observable child exit/close boundary so natural exit status, stderr, and final stdout are preserved. The current awaitable `kill()` contract remains intact. - Add real-child regressions for post-exit stdout draining, EPIPE immediately before a natural exit, and containment of a live child with closed stdin. No request, polling, release, or test timeout was increased. There is no server/daemon wire change, so `HOST_DAEMON_PROTOCOL_VERSION` is unchanged. There are no CLI, SDK, guide, or configuration-surface changes. ## How you verified - Original red-capable exact stress on the enrolled 8-logical-CPU Intel host, 64 runs at 32-way parallelism: - Before: 5/64 passed; 59/64 failed with the exact `Timed out after 10000ms waiting for the late-constructed child was released` signature. - Instrumented classification: 22/24 exact failures; every failure recorded `spawned=0`, `exited=0`, no child PID, and `bridgeExits=[{expected:true}]`. - Final: 64/64 passed with no timeout, EPIPE, or survivor; test-body p50/p95/max were 21.48 s / 24.16 s / 24.51 s under deliberate 4x oversubscription. - Closed-stdin regression before the connection change: failed deterministically because the request remained pending past 500 ms and Vitest captured an unhandled `write EPIPE`. After: the three-test connection file passed, then passed 32/32 parallel stress runs with no unhandled error or survivor. - `pnpm exec turbo run test --filter=@bb/agent-runtime -- --run src/runtime.codex-topology.test.ts` — 1 file / 4 tests passed. - `pnpm exec turbo run test --filter=bb-plugin-provider-codex -- --run src/bridge/app-server-connection.test.ts` — 1 file / 3 tests passed. - `pnpm exec turbo run test --filter=@bb/agent-runtime --force` — 22 files / 318 tests passed. - `pnpm exec turbo run test --filter=bb-plugin-provider-codex --force` — 27 files / 264 tests passed. - A combined two-package test run made nested contention visible: the Codex provider passed, while agent-runtime hit three unrelated existing failures in ACP topology and process-lifecycle tests. Both package suites passed independently, and the changed focused tests remained green. - `pnpm exec turbo run typecheck --filter=@bb/agent-runtime --filter=bb-plugin-provider-codex --force` — passed. - `pnpm exec turbo run build --filter=@bb/agent-runtime --filter=bb-plugin-provider-codex --force` — passed (the scoped packages have no direct build tasks; their applicable dependency graph passed). - `pnpm exec prettier --check packages/agent-runtime/src/runtime.codex-topology.test.ts plugins/provider-codex/src/bridge/app-server-connection.ts plugins/provider-codex/src/bridge/app-server-connection.test.ts plugins/provider-codex/src/bridge/fake-codex-app-server.mjs` — passed. - Every reproduction, stress, test, typecheck, and build command ran inside a bounded process group on `host_nwqfteeqz4`; cleanup checks reported no surviving group or matching test/fake-child process. Fixes: no issue — exact path/signature searches found no open issue or PR, and the prior BB owners are archived without environments. > AGENT GENERATED
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
The recurring packages failure was amplified by package-shard CPU oversubscription but rooted in two lifecycle races. First, the topology test started a 200 ms real-time request deadline before the app-server subprocess had executed, then required the fake to have logged both
spawn:andexit:; under contention the runtime correctly released the construction before the fake ran its first line, sospawned() === 1 && exited() === 1was impossible forever. Instrumentation reproduced that state in all 40/40 stressed failures (spawned=0, no live PID, no failed-release warning). Second, once the test made the construction boundary deterministic, release could kill the app-server while the Codex bridge was making its next initialization write; the resulting child-stdinEPIPEwas unhandled and crashed the shared bridge.Review of the initial containment found two distinctions inside that fix. An unwritable stdin after the child had already emitted
exitis part of the existing bounded stdout-drain window, not a new transport failure. Treating it as broken stdin cleared pending requests before final protocol output arrived and replaced the real exit code/stderr diagnostic withstdin failed. An asynchronous EPIPE can also arrive immediately before Node emits the child's realexit; finalizing synchronously at EPIPE preserved stderr but replaced a real code 7 with synthetic{ code: null, signal: null }. Conversely, a genuine closed stdin before child exit is irrecoverable and must make the connection terminal immediately so the bridge can rebuild it.This is distinct from #2352: its predicate-before-deadline polling fix remains intact, and these failures were real lifecycle states that never satisfied the predicate. The independently verified merge base is
524b2fe4b0df74185bdd29a274fb77cd6765b2b3.What changed
thread/start, freeze only the runtime request clock until the real child has started, advance the existing 200 ms deadline, and assert both that its SIGTERM handler recorded a graceful exit and that the recorded PID is gone. The fake installs that handler before publishingspawn, and its obsoletestartDelayMsoption was removed.exitare ignored while final output continues to settle pending requests, and normal finalization retains the real exit status and stderr tail.EPIPEandERR_STREAM_DESTROYED) as terminal connection failures. The connection reportsexitedand rejects new work immediately, records the transport detail, and force-stops the unusable child. The already-pending request andonExitfinalize through the child's observableexit/closeboundary, preserving a natural exit code or the SIGKILL signal plus any final stdout. Unexpected stdin errors are not silently reclassified.There is no server/daemon wire-contract change, so
HOST_DAEMON_PROTOCOL_VERSIONis unchanged. There are no CLI, guide, or configuration-surface changes.How you verified
Timed out after 10000ms waiting for the late-constructed child was releasedsignature. Test-body p50/p95/max were 2.59 s / 3.01 s / 12.62 s.stdin failed, andconnection.exitedremained false after EPIPE. After: all passed.stdin failed (EPIPE)with null status. After: the request andonExitretain code 7 and stderr. The four-test connection suite passed 32/32 parallel stress runs on 16 CPUs.pnpm exec turbo run test --filter=@bb/agent-runtime -- --run src/runtime.codex-topology.test.ts— 1 file / 4 tests passed.pnpm exec turbo run test --filter=bb-plugin-provider-codex -- --run src/bridge/app-server-connection.test.ts— 1 file / 4 tests passed.pnpm exec turbo run test --filter=@bb/agent-runtime --filter=bb-plugin-provider-codex --force— agent-runtime 22 files / 318 tests and Codex provider 25 files / 242 tests passed.pnpm exec turbo run typecheck --filter=@bb/agent-runtime --filter=bb-plugin-provider-codex --force— passed under the same unrelated CPU contention.pnpm exec turbo run build --filter=@bb/agent-runtime --filter=bb-plugin-provider-codex --force— applicable Turbo build graph passed (the two scoped packages have no direct build scripts).pnpm exec prettier --check packages/agent-runtime/src/runtime.codex-topology.test.ts plugins/provider-codex/src/bridge/app-server-connection.ts plugins/provider-codex/src/bridge/app-server-connection.test.ts plugins/provider-codex/src/bridge/fake-codex-app-server.mjs— passed.Fixes: no issue — exact and fuzzy open issue/PR searches found no active recurrence fix.