Skip to content

thread/resume inherits the 30s JSON-RPC default and fails large pi sessions #5080

Closed

Description

@Diffuzmetall

Summary

thread/resume is the only session-construction command that does not pass an explicit deadline to sendCommand, so it inherits the JSON-RPC transport default of 30 seconds. A resume answers only after the provider has built or loaded the thread's session, so on a large session the call dies at 30.0s and the thread is marked failed:

Command turn.submit failed
JSON-RPC request timed out: thread/resume

thread/start and thread/fork already use threadCreationRequestTimeoutMs for the same class of work. Resume needs the same deadline, or it needs the deadline to be a property of the command rather than an argument each call site remembers to pass.

Impact

A heavyweight pi thread becomes unusable: every new message fails during resume, the thread goes to error, and resending produces the same failure because nothing changed in between. Two consecutive attempts failed identically 90 seconds apart, with no provider crash and no error from the provider itself.

Reproduction

Observed on a self-hosted bb 0.45.0 instance, pi provider, thread thr_pbsqhhv4c8.

Session: 26.9 MB, 4366 records, 12 compactions (5.6 MB of summaries), ~108k tokens of live context.

Timeline from the thread's event log and the pi session file:

21:34:27.615Z  client/turn/requested (resume needed, worker had idle-stopped)
21:35:01.215Z  pi session records state/reconstructed   <- construction finished
21:35:02.614Z  client/turn/rejected: JSON-RPC request timed out: thread/resume
21:35:02.618Z  system/error: Command turn.submit failed
21:36:01.500Z  retry
21:36:32.747Z  pi session records state/reconstructed
21:36:34.110Z  client/turn/rejected: JSON-RPC request timed out: thread/resume

The daemon gave up at 30.0s while the construction finished at 31 to 34 seconds.

Deterministic A/B on a dev instance running the same code, pi provider, session transplanted from the failing thread (26.9 MB, rewritten cwd), with a delay injected into session construction to synthesize the loaded-host construction time, and temporary logging of the deadline each command is sent with:

Before, i.e. current upstream behaviour:

[bb-deadline] send  thread/resume timeoutMs=undefined
[bb-deadline] FAIL thread/resume afterMs=30001: JSON-RPC request timed out: thread/resume

thread status error, exactly the production symptom.

After, i.e. with the deadline added:

[bb-deadline] send  thread/resume timeoutMs=120000
[bb-deadline] ok   thread/resume afterMs=35847

turn completed, thread idle. On the same instance thread/start reports timeoutMs=120000, ok afterMs=35454, which is the same work with the deadline already attached.

A cold resume of the same 26.9 MB session on an unloaded dev host takes about 15 seconds, on the loaded production host 31 to 34 seconds. The deadline has to cover that spread, and 30 seconds does not.

Root cause

packages/provider-bridge-protocol/src/bridge-kit/runtime-json-rpc.ts:

    const timer = setTimeout(() => {
      args.pending.delete(id);
      reject(new Error(`JSON-RPC request timed out: ${message.method}`));
    }, args.timeoutMs ?? 30_000);

packages/agent-runtime/src/runtime.ts (2581 lines at upstream/main):

  • line 234 const DEFAULT_THREAD_CREATION_REQUEST_TIMEOUT_MS = 2 * 60_000;
  • line 269 const threadCreationRequestTimeoutMs = options.threadCreation?.requestTimeoutMs ?? DEFAULT_THREAD_CREATION_REQUEST_TIMEOUT_MS;
  • thread/start at line 1608 and thread/fork at line 1749 pass timeoutMs: threadCreationRequestTimeoutMs
  • thread/resume builds its command at line 1912 and calls sendCommand at line 1938 with recovery only, no timeoutMs, so it falls through to the 30 second default

The provider side cannot answer earlier: for the pi provider, thread/resume reaches handleThreadConstruction → constructPiThreadSession → await session.start(), and the bridge replies with the provider thread id only after that resolves. Construction time therefore scales with the session, not with the request.

Proposed solution

