Skip to content

Keep bridge lifecycle checks independent of provider startup - #8136

Merged
ymichael merged 2 commits into
mainfrom
bb/nov24-flake-bridge
Nov 24, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/nov24-flake-bridge

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

The Linux OOM test required a deprioritized child to start within one second. The retirement test initialized two full scripted providers within a single test deadline. Failing run.

What changed

Use real idle children for lifecycle checks. Request the kernel OOM score through the child’s pipe and register manager cleanup before assertions.

How you verified

The process lifecycle suite passed on macOS. The Linux-only OOM assertion runs in CI.

AGENT GENERATED

@ymichael
ymichael merged commit a1ad3f7 into main Nov 24, 2026
33 checks passed
@ymichael
ymichael deleted the bb/nov24-flake-bridge branch November 24, 2026 22:06
ymichael added a commit that referenced this pull request Nov 24, 2026
Two process-manager tests still started the full scripted-echo bridge twice
to check process bookkeeping (5.9-7.2 s and 2.7 s on CI). Use the idle
provider manager from #8136, as the retire test now does. The old-hash test
also launched its second process with the same launch as the first, so the
thread-ownership guard it names was never exercised; it now uses the
superseding launch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael added a commit that referenced this pull request Nov 24, 2026
## Human comments

## What was wrong

#8136 moved `retires a threadless bridge process superseded by a new
artifact hash` onto idle children, because two full scripted-echo starts
can exceed the 15 s test deadline under CI load. Two sibling
process-manager tests still started the full bridge twice to check the
same bookkeeping:

| Test | CI time |
|---|---|
| `keeps an old-hash bridge process that still owns a thread` | 5.9 s
and 7.2 s |
| `waits for provider retirement before starting a same-key replacement`
| 2.7 s |

Reproduced in a Linux `node:22` container under CPU load (24 busy loops
on 16 cores). Each full bridge start took 3.7–4.6 s, while retiring a
process took 20–40 ms, so these tests are one busy runner away from the
same timeout.

`keeps an old-hash bridge process that still owns a thread` also didn't
test what its name says. It launched the "new" process with the same
`bridgeLaunch` as the old one, so the old process was never stale. The
guard it names (`threadIds.size === 0` in `retireStaleBridgeProcesses`)
could be deleted without the test failing.

## What changed

`packages/agent-runtime/src/runtime.process-lifecycle.test.ts` only.

- Both tests use `createIdleProviderManager` from #8136.
- The old-hash test launches its second process with
`SUPERSEDING_BRIDGE_LAUNCH`.

No production code changes.

## How you verified

- Mutation check: with `providerProcess.identity.threadIds.size === 0`
removed from `retireStaleBridgeProcesses`, the old-hash test now fails.
On `main` it passes with that guard removed.
- `pnpm exec turbo run test typecheck lint --filter=@bb/agent-runtime`
passes: 314 passed, 1 skipped.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael added a commit that referenced this pull request Nov 25, 2026
"does not wait for stalled replacement initialization during full
shutdown" started and retired a full scripted-echo bridge before its
stalled replacement, and that start and retirement took 3-12 s on loaded
CI runners against a 15 s deadline. When it overran, the timed-out test
body kept running after afterEach removed tmpDir and spawned the
replacement into the missing cwd, which surfaced as an unhandled
"spawn node ENOENT". The first process is now the idle child that #8136
and #8141 use for the sibling retirement tests; the stalled replacement
still uses the real fake adapter so it receives initialize and holds its
reply.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael added a commit that referenced this pull request Nov 25, 2026
…ess start speed (#8147)

## Human comments

## What was wrong

Two tests in
`packages/agent-runtime/src/runtime.process-lifecycle.test.ts` fail at
random in `Tests (packages-host)` on loaded runners. Both depend on how
fast processes start under CPU load.

**`drains provider stderr before reporting process exit`** fails with
`expected null to be 'stderr-after-exit'`, for example on #8075's merge
run
([job](https://github.com/get-bb/bb/actions/runs/45507748534/job/138847431154),
2286 ms). The fake provider spawned a grandchild that inherits stderr,
then exited at once. The grandchild had to boot Node and wait 50 ms
before writing. After a provider exits, the runtime waits at most
`PROVIDER_PROCESS_CLOSE_GRACE_MS` (1 s) for stderr to close. On a loaded
runner, Node startup alone can take longer than that.

**`does not wait for stalled replacement initialization during full
shutdown`** times out at 15 s, followed by an unhandled `Provider "fake"
failed to start: spawn .../node ENOENT`
([job](https://github.com/get-bb/bb/actions/runs/45506198560/job/138847994142);
it failed on all three attempts of that branch, and took 12.1 s on
#8076's passing run). Before reaching its stalled replacement, the test
started and retired a full scripted-echo bridge. #8141 measured a full
start at 3.7–4.6 s under load, and stopping one can take up to 5 s plus
kill and stderr grace periods. On other PRs' loaded runs the test took
3–12 s. When it overran, Vitest timed the test out but its body kept
running. `afterEach` removed `tmpDir`, and the replacement then spawned
into the missing cwd, which Node reports as `spawn <node> ENOENT`. The
ENOENT is a consequence of the timeout, not its cause. #8136 and #8141
fixed the sibling retirement tests the same way; this one was left.

## What changed

`runtime.process-lifecycle.test.ts` only. No runtime code changes.

- **stderr drain:** the grandchild reports ready over IPC, the provider
exits only after that, and the grandchild writes to stderr 50 ms after
the IPC channel disconnects, which happens when the provider exits. The
write still lands after the exit, but Node startup no longer counts
toward the 1 s grace period.
- **stalled shutdown:** the first process is the idle child
(`process.stdin.resume()`, no post-initialize requests) that the sibling
tests use. The adapter it uses is pulled out into a `createIdleAdapter`
helper that `createIdleProviderManager` now shares. The replacement
still uses the real fake adapter on the raw stalled script, so it
receives `initialize` and holds its reply for 3 s, which is the behavior
under test.

## How you verified

CPU starvation locally: the test runs at background QoS (`taskpolicy
-b`) next to 32 busy-loop processes on a 16-core Mac. This reproduces
both CI failures.

| Test | Before | After |
|---|---|---|
| stderr drain | 2 CI-assertion failures before I stopped it | 6 of 6
pass |
| stalled shutdown | 2 of 4 time out (18.9 s, 21.4 s); passes took 13.1
s and 2.3 s | 4 of 4 pass in 198–358 ms |

Both tests still catch the bugs they guard:

- stderr drain: with `PROVIDER_PROCESS_CLOSE_GRACE_MS` temporarily set
to 0, the new test fails 3 of 3.
- stalled shutdown: with `shutdown()` temporarily changed to await
in-flight provider starts, the new test fails.

`pnpm exec turbo run typecheck lint test --filter=@bb/agent-runtime`:
pass (316 tests, 1 skipped).

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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