Skip to content

fix(coding-agent): apply httpIdleTimeoutMs to Bun's fetch (fixes #206) - #216

Merged
Kushalkhemka merged 3 commits into
pi-boltfrom
fix/206-request-timeout
Oct 30, 2026
Merged

Kushalkhemka merged 3 commits into
pi-boltfrom
fix/206-request-timeout

Conversation

@Kushalkhemka

Copy link
Copy Markdown
Member

Fixes #206.

Problem

On Bun, configureHttpDispatcher() returned early (packages/coding-agent/src/core/http-dispatcher.ts, if (isBunRuntime) return;), so the httpIdleTimeoutMs setting did nothing. Bun's own fetch idle timer always applied instead. That timer is fixed at 300 s, or whatever BUN_CONFIG_HTTP_IDLE_TIMEOUT sets, and Pi cannot change it. When it fires, the request fails with TimeoutError: The operation timed out.

On Node, the same setting becomes undici's headersTimeout and bodyTimeout, and 0 turns them off. Someone who sets the timeout to disabled (or raises it) for a slow local model gets that behaviour from Pi on Node. Pi-Bolt still fails once the model sends nothing for about 6 minutes.

Trace

I used a local fake OpenAI-compatible server, with no real provider. These are raw fetch timings with a 400 s delay:

runtime headers 400 s late 400 s gap mid-stream
Node 300 s undici default fetch failed at 301.6 s terminated at 301.7 s
Bun 1.4.2 and Pi-Bolt 1.0.7 runtime TimeoutError: The operation timed out. at 360.3 s same, at 360.3 s
Bun with timeout: false completes at 400 s n/a

End to end, I ran pi-bolt -p headless with httpIdleTimeoutMs: 0 and BUN_CONFIG_HTTP_IDLE_TIMEOUT=5, which shrinks Bun's timer so the run takes seconds:

case 1.0.7 binary this branch (source on the Pi-Bolt runtime)
20 s gap mid-stream, timeout disabled The operation timed out. (13 s) completes
headers 20 s late, timeout disabled Request timed out. (13 s; the OpenAI SDK rewrites the error before headers) completes
20 s gap mid-stream, httpIdleTimeoutMs: 30000 n/a completes
8 s gap mid-stream, httpIdleTimeoutMs: 3000 n/a No data from the server for 3 s (HTTP idle timeout)

The message in the issue, The operation timed out., is the mid-stream case. The headers arrive, then the model sends nothing for a long time, for example a long prefill. With the default settings, Bun (about 360 s) actually waits longer than Node (300 s). The reporter's stock Pi most likely has the timeout disabled or raised, and Pi-Bolt ignored that setting.

Fix

The fix is TypeScript only and does not change the engine. On Bun, when the timeout is not the default, configureHttpDispatcher() installs a wrapper around Bun's fetch:

  • It passes timeout: false to Bun's fetch, which turns off Bun's own timer. A caller's own timeout option still wins.
  • It applies the setting the way undici does. The request fails if no response headers arrive within the timeout, or if a single body read waits longer than the timeout. Time the consumer spends between reads does not count. 0 waits forever.
  • It keeps fetch.preconnect, which the connection warmer uses, and leaves alone a global fetch that another module has replaced.

With the default timeout, the global fetch stays Bun's own fetch, so the default setup has no extra cost per request.

Test

packages/coding-agent/test/http-dispatcher-bun.test.ts, with comments naming #206, checks:

  • timeout: false reaches the runtime fetch when the setting is disabled or changed, and going back to the default restores the original fetch.
  • A fetch that another module installed is kept.
  • Slow headers and a slow stream succeed when disabled or when within the timeout.
  • Headers or a stream that stall past the timeout fail with a TimeoutError.
  • A caller's abort still works.

npm run check passes with no errors or warnings.

On Bun, configureHttpDispatcher() returned early, so httpIdleTimeoutMs did
nothing: Bun's own fetch idle timer (300 s, firing at about 360 s) always
applied. With the timeout disabled or raised for a slow local model, a
stream that went quiet for 6 minutes failed with "The operation timed out."
where Pi on Node waits.

With a non-default timeout, Pi-Bolt now wraps Bun's fetch: it passes
`timeout: false` to turn off Bun's timer and applies the setting as undici
does on Node, to the response headers and to each body read; 0 waits
forever. With the default, the global fetch stays Bun's own.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T22:03:52.663312Z 2593e75 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2593e7560d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…meout fetch

The idle-timeout wrapper is not native code, so isRuntimeFetch() in
request-body.ts rejected it and every request re-serialized the whole
conversation instead of reusing the bytes kept between requests (#202).

The wrapper now names the fetch it wraps under RUNTIME_FETCH_WRAPPER (a
registered symbol), and isRuntimeFetch() accepts a wrapper only when the
fetch it names is the runtime's own. Other fetch replacements still get
the SDK's string body.
@Kushalkhemka
Kushalkhemka merged commit f9bcbe6 into pi-bolt Oct 30, 2026
18 checks passed
@Kushalkhemka
Kushalkhemka deleted the fix/206-request-timeout branch October 30, 2026 22:30
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.

pi-bolt displays "Error: The operation timed out."

2 participants