Minimum, matching the existing convention at the other two construction sites:

           let resolved: string;
           try {
             const result = await sendCommand({
               proc,
               message: plan,
               resultSchema: threadIdentityResultSchema,
+              // A resume loads the thread's whole session, so it is construction
+              // work and needs the construction deadline, not the 30s transport
+              // default.
+              timeoutMs: threadCreationRequestTimeoutMs,
               recovery: {

A more structural option, if maintainers prefer it, is to decide the deadline from the command type inside sendCommand (a thread/start, thread/fork, thread/resume mapping) instead of an optional argument, so a future construction command cannot silently fall back to the transport default. That is what the fix on my fork does; it touches every sendCommand call site, so it is a judgement call which shape belongs here.

Testing

  1. Unit, small and deterministic: cover whichever shape lands. With a command-type mapping, assert thread/start, thread/fork and thread/resume all resolve to the construction deadline and that e.g. turn/start stays on the transport default. With the minimal diff, assert the resume command is sent with timeoutMs (a recording adapter or a spy on the request args). Both fail before the change: the mapping returns undefined for thread/resume, and the minimal version sends no timeoutMs.
  2. Behavioural, which is the one that actually pins the user-visible behaviour: the runtime option threadCreation.requestTimeoutMs already exists, so set it low (for example 2 seconds) and make the fake provider answer thread/resume later than that. Before the change the resume succeeds with the low configured value, i.e. the option is ignored on the resume path; after the change the same call rejects with JSON-RPC request timed out: thread/resume. The fake provider script has no delay knob for thread/resume today, so this needs one small addition next to the existing delay:N support for turns.
  3. If a heavier gate is wanted, run packages/agent-runtime integration resume tests with a large synthetic session; that is slow, so I would keep it out of the default suite.

Residual risk

With the deadline attached, a provider that is genuinely stuck holds a turn for up to the construction deadline instead of 30 seconds before the turn fails. A progress heartbeat between the runtime and the provider bridge would separate a slow but healthy construction from a stalled one and would let the deadline be an idle timeout rather than a total one. That needs the provider bridge protocol, so it is a follow-up rather than part of this fix.

Environment

  • bb-app 0.45.0, self-hosted, Linux, pi provider (openai-codex model), full permission mode.
  • Producer of the failure: pi bridge worker idle-stopped after about 5 minutes (host plugin worker became idle, uptime ≈300s), so the next message needs a cold resume of the whole session.
  • The same failure mode should affect any provider whose resume blocks on session construction, not only pi.

Activity

  1. added theissue type on Oct 7, 2026
  2. added
    providers
    provider-pi
    confirmed-repro
    on Oct 7, 2026
  3. bb-slop-cop commented on Oct 7, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · Priority: High · Effort: Low. Area/plugin labels: providers, provider-pi.
    • Report: Reproduction and root-cause evidence · REPRODUCED · confidence: high. Applied confirmed-repro.
    • Root cause: The runtime's resume request omits the construction deadline, falling back to the 30-second JSON-RPC timeout and ignoring configured construction limits.
    • Verification: Two clean trusted-main checkouts reproduce both deadline failures through the real runtime/bridge and scripted provider. The regression passes after the fix; all 309 runtime tests, lint, and typecheck pass. No private session or live pi account was accessed.
    • Fix: Ready PR #5082, with 127 changed text lines across two files. Not merged.

    AGENT GENERATED

  4. Diffuzmetall commented on Oct 7, 2026

    @Diffuzmetall
    ContributorAuthor

    Follow-up after deploying the fix on the affected instance: the resume path is fixed, and the same class of failure showed up one command later.

    Evidence from the thread that was failing (pi session of 31.6 MB), local time, after the daemon was restarted with the resume deadline raised:

    • 08:22:38 the pi session records state/reconstructed, so the resume completed. Before the change the daemon had already given up at 30.0s and this line was reached only after the thread was killed.
    • 08:22:39 state/input-pending, immediately followed by state/session_before_compact: this session starts compacting as soon as it is loaded.
    • 08:23:08 Command turn.submit failed / JSON-RPC request timed out: turn/start, the 30 second transport default again, now on prompt submission.

    Compaction on that session is not quick: session_before_compact at 08:01:46 and the next session entry at 08:06:23, about four and a half minutes.

    So the provider was busy doing legitimate, provider-side work and the daemon killed the prompt at 30 seconds. Two shapes for the fix, and I think the first is the right long term one:

    1. The bridge should answer turn/start immediately with the compaction-in-progress outcome it already produces on other paths:

      Cannot submit a prompt while compaction is in progress. Wait for compaction to finish and retry.

      Then the runtime can retry or queue instead of holding a request open, and the user gets a fast, accurate answer rather than a timeout.

    2. Give prompt submission the same provider-busy deadline as construction, which is what I applied as a local mitigation: turn/start and turn/steer now share a ten minute provider-busy deadline with thread/start, thread/fork and thread/resume, in both the source fix and the deployed bundle.

    Shape 2 removes the immediate failure but keeps the failure mode where a genuinely stuck provider holds a turn for the full deadline, so shape 1 is still worth doing.

  5. Diffuzmetall commented on Oct 7, 2026

    @Diffuzmetall
    ContributorAuthor

    Confirmed on the affected instance, same heavy thread (thr_pbsqhhv4c8, pi session grown to 32 MB):

    09:39:58  user message
    09:40:26  thread/identity                     (resume, 28 s)
    09:40:26  state/input-pending, state/session_before_compact   (prompt accepted, pi starts compacting)
    09:47:28  session records the user message    (compaction finished, about 7 minutes)
    09:47:59  assistant text
    09:48:01  turn/completed, thread idle
    

    Zero JSON-RPC timeouts in the host daemon log since that daemon started. The same scenario on the previous, 30 second default build failed at 08:23:08 with JSON-RPC request timed out: turn/start and left the thread in error.

    The margin is worth noting: that compaction took about seven minutes against the ten minute provider-busy deadline I gave turn/start and turn/steer. So the timeout works but the outcome is still a race against how long compaction happens to take, which is the argument for the first shape above: the bridge should answer prompt submission with the compaction-in-progress outcome it already knows, and the runtime should retry, so no timeout value has to guess the maximum compaction time.

  6. Diffuzmetall commented on Oct 7, 2026

    @Diffuzmetall
    ContributorAuthor

    One more guard shows up in the same window, worth recording here.

    During the seven minute compaction of that session the thread logged:

    09:42:29  system/error  {"code":"provider_turn_start_timeout","message":"The provider accepted a turn but did not start it within 120s. The request may be stalled; stopping the thread interrupts it."}
    

    The turn still completed at 09:48:01 and the thread went back to idle, so this guard did not kill the run, but the thread carries an error event and the user sees it. It is a second, independent deadline: the runtime expects turn/started within 120 seconds of the provider accepting the prompt, and pi cannot start the turn until compaction finishes.

    So on a 32 MB session a prompt submitted at the wrong moment races two clocks, the 30 second transport default on turn/start and this 120 second provider-turn-start guard, and compaction took about seven minutes. Raising either number only moves the race. The shape that removes it is still the one in my earlier comment: while the provider reports session_before_compact / compaction_start, do not submit the prompt at all, or submit it and treat it as queued until the provider is ready, instead of timing the wait.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-reproprovider-piproviders

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions