Skip to content

Stabilize Pi bridge process-backed tests - #2337

Merged
ymichael merged 1 commit into
mainfrom
bb/ci-flake-fix-provider-pi-install-gate-and-fork-i-thr_ieynikwk4n
Aug 24, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/ci-flake-fix-provider-pi-install-gate-and-fork-i-thr_ieynikwk4n

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

What was wrong

The Pi bridge tests exercise real Node child processes, but the two install-gate cases that cold-start the catalog child inherited Vitest’s 5 s default and the conformance wrapper passed only a 10 s per-wait protocol budget. Under the 4-vCPU packages shard contention, the same fork-helper path took 11.47 s in its correctly budgeted lifecycle test, so these smaller limits expired while valid bridge work was still running. Vitest does not cancel a timed-out async body; because each install-gate scenario then reused JSON-RPC request id 1 with a fresh stdout capture, a late response from the timed-out scenario could satisfy the next test and produce the unsupported/not-installed assertion cascade. The failures are visible in the main run and unrelated PR #1781 and PR #1785 runs.

What changed

The two install-gate cases that actually cold-start RPC children now use the same 30 s class of test budget as the neighboring Pi process tests, and conformance waits up to 30 s for each protocol response while retaining the existing 60 s wrapper. Install-gate request ids are monotonic across the file, so any late result remains diagnostic noise instead of being mistaken for another scenario’s response. Assertions and production behavior are unchanged. This is test-only and does not change the host-daemon wire protocol.

How you verified

Before the change, the cited CI runs crossed the old limits, and a controlled local stress run with 64 competing CPU burners stretched the unchanged conformance test to 18.4 s and the two install-gate process cases to 4.64 s and 4.35 s. After the change, three identical stress rounds passed all 6 focused tests; conformance took 12.01 s, 11.96 s, and 11.87 s without losing session/fork-identity.

  • pnpm exec vitest run src/bridge/bridge.install-gate.test.ts src/bridge/bridge.conformance.test.ts --config vitest.config.ts --reporter=dot --maxWorkers=1 — 6 passed
  • pnpm exec turbo run test --filter=bb-plugin-provider-pi --force — 17 files, 104 tests passed
  • pnpm exec turbo run typecheck --filter=bb-plugin-provider-pi --force — 4 Turbo tasks passed
  • pnpm exec turbo run build --filter=@bb/server --force — 4 Turbo tasks passed
  • pnpm exec oxfmt plugins/provider-pi/src/bridge/bridge.install-gate.test.ts plugins/provider-pi/src/bridge/bridge.conformance.test.ts --check — passed

AGENT GENERATED: by GPT-5.6-Sol

@ymichael
ymichael merged commit 47643f5 into main Aug 24, 2026
24 of 25 checks passed
@ymichael
ymichael deleted the bb/ci-flake-fix-provider-pi-install-gate-and-fork-i-thr_ieynikwk4n branch August 24, 2026 16:55
ymichael added a commit that referenced this pull request Aug 24, 2026
## What was wrong

The real-process crash/stop coverage serialized two independent
plugin-bridge Node startups: it fully started an unused healthy thread
before launching the provider that crashes mid-turn. Under the
73-package, 4-vCPU CI shard, that additive startup latency consumed the
test's unchanged 15-second wall-clock budget; the unrelated PR #2337 run
exposed a 15.292-second outlier. The test then polled a process-exit
callback with a second fixed timeout even though the runtime already
reports that transition directly.

## What changed

The test now creates the environment without an unused healthy provider
session, starts the required healthy keepalive process concurrently with
the crashing provider, and awaits the runtime's unexpected-process-exit
callback directly. It still launches both real provider subprocesses,
proves the process died with an active turn, verifies runtime-owned
cleanup and the synthesized failed completion, asserts the original
environment entry stayed loaded, and confirms the later stop never
reached a provider. The 15-second test budget and all crash/stop
assertions remain unchanged. This is test-only, so there is no
host-daemon protocol change.

## How you verified

- Before: a warm one-process case took 455ms, while the serialized crash
case took 1,062ms; under 96 controlled CPU competitors the crash case
took 2,189ms. A cold focused run took 6,060ms.
- After: the focused crash case took 421ms, the complete race file
passed all 4 cases (the warm crash case took 128ms), and the matching
96-worker contention run passed in 1,900ms without widening the timeout.
- `pnpm exec turbo run typecheck --filter=@bb/host-daemon --force`
- `pnpm exec turbo run build --filter=@bb/host-daemon --force`
- `pnpm exec turbo run test --filter=@bb/host-daemon --force` (44 files,
534 tests)

> AGENT GENERATED: by GPT-5.6-Sol
ymichael added a commit that referenced this pull request Aug 24, 2026
## What was wrong

