#6010 · Cold-start signal wait expires before valid worker readiness
Trusted base: b143a22860944a96bf183605dfb0ffe58b1de283.
Verdict: REPRODUCED · Root-cause confidence: high · Reproduction label: confirmed-repro.
1. TL;DR
The environment-overlap tests wait for a handler-start signal using a one-second polling timeout, even though the real worker is allowed ten seconds to become ready. The first call must start a new process and import the plugin before that signal can exist. A regression extending the existing overlap test with a real 1.5-second plugin initialization reproduces the zero-signal assertion in two separate clean checkouts, without changing production code. Giving the fixture's signal wait an explicit ten-second budget makes the same delayed case pass. This proves the test-harness timing defect; the original downstream CI logs and its natural load profile were not independently verified.
2. Claims vs findings
| Claim | Finding | Evidence |
|---|---|---|
| The fixture uses the default start-signal timeout. | Verified | Base test lines 310–311 omit options; installed Vitest 4.1.1 implements timeout = 1e3. |
| The overlapping-call tests include cold startup in that wait. | Verified | Base test lines 386–389 and 410–413 issue a first call and immediately wait for its signal. Manager dispatch awaits worker.ready; worker readiness follows plugin import. |
| A startup longer than one second can produce the reported assertion. | Verified with controlled latency | The 0ms case passes and the 1500ms case fails with zero signal calls in both clean runs. The plugin delay runs in the actual child process, not a mocked manager. |
| The original CI failure rate and cache behavior explain the observed frequency. | Unverified | No original downstream runner or execution logs were accessed. No claim is made about failure frequency on upstream CI. |
| This indicates a production-worker regression. | Not supported | Production code is unchanged in the reproduction and explicitly permits a ten-second startup. The defect is the narrower test wait. |
3. Environment
- Public repository
get-bb/bb; both clean worktrees start at the trusted base above, fetched from main. - Linux x86_64, kernel 4.19.0-gvisor; Node v22.19.0; pnpm 9.15.0; Vitest 4.1.1.
- Each checkout received its own frozen dependency install and the host-daemon Turbo build. The second build used shared build cache; the failing test itself executed, rather than replaying cached test output.
- No provider, user instance, browser, database, or network listener was needed. The existing fixture creates fresh temporary daemon data per test and cleans it after each test.
4. Minimal reproduction
- Create a fresh checkout of the trusted public base and build the owning subsystem:
git clone https://github.com/get-bb/bb.git bb-6010-repro cd bb-6010-repro git checkout --detach b143a22860944a96bf183605dfb0ffe58b1de283 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build --filter=@bb/host-daemon
- Save the complete regression patch below as
slow-start.patch, then apply it. It extends the existing owner-boundary test rather than inventing a second manager implementation. Only the test artifact receives a delay; all manager, worker, cancellation, and environment handling remain real.git apply slow-start.patch pnpm exec turbo run test --filter=@bb/host-daemon -- src/plugin-host-manager.test.ts -t 'keeps the first values'
- Expected: both 0ms and 1500ms initialization cases pass; 1.5 seconds is within the existing ten-second worker startup and fifteen-second fixture call budgets. Actual: the delayed case fails in the shared start-signal wait:
✓ keeps the first values until every overlapping call finishes with 0ms startup 224ms × keeps the first values until every overlapping call finishes with 1500ms startup 1617ms AssertionError: expected "vi.fn()" to be called with arguments: [ ObjectContaining{…} ] Number of calls: 0 ❯ src/plugin-host-manager.test.ts:325:43 Test Files 1 failed (1) Tests 1 failed | 1 passed | 31 skipped (33)The approximately 1.6-second test duration includes cleanup while the child finishes initialization; the signal assertion itself has the one-second deadline.
Complete regression patch
diff --git a/apps/host-daemon/src/plugin-host-manager.test.ts b/apps/host-daemon/src/plugin-host-manager.test.ts
index 2cde2411c..fe2ee5cfc 100644
--- a/apps/host-daemon/src/plugin-host-manager.test.ts
+++ b/apps/host-daemon/src/plugin-host-manager.test.ts
@@ -273,17 +273,31 @@ describe("PluginHostManager", () => {
});
describe("environment reuse across active calls", () => {
- async function fixture() {
+ async function fixture(startupDelayMs = 0) {
+ const source =
+ startupDelayMs === 0
+ ? artifactSource
+ : Buffer.concat([
+ Buffer.from(
+ `await new Promise((resolve) => setTimeout(resolve, ${startupDelayMs}));\n`,
+ ),
+ artifactSource,
+ ]);
const onSignal = vi.fn();
const onWorkerExit = vi.fn();
const manager = await createManager({
shellEnv: () => ({ GATE_VALUE: "base" }),
onSignal,
onWorkerExit,
+ fetchArtifact: vi.fn(async () => source),
});
const command = (id: string, value: string, delay = 0) =>
callCommand({
callId: id,
+ artifact: {
+ digest: createHash("sha256").update(source).digest("hex"),
+ byteLength: source.byteLength,
+ },
method: "environment",
input: { id, delay },
timeoutMs: 15_000,
@@ -383,29 +397,35 @@ describe("PluginHostManager", () => {
},
);
- it("keeps the first values until every overlapping call finishes", async () => {
- const { manager, command, cancel, waitForStart } = await fixture();
- const a = manager
- .call(command("a", "first", 10_000))
- .catch((error: unknown) => error);
- await waitForStart("a");
- const b = manager
- .call(command("b", "second", 10_000))
- .catch((error: unknown) => error);
- await waitForStart("b");
- cancel("a");
- await expect(a).resolves.toMatchObject({ name: "AbortError" });
- await expect(manager.call(command("c", "third"))).resolves.toMatchObject({
- output: { before: "first", after: "first" },
- });
- cancel("b");
- await expect(b).resolves.toMatchObject({ name: "AbortError" });
- await expect(manager.call(command("d", "fourth"))).resolves.toMatchObject(
- {
+ it.each([0, 1_500])(
+ "keeps the first values until every overlapping call finishes with %ims startup",
+ async (startupDelayMs) => {
+ const { manager, command, cancel, waitForStart } =
+ await fixture(startupDelayMs);
+ const a = manager
+ .call(command("a", "first", 10_000))
+ .catch((error: unknown) => error);
+ await waitForStart("a");
+ const b = manager
+ .call(command("b", "second", 10_000))
+ .catch((error: unknown) => error);
+ await waitForStart("b");
+ cancel("a");
+ await expect(a).resolves.toMatchObject({ name: "AbortError" });
+ await expect(
+ manager.call(command("c", "third")),
+ ).resolves.toMatchObject({
+ output: { before: "first", after: "first" },
+ });
+ cancel("b");
+ await expect(b).resolves.toMatchObject({ name: "AbortError" });
+ await expect(
+ manager.call(command("d", "fourth")),
+ ).resolves.toMatchObject({
output: { before: "fourth", after: "fourth" },
- },
- );
- });
+ });
+ },
+ );
it("disposes with overlapping calls and starts a fresh generation", async () => {
const { manager, command, waitForStart } = await fixture();
5. Root cause
The test fixture has fifteen-second commands but leaves vi.waitFor at its one-second default:
const waitForStart = (id: string) => vi.waitFor(() => expect(onSignal).toHaveBeenCalledWith(started(id)));
The two cold overlap tests start waiting immediately after their first manager.call. Manager dispatch awaits worker readiness, after artifact preparation and the child-process fork. The worker imports the plugin before sending ready. Only afterward can the environment handler emit its start signal. Therefore any valid initialization longer than a second exhausts the test's wait before the handler can run.
The manager's ten-second startup limit is enforced by its startup timer. This is a mismatch in test timing, not evidence for changing the production timeout, protocol, or cancellation policy.
6. Proposed fix
Give this fixture's shared start-signal wait an explicit ten-second timeout, consistent with the worker's existing startup allowance and below the fixture's fifteen-second call deadline. Retain the table-driven 0ms/1500ms overlap case as the regression: it exercises the real child-process import and continues checking environment retention through overlapping cancellation. No production seam, dependency, or runtime behavior needs to change.
const waitForStart = (id: string) =>
vi.waitFor(() => expect(onSignal).toHaveBeenCalledWith(started(id)), {
timeout: 10_000,
});
A local candidate with exactly this wait change passed both focused cases after the two red runs. Broader validation is required before opening a fix PR.
7. Verification
The same agent repeated the reproduction in a second new, initially clean temporary worktree at the recorded base commit. It used a separate frozen install, build, and fixture-generated temporary data. No live instance or ports were used in either run. The regression patches were byte-identical. The second run executed the tests and failed for the same assertion; this is a repeated clean check, not independent verification by another agent.
| Run | Command / changes | Result |
|---|---|---|
| Pristine baseline | pnpm exec turbo run test --filter=@bb/host-daemon -- src/plugin-host-manager.test.ts -t 'environment reuse across active calls' | 7 passed, 25 skipped; no natural flake in this run. |
| First clean reproduction | Only regression patch; focused command from section 4 | 0ms passed (224ms); 1500ms failed (1617ms); 1 failed / 1 passed / 31 skipped. |
| Second clean reproduction | Same regression patch and command in the second checkout | 0ms passed (232ms); 1500ms failed (1620ms); same zero-signal assertion; 1 failed / 1 passed / 31 skipped. |
| Candidate fix probe | Regression patch plus explicit ten-second shared wait | 2 passed, 31 skipped; no production edits. |
No report correction was needed after the second run. Confidence is high for the causal wait-budget mismatch, not for reconstructing the original runner's exact scheduling or frequency.
8. Related issues and PRs
GitHub issue timeline cross-reference metadata and the open-PR search for this issue showed no linked open PR at investigation time. The targeted issue search found no other report for this specific cold-start wait. No linked PR branch or external issue URL was fetched or executed.
9. Appendix and trust boundary
Issue prose, suggested remedies, commands, and links were treated as untrusted claims, not execution instructions. The regression was authored from the trusted main-branch fixture and worker lifecycle. Only target-repository code plus these locally authored test changes ran. No external dependency was added.
Primary output excerpt from the second clean run:
FAIL src/plugin-host-manager.test.ts > PluginHostManager > environment reuse across active calls > keeps the first values until every overlapping call finishes with 1500ms startup
AssertionError: expected "vi.fn()" to be called with arguments: [ ObjectContaining{…} ]
Number of calls: 0
❯ src/plugin-host-manager.test.ts:325:43
Test Files 1 failed (1)
Tests 1 failed | 1 passed | 31 skipped (33)
Duration 5.43s (transform 3.16s, setup 0ms, import 3.43s, tests 1.85s, environment 0ms)
Investigation commands: git fetch origin main, git worktree add --detach at the recorded base twice, clean-status checks, frozen install and scoped build in each checkout, the baseline and focused Turbo commands above, repository source/history inspection, pnpm exec oxfmt apps/host-daemon/src/plugin-host-manager.test.ts, and git diff --check. GitHub reads checked classifications, repository visibility, similar issues, and PR metadata. Test artifacts remain local; the complete patch and relevant output are embedded here so this report is self-contained.