#5080 · Session restoration uses the wrong request deadline
Verdict: REPRODUCED · Root-cause confidence: high
1. TL;DR
Restoring an existing provider session can fail even when the provider is healthy and eventually answers. The runtime gives new and forked sessions a two-minute construction deadline, but leaves restoration on the transport's shorter 30-second deadline. Two fresh checkouts reproduced this mismatch through the real runtime, bridge worker, JSON-RPC transport, and repository scripted-echo provider. Restoration also ignores an explicitly configured construction deadline: a request configured for 500 ms incorrectly succeeds after that deadline. A one-line runtime correction makes both restoration cases behave as specified while keeping the existing new-session behavior.
2. Claims vs findings
| Reported claim, paraphrased | Finding | Evidence |
|---|---|---|
| Restoration falls back to the transport deadline. | Verified | At 30,001 ms of simulated runtime time, restoration rejects with the exact transport timeout. The start-session control succeeds. |
| Start and fork already use the construction deadline. | Verified | Both sendCommand call sites pass the same construction deadline in the pinned source; start is also exercised as the behavioral control. |
| The pi bridge responds only after session initialization. | Verified in source | The construction function awaits session.start(); the resume handler awaits construction before sending the identity result. |
| The reported large session takes over 30 seconds on the affected host. | Not independently measured | No production data, private session, or real pi account was accessed. Provider latency is modeled using the repository's existing scripted provider and parent-process fake timers. |
| Restoration needs a new test-provider delay control. | Refuted | The existing startDelayMs fixture already delays resume and fork as well as start. No provider or protocol change is needed. |
3. Environment
- Public repository: get-bb/bb; trusted origin/main commit
68a1e8b7aa84fbd836eb8825e4d042ae0c52e74a, package version 0.45.0. - Linux 4.19.0-gvisor x86_64; Node v22.19.0; pnpm 9.15.0; Vitest 4.1.1.
- Repository scripted-echo provider loaded through the actual built bridge worker and bridge artifact. Provider construction delay: 1,500 ms of real child-process time. Only parent runtime timers are advanced.
- Two separate temporary Git worktrees:
base/andverification/. Each received a frozen dependency install and normal Turbo build; both builds passed all 64 tasks. - No HTTP server, browser, or public port was started. Each runtime and fixture uses fresh temporary workspace/provider directories; shutdown reaps its worker processes.
4. Minimal reproduction
- Check out the pinned trusted base, install and build it, then apply only the independently authored regression-test patch:
git clone https://github.com/get-bb/bb.git bb-5080 cd bb-5080 git checkout 68a1e8b7aa84fbd836eb8825e4d042ae0c52e74a pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build curl --fail --output regression.patch https://get-bb.github.io/reports/issues/5080/repro/regression.patch git apply regression.patch pnpm exec turbo run test --filter=@bb/agent-runtime -- src/runtime.lifecycle.test.ts -t 'uses the construction deadline'
- The test waits until the child bridge has received the session-construction request. It advances the parent's runtime clock while the child has a real delayed reply. Three cases exercise the same production boundary:
- Default start deadline: advance 30,001 ms; expect successful construction.
- Default resume deadline: advance 30,001 ms; expect successful construction.
- Resume with a 500 ms construction deadline: advance 501 ms; expect timeout and removal of failed runtime session state.
- Expected before fixing production: the new restoration expectations fail, while the original start control passes. Observed in both runs:
Test Files 1 failed (1) Tests 2 failed | 1 passed | 23 skipped (26) Default resume: expected status "resolved"; received status "rejected" Error message: JSON-RPC request timed out: thread/resume Configured 500 ms resume: expected status "rejected"; received status "resolved"
The skipped tests are intentional name-filter exclusions, not unavailable providers. Download the test-only patch and test case excerpt. The excerpt belongs inside the existing lifecycle suite; the patch is the executable reproduction artifact.
Complete regression case
it.each([
{
method: "start",
requestTimeoutMs: undefined,
advanceMs: 30_001,
timesOut: false,
},
{
method: "resume",
requestTimeoutMs: undefined,
advanceMs: 30_001,
timesOut: false,
},
{
method: "resume",
requestTimeoutMs: 500,
advanceMs: 501,
timesOut: true,
},
] as const)(
"uses the construction deadline for thread/$method (requestTimeoutMs=$requestTimeoutMs)",
async ({ method, requestTimeoutMs, advanceMs, timesOut }) => {
const realSetTimeout = setTimeout;
const sleepReal = (ms: number): Promise<void> =>
new Promise((resolve) => {
realSetTimeout(resolve, ms);
});
vi.useFakeTimers();
const record = createScriptedEchoRequestRecord();
const runtime = createScriptedEchoRuntime({
runtime: {
workspacePath: tmpDir,
env: record.env,
onEvent: () => undefined,
threadCreation: { requestTimeoutMs },
},
launch: { scripted: { startDelayMs: 1_500 } },
});
let settled = false;
const threadArgs = {
environmentId: "env-1",
threadId: "t1",
projectId: "p1",
providerId: "fake",
options: fullRuntimeOptions,
};
const construction =
method === "start"
? runtime.startThread(threadArgs)
: runtime.resumeThread({
...threadArgs,
providerThreadId: "prov-1",
});
const constructionOutcome = construction.then(
(result) => ({ status: "resolved" as const, result }),
(error: unknown) => ({ status: "rejected" as const, error }),
);
void constructionOutcome.then(() => {
settled = true;
});
try {
for (
let attempt = 0;
record.last(`thread/${method}`) === undefined;
attempt += 1
) {
if (attempt >= 1_000) {
throw new Error(`The bridge never received thread/${method}`);
}
await sleepReal(10);
}
await vi.advanceTimersByTimeAsync(advanceMs);
if (timesOut) {
expect(await constructionOutcome).toEqual({
status: "rejected",
error: new Error(`JSON-RPC request timed out: thread/${method}`),
});
expect(runtime.hasThread("t1")).toBe(false);
expect(runtime.getProviderSession("t1")).toBeNull();
} else {
expect(settled).toBe(false);
expect(await constructionOutcome).toEqual({
status: "resolved",
result: { providerThreadId: "prov-1" },
});
}
} finally {
vi.useRealTimers();
await runtime.shutdown();
}
},
);
5. Root cause
The runtime's construction timeout setting defaults to 120,000 ms. The start and fork call sites forward that value to sendCommand. The resume call forwards only the command, result schema, and recovery metadata:
const result = await sendCommand({
proc,
message: plan,
resultSchema: threadIdentityResultSchema,
recovery: {
providerId,
providerThreadId: adapterCommand.providerThreadId,
threadId,
},
});
sendCommand forwards an optional timeout only when supplied. The JSON-RPC request timer therefore selects its 30,000 ms fallback. This also explains the opposite configured-deadline failure: choosing a shorter construction limit has no effect on resume.
On pi, constructPiThreadSession awaits session.start() at line 777. The resume construction handler does not send its result until that construction finishes. Thus, a construction that takes between 30 seconds and the intended two-minute limit is rejected prematurely. The test reaches the same runtime/transport boundary without depending on a private large session. The scripted resume handler already uses afterStartDelay, so no new test support is required.
6. Proposed fix and verified result
Forward the existing construction deadline in the resume sendCommand call, just as start and fork do. Do not change the transport default, command schema, bridge protocol, provider implementation, or daemon wire contract. Extend the existing lifecycle regression rather than adding a mock call-shape test.
timeoutMs: threadCreationRequestTimeoutMs,
After this correction, the focused test passes all three cases. The complete agent-runtime suite passes 309 tests in 23 files; package lint and typecheck also pass. The diff is 127 changed text lines in two files: one production addition, plus 82 test additions and 44 test deletions. No dependencies, generated files, binary files, migrations, stored data, or public contracts change. A truly unresponsive provider can now hold a resume request for the same two-minute total limit as other construction commands; it still times out, and the short-deadline test checks failed-session cleanup.
7. Verification
The same agent repeated the reproduction, not an independent reviewer. A second initially clean worktree was detached at the exact pinned commit. Its pristine status was checked before applying the same test-only patch. It received its own frozen install and successful Turbo build, and then ran the identical focused command. The second run again produced two intended restoration failures and a passing start-session control. Production code remained unchanged in that checkout. No report corrections were necessary after repetition.
First run: full sanitized output. Second clean run: full sanitized output. Fixed focused run: full sanitized output. Full test/lint/typecheck gate: full sanitized output.
Live pi performance, the reported production timeline, automatic idle-worker resumption through the UI, and real-provider integration tests were not run. The reproduction proves the request deadline failure and configured-deadline behavior at the runtime's owning boundary; it does not claim to benchmark large sessions.
8. Related issues and pull requests
No open pull request linked to issue 5080 was found in its timeline or the open-PR search before fixing. Searches surfaced #4461 as context about turn latency, but did not establish an identical root cause. No linked PR code or branch was executed.
9. Appendix
Issue content was treated as untrusted hypotheses; its proposed patch and testing directions were not executed. All code under test came from the pinned trusted origin/main and this agent's repository-derived test and one-line repair. Administrative issue writes use the supplied SlopCop identity command. No user runtime or production logs were accessed.
First and second base checkouts: pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build pnpm exec turbo run test --filter=@bb/agent-runtime -- src/runtime.lifecycle.test.ts -t 'uses the construction deadline' After the one-line repair: pnpm exec turbo run test --filter=@bb/agent-runtime -- src/runtime.lifecycle.test.ts -t 'uses the construction deadline' pnpm exec turbo run test lint typecheck --filter=@bb/agent-runtime pnpm exec oxfmt packages/agent-runtime/src/runtime.lifecycle.test.ts packages/agent-runtime/src/runtime.ts git diff --check git diff --numstat origin/main
AGENT GENERATED · October 7, 2026