The `PluginHostManager` native-watch test launches a real plugin host
worker, but it waited for host watch registration with Vitest's default
one-second budget. Under scheduler and process contention, worker
startup crossed that boundary before the watch could register. Test
teardown then disposed the manager while `manager.call` was still
pending, so the worker rejected that call and Vitest reported a
secondary unhandled rejection. That rejection is test-cleanup fallout,
not evidence of a production watch-disposal defect.

This matches the failure in [PR #2337's unrelated CI
run](https://github.com/get-bb/bb/actions/runs/32750957324): readiness
timed out at line 553, followed by the disposal rejection.

## What changed

Give only the cross-process watch-registration wait an explicit
five-second budget. The 20 ms idle timeout, 100 ms dwell, backpressure
checks, disposal assertion, and all production behavior remain
unchanged.

There are no host-daemon wire changes, so `HOST_DAEMON_PROTOCOL_VERSION`
is unchanged. No CLI or documentation surfaces changed.

## How you verified

- Before the change, the focused test passed normally but failed at line
553 under 256 controlled CPU competitors, with the secondary unhandled
rejection during cleanup.
- After the change, the same contended command passed; the focused test
took 1.95 seconds, beyond the former one-second readiness boundary.
- `plugin-host-manager.test.ts`: 19/19 passed.
- `pnpm exec turbo run build --filter=@bb/host-daemon`
- `pnpm exec turbo run typecheck --filter=@bb/host-daemon`
- `pnpm exec turbo run test --filter=@bb/host-daemon --force`: 44 files
and 534 tests passed.

> AGENT GENERATED: by GPT-5.6-Sol
ymichael added a commit that referenced this pull request Aug 24, 2026
## What was wrong

The Pi lifecycle test coupled two separate contracts. To prove that a
failed construction leaves no child, it requested a permanently
mismatched model. Production correctly treats an initial mismatch as a
transient auth race and retries eight times, so this single lifecycle
assertion launched nine real Node children in series and imported the
real Pi extension nine times. The test asserted only that more than one
child spawned and that all children exited; it did not need nine real
processes to prove cleanup. Under packages-shard contention, those
avoidable serial launches crossed the harness's unchanged 60-second
response deadline and produced `no response to thread/start` in the
[failed packages job on PR
#2349](https://github.com/get-bb/bb/actions/runs/32773414046/job/97578813957).

## What changed

The retry policy and real-process lifecycle coverage are now separate:

- `runPiTransientAuthConstruction` contains the unchanged production
policy and accepts injected construction, discard, closed-state, and
wait operations. A zero-process test deterministically proves one
initial attempt plus eight retries, eight failed-attempt discards, and
propagation of the ninth error.
- The existing real-process transient-mismatch test still proves that a
mismatched child is killed, a replacement child succeeds, and no
construction-time session error leaks.
- The failed-construction lifecycle test now uses a fake-Pi fault that
exits before its first response. It launches one real child and still
verifies the bridge error, exact spawn count, observed process exit, and
no child left behind.
- The scratch-file lifecycle case uses the same one-process construction
failure and verifies its tool/prompt files disappear after the child
exits.

The earlier timeout-only changes were reverted: the shared request
deadline remains 60 seconds, and the existing lifecycle wrappers remain
90 and 60 seconds. Production retry count, delay, child detachment, and
error behavior are unchanged. This does not alter the host-daemon wire
protocol, so `HOST_DAEMON_PROTOCOL_VERSION` is unchanged.

## How you verified

Before edits, the parent and worker independently confirmed that `HEAD`,
`origin/main`, and `git merge-base HEAD origin/main` all equaled
`21cb6b68b8fdffe2cd576f11c8af500f98d22c11`, with a clean worktree. Exact
GitHub issue/PR and bb thread searches found no overlapping lifecycle
fix; PRs #2337 and #2342 cover different provider-pi signatures.

The original coupled test reproduced the exact CI error under 256 CPU
competitors at 61.288 seconds: `Error: no response to thread/start`.
With the structural split and the original clocks restored, the
identical stress command passed with 150 milliseconds of lifecycle test
time (7.73 seconds total including imports). The deterministic
nine-attempt policy test completes in 1–2 milliseconds.

- Focused retry-policy and failed-construction coverage — 3 passed, 6
skipped
- `pnpm exec turbo run test --filter=bb-plugin-provider-pi --force` — 18
files, 105 tests passed
- `pnpm exec turbo run typecheck --filter=bb-plugin-provider-pi --force`
— 4 Turbo tasks passed
- `pnpm exec turbo run build --filter=@bb/server --force` — 4 Turbo
tasks passed
- `pnpm exec oxfmt
plugins/provider-pi/src/bridge/rpc-session.retry.test.ts --check` —
passed
- `git diff origin/main --check` — passed

> AGENT GENERATED: by GPT-5.6-Sol
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