Repository navigation
fix(coding-agent): apply httpIdleTimeoutMs to Bun's fetch (fixes #206) - #216
Merged
Merged
Conversation
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.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #206.
Problem
On Bun,
configureHttpDispatcher()returned early (packages/coding-agent/src/core/http-dispatcher.ts,if (isBunRuntime) return;), so thehttpIdleTimeoutMssetting did nothing. Bun's own fetch idle timer always applied instead. That timer is fixed at 300 s, or whateverBUN_CONFIG_HTTP_IDLE_TIMEOUTsets, and Pi cannot change it. When it fires, the request fails withTimeoutError: The operation timed out.On Node, the same setting becomes undici's
headersTimeoutandbodyTimeout, and0turns them off. Someone who sets the timeout todisabled(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
fetchtimings with a 400 s delay:fetch failedat 301.6 sterminatedat 301.7 sTimeoutError: The operation timed out.at 360.3 stimeout: falseEnd to end, I ran
pi-bolt -pheadless withhttpIdleTimeoutMs: 0andBUN_CONFIG_HTTP_IDLE_TIMEOUT=5, which shrinks Bun's timer so the run takes seconds:The operation timed out.(13 s)Request timed out.(13 s; the OpenAI SDK rewrites the error before headers)httpIdleTimeoutMs: 30000httpIdleTimeoutMs: 3000No 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:timeout: falseto Bun's fetch, which turns off Bun's own timer. A caller's owntimeoutoption still wins.0waits forever.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: falsereaches the runtime fetch when the setting is disabled or changed, and going back to the default restores the original fetch.TimeoutError.npm run checkpasses with no errors or warnings.