Repository navigation
fix(aimux): fail a model stream that goes idle - #2143
Conversation
A request waited for the next stream part with no deadline, so a provider that stopped delivering without closing held the turn until an external deadline ended the process. Each wait now has a five-minute allowance, and an expired one fails the request as a network failure so the retry policy can replace the attempt while nothing was committed. The allowance is per wait, not per request: a reply that keeps streaming is never cut. Cancelling the request outranks the deadline, and the deadline outranks a part that is ready at the same moment.
The stream fixture now lets a test feed parts after the idle wait is armed, so virtual time can pass inside one wait. The cases cover the failure's kind and reason, parts that keep the stream open, and an expired deadline that outranks a part ready at the same moment.
An idle failure is a network failure, so an attempt that committed nothing is replaced in place under one request, while one that already committed text ends the turn without replaying it. Both outcomes are scripted with the failure the aimux stream builds.
The development model configuration could not state the facts the transport already reads from a product provider record, so a development run could not set a proxy or a total request timeout. A provider now takes an optional network block with the rules the product record applies: an HTTP or HTTPS root proxy URL and a positive safe-integer timeout. The block sets the connection the catalog resolves for every request of that provider. The streaming idle allowance stays a fixed bound of its own, not a connection setting.
A provider that reads the request and never sends the response headers holds the turn with no deadline. The case keeps a raw listener at that point after its request head arrives, moves the clock five minutes, and expects the network failure the bridge reports for an idle stream, with the reason naming the response headers. Without the bound the wait never ends; the test's guard reports it, and the assertions on the failure's kind and reason cannot be reached.
The idle allowance started only after the response headers arrived, so a provider that accepted the request and never answered held the turn until an external deadline whenever the connection's optional total timeout was unset, which is the default. The wait for the headers now carries the same five-minute allowance and fails as a network failure with the reason naming the headers, so the retry policy replaces the attempt in place while nothing was committed. The connection's optional total timeout is unchanged: this bounds one wait, not the whole request. Cancelling the request still outranks the deadline.
The development configuration's network check also refuses a timeout above the largest safe JSON integer, but its message and the CLI README asked for a positive integer, which such a value satisfies. Both now ask for a positive safe integer, and the load-failure case asserts that wording.
The five-minute bound starts when the request is sent and covers its body and any redirects, so the failure reason, the constant's documentation and the design pages now name the whole exchange instead of only the wait for the response headers. The retry budget is unchanged: eight attempts of five minutes each bound a half-open connection to roughly 42 minutes before the turn fails.
eric8810
left a comment
There was a problem hiding this comment.
[P2] Start the first-event allowance when headers actually arrive (crates/dim-agent-aimux/src/driver.rs:735). This races the whole model.do_stream() future, not the HTTP response headers. In the pinned Aimux 0.6.1, OpenAI Chat reads one SSE event after receiving the headers and before returning StreamResult. If the headers arrive at 4m59s and the first event at 5m01s, both documented allowances are satisfied, but this branch aborts at 5m, reports that no headers arrived, and can retry the request. The header test only covers a peer that never sends headers, so it cannot catch this. Please anchor the header deadline to actual header receipt, give the first event its own idle window, and cover the delayed-headers/short-first-event-gap case.
The same distinction matters for errors: Aimux reads a non-2xx response body before returning the failure. If that body stalls after a 401, this timer discards a known status and returns a retryable network failure instead. Bound that body read separately without losing the status. Also, please carry the decoded-parts-only limitation from the PR description into the EN/ZH model-failure docs so readers know SSE keep-alives do not reset the timer.
Static review of c346caa8; GitHub's Linux workspace tests were still running. I did not run the tests locally.
A reply whose headers arrive inside the allowance must still get its own allowance for the first event, and a stalled non-2xx body must keep the HTTP status instead of becoming an idle network failure. Both cases fail on the current driver by assertion.
The wait for the response headers raced the whole do_stream call, so a reply whose headers arrive inside the allowance but whose first event follows after it was failed as a missing header. The transport now reports the response status, the deadline moves to the first event when the headers arrive, and a non-2xx body is read under its own total allowance so a stalled error body keeps the HTTP status and its kind.
The design document now names the three waits the idle allowance bounds, the separate total allowance for a non-2xx body, and the limitation that only decoded stream parts renew the wait between parts.
A reply whose headers arrive and whose first event never does fails as a network failure that names the missing event, so the window that starts at the headers is both extended and bounded.
The three deadline tests answered over a real listener and held the call in real time with a blocking sleep before the virtual clock moved, so a scheduler slower than the sleep failed them without a product defect. They now build the driver in the crate, answer each exchange from a scripted transport, and poll the call until it has no ready work before the clock moves, so the same assertions hold with no real waiting. The flow suite keeps the real-transport case for the response headers.
|
Thanks. All four points are addressed in
One boundary remains and the design document states it: the header window still starts when the request is sent, so the request body and any redirects count against it. |
eric8810
left a comment
There was a problem hiding this comment.
The new split addresses the original delayed-header/first-event case, preserves the HTTP status for the partial 401 body, and documents the keep-alive limitation. One boundary still contradicts the new contract:
[P2] Use when headers were received, not when the driver next polls (crates/dim-agent-aimux/src/driver.rs:276–280,805–838). ResponseWatch sends only the status, then do_stream can yield pending while reading the body. If the response is reported just before the deadline but the task next runs just after it, the biased select takes the timer before the already-ready report. It can still say “no response headers arrived” and retry a known 401. When the status branch does win, the first-event window starts at the receiver's Instant::now() instead of at receipt. Report the receipt timestamp, use it to distinguish on-time headers from genuinely late ones, and derive the first-event deadline from it while keeping cancellation precedence. The existing test reads the report at 299s; please also cover a report sent before the boundary but not polled until afterward.
Non-blocking diagnostics note: the bridge's mid-stream deadline is outside RecordingOutcomeStream, so dropping it without an Aimux terminal item records Cancelled, even though the application receives a network failure. The pre-stream timeout paths already record failure explicitly. Recording both consistently would make these incidents easier to diagnose.
Static re-review at 4a0f220f; Linux CI was still running. No local test run.
zerob13
left a comment
There was a problem hiding this comment.
Define the startup deadline for OpenAI Responses, including managed Codex. The separated HTTP-header and body waits fix the previous Chat cases. On the Responses path, the driver still treats completion of do_stream() as receipt of the first decoded part, but the pinned SDK's startup scan can already have decoded and buffered response metadata before returning the stream. The current deadline can therefore classify a progressing response as having delivered no event.
Base the deadline on observable decoded progress, or explicitly define a separate SDK startup-completion deadline and its error and retry behavior. Add Responses-path coverage; the new Chat tests and green exact-head CI do not establish this behavior. This is separate from the peer's existing header receipt timestamp finding. No external provider was called during this review.
zerob13
left a comment
There was a problem hiding this comment.
Verdict: approved for the delta c346caa8..4a0f220f. The three blockers from the previous review are fixed at this head, and the follow-up commits do not introduce new ones.
Scope: this review covers the seven commits pushed after c346caa8 (94c0607f through 4a0f220f). Everything before that, including the network block, was already covered by the earlier review.
What changed and why it is correct
1. The header wait and the first-event wait are now separate. The transport is wrapped in ResponseWatch, which reports the status as soon as the headers arrive; driver.rs:781-836 then resets the allowance for the first event. This is the distinction the previous review asked for: the old code raced the whole do_stream() call, so headers at 4m59s plus a first event at 5m01s was failed as "no response headers". The new test at driver/tests.rs:160 reproduces exactly that case and passes.
2. A stalled non-2xx body no longer loses the HTTP status. For a non-2xx reply the body is read under one total five-minute allowance (ResponseWatch, driver.rs:269-298), the driver stops applying its own idle deadline for that exchange, and the provider still reports the status it received. The test at driver/tests.rs:260 sends a 401 with a partial error body and gets host_error_code = Some(401) with AuthRejected, not a retryable network failure.
3. The documentation matches the code. docs/design/model-failures.md and docs/zh/design/model-failures.md now state the three waits, the separate error-body allowance, and the limitation that only decoded stream parts renew the wait (SSE comments and Anthropic ping events do not).
Verification
cargo test -p dim-agent-aimux --lib— 77 passed, including the three new driver tests.cargo test -p dim-agent-aimux --test agent_aimux_flow— 88 passed.cargo fmt -p dim-agent-aimux -- --check— clean.- CI at
4a0f220fis green (ci-ok,verify (linux),macos-native,windows-cli,dependencies).
Non-blocking notes
- When a non-2xx status arrives,
bounded = falseremoves the driver's idle deadline for the rest of that exchange (driver.rs:836). That is safe today because the body read is the only remaining wait, but if a provider later does other work after a non-2xx status, that work will be unbounded. A comment saying the body wrapper is now the only bound would help the next reader. - A refused 3xx takes the same non-success path.
follow_redirectsalready stripsLocationbefore the provider sees it, and the body allowance still bounds the exchange, so there is no hang. - The deadline branch is biased ahead of the status branch, so headers that are ready at the same instant the allowance expires still fail as "no response headers". This matches the documented "an expired bound outranks a part that is ready at the same moment" rule; noted only because the error text can be slightly misleading at that exact boundary.
Where to look
crates/dim-agent-aimux/src/driver.rs:269—ResponseWatch(status reporting + non-2xx body cap).crates/dim-agent-aimux/src/driver.rs:781— the three-wait loop and the deadline reset.crates/dim-agent-aimux/src/stream.rs:31— the updated allowance documentation.crates/dim-agent-aimux/src/driver/tests.rs:160,:211,:260— the three new deadline tests.
The earlier REQUEST_CHANGES was posted against c346caa8; this approval only covers the delta above. The PR stays blocked until the remaining review state is resolved.
Withdrawing this approval. After checking the pinned aimux 0.6.1 Responses path, do_stream runs read_until_output before it returns, so the driver's first-event window starts at the headers and cannot observe the events the SDK consumes during that startup scan. A slow-but-progressing Responses startup can therefore be failed as 'no stream event'. The separate changes-requested review covers the fix this needs; this head is not merge-ready. The delta verification in the dismissed review still stands for the Chat and non-2xx paths.
…tart The transport reports the response headers at 299 seconds of virtual time and the task is not polled again until 301: the reply must still start, and a 401 in the same position must still keep its status instead of becoming a header timeout. The OpenAI Responses startup scan can decode response metadata before it returns the stream, so a stream that never starts must name the stream start rather than a missing event, and a reply whose metadata arrives before its output must still deliver that output. All four fail on the current driver by assertion, except the last, which pins the path the fix must keep working.
The transport now reports when it produced the response headers, and the wait after them starts at that instant, so a report written inside the header allowance is on time even when the driver next polls after the deadline. The deadline arm still runs before the report and the exchange: it reads the report there and treats an on-time non-2xx reply as a reply whose status must survive, instead of declaring that no headers arrived. The wait after the headers is named by what the provider does with it. The OpenAI Responses SDK reads response metadata before it returns the stream, so that wait ends at the stream's start and its expiry says so, while the providers that read one event keep the reason that names the missing event.
The design document now states that a wait with a producer-reported instant is judged against that instant, so the header wait and the wait after it meet where the transport produced the headers rather than where the driver next polls. It also states that the OpenAI Responses provider's wait ends at the stream's start because its SDK reads response metadata first, and which providers leave the first event to the wait between parts.
Headers reported at 299 seconds and read at 301 must end the stream-start allowance at 599 seconds, three hundred seconds after the report, not at 601 seconds after the poll that read it. The case fails on the driver that starts the window at the poll.
|
Thanks. Both points are addressed in The transport now reports when it produced the response headers, and that instant decides the boundary.
On the diagnostics note: this change does not alter it. The mid-stream deadline is in the bridge, outside |
|
Thanks. The OpenAI Responses path now has its own startup deadline in The wait after the response headers is now defined by what the provider does before it returns the stream, and on this path it ends at the stream's start, not at an event the driver can see. The pinned Responses SDK reads and buffers
|
eric8810
left a comment
There was a problem hiding this comment.
Approved at c78ad3f6. The timestamp on the transport report now preserves headers received before the cutoff even when the driver resumes late, and anchors the startup window to receipt. I verified the exact-head Linux CI log: the late-read 200, stalled 401 (status preserved), receipt-anchored startup deadline, and both OpenAI Responses startup cases all ran and passed. The ci-ok job passed. The mid-stream recording outcome discrepancy remains a non-blocking follow-up, as discussed. I did not run tests locally.
zerob13
left a comment
There was a problem hiding this comment.
The transport records header receipt time, late driver polling preserves on-time responses and a stalled non-success body keeps the HTTP status. OpenAI Responses, including the managed Codex path, now has an explicit SDK startup deadline rather than claiming that no event arrived. This addresses my earlier request; exact hosted CI passed the metadata-first, header receipt, stalled 401 and interruption cases. Non-blocking follow-up: compare the reported timestamp with the cutoff on every completion path, so a report produced around the timer boundary is classified the same way regardless of poll order.
|
Fixed in #2150. The report arm now compares the reported instant with the header cutoff and ends the wait as missing headers, with the same kind and reason the deadline arm uses, so a report produced around the timer boundary is classified the same way whichever arm reads it. The select order is unchanged: the deadline still runs before the report and the exchange, so a part that is ready when the allowance expires still loses to it. The boundary was narrower than a whole completion path: the header allowance is a timer and fires on its next millisecond tick, so for up to one tick the report arm could read a report stamped after the cutoff while the deadline arm was still pending. |
Fixes #2117
A model request waits for the next stream part with no deadline. The transport applies only an optional total request timeout, which no configuration sets by default, so a provider that stops delivering without closing holds the turn until an external deadline ends the process. The benchmark runs that motivated this issue do not show that shape: five trials kept streaming thinking for the whole deadline, so a bound on silence cannot end them. What it bounds is the other class, a connection that stays open and delivers nothing, where one observed request stayed open for its whole lifetime.
This change gives every wait between stream parts a five-minute allowance and classifies an expired one as
network, the kind the retry policy retries beside transport failures. The allowance is per wait, not per request: a reply that keeps streaming is never cut. An expired deadline outranks a part that is ready at the same moment, so data that was already waiting when the allowance ran out does not revive a connection that was silent for all of it. Cancelling the request outranks both.AiMuxError::Timeoutkeeps its existingunknownkind; the bridge builds this failure with its own facts and the reasonthe stream delivered nothing for 300 seconds.The wait for the response headers carries the same allowance, because the stream bound starts only once the connection is answered: a provider that accepts the request and never sends headers would otherwise hold the turn forever when no total timeout is set. The wait ends when the response headers actually arrive: the transport reports the moment it produced them, and both that wait and the wait after it are judged against that moment, so headers that arrive inside the allowance are not late because the driver next polls after it, and a report from a non-2xx reply in that position keeps its status. The wait after the headers then runs from the headers to the start of the stream: the OpenAI Chat provider reads one event before it returns the stream, so without that wait the header deadline would still cover it. The header wait itself starts when the request is sent, so the request body and any redirects count against it; an expired header wait fails as
networkwith the reasonno response headers arrived within 300 seconds of sending the request, and an expired stream-start wait fails the same way. The OpenAI Responses provider returns only after its SDK's startup scan, which reads response metadata the driver cannot see, so its stream-start wait says what it measures and expires with the reasonthe response headers arrived, but the stream did not start within 300 seconds; the providers that read one event keep the reasonthe response headers arrived, but no stream event followed within 300 seconds, and the compatible and Bedrock providers return at the headers and leave the first event to the wait between parts. The retry budget is unchanged: at most eight attempts and 300 seconds of backoff sleep, each attempt bounded by the waits above, so a half-open connection ends the turn as failed instead of holding it forever. The optionalnetwork.timeoutMskeeps its meaning: it bounds one whole request, its response body included, separately from these waits.A non-2xx response is bounded on its own. The provider reads the error body before it returns the failure, so a stalled body would otherwise outlive the request and, if the request were failed as idle, would also discard the status that had already arrived. The transport ends a non-2xx body after a total five-minute allowance, the provider keeps the bytes that arrived and reports the HTTP status it received, and the driver runs no idle deadline over a non-2xx reply. A 401 whose body stops after a partial error object therefore still fails as
auth_rejectedwith status 401, not as a retryable network failure.Known limitation, also stated in the design document: only decoded stream parts reset the allowance. The provider parser drops SSE comments and Anthropic
pingevents before they reach the bridge (StreamEvent::Other => {}), so a connection that stays alive only with keep-alives is failed after five minutes without parts. Renewing the allowance on those events needs an upstream aimux change, which this change does not make; the allowance stays a fixed bound of its own and is not configurable.With #2121's retry, an idle failure before the attempt committed anything is replaced in place under the same request. After committed output it ends the turn without replaying what was already shown, and a step whose tool call was announced continues with a new request, as every retried kind does.
The development model configuration could not state the connection facts a product provider record already carries, so a development run could not set a proxy or a total request timeout. A provider now accepts an optional
networkblock with the same fields, rules and meaning:proxyandtimeoutMs(a positive safe integer) belong to the connection, while the idle allowance stays a fixed five minutes of its own.Verification:
cargo test -p dim-agent-aimux --libcovers the deadlines in the stream bridge: the failure's kind and reason, parts that keep the stream open across virtual time, and an expired deadline that outranks a ready part. It also covers the driver's waits through a scripted transport: late headers, a report read after the allowance, a missing first event, the Responses startup, and a stalled error body.cargo test -p dim-agent-aimux --test agent_aimux_flowruns the model flow suite, including the response-header case below.model_flow::a_wait_for_response_headers_past_the_idle_allowance_fails_as_a_network_failurecovers a listener that reads the request and never answers: virtual time passes five minutes and the call fails as a network failure naming the headers.driver::tests::a_delayed_header_reply_still_gets_its_first_event_allowancecovers headers at 299 seconds of virtual time and a first event at 301 seconds: the call starts and delivers its text.driver::tests::a_header_report_read_past_its_allowance_is_on_timecovers a header report written at 299 seconds and read only after 301: the call starts from the reported instant and delivers the text of a first event at 301 seconds.driver::tests::a_header_report_read_past_its_allowance_keeps_the_response_statuscovers a 401 reported at 299 seconds and read only after 301: the call fails with status 401 andauth_rejected, not as a retryable network failure.driver::tests::a_header_report_starts_the_stream_allowance_at_its_instantcovers the same report read at 301: the stream-start allowance ends three hundred seconds after the report, not three hundred seconds after the poll that read it.driver::tests::a_first_event_past_its_own_allowance_fails_as_a_network_failurecovers headers that arrive and a first event that never does: the call fails as a network failure naming the missing event.driver::tests::a_responses_startup_past_its_allowance_names_the_stream_startcovers a Responses reply whose startup scan decodesresponse.createdand then delivers no output: the call fails as a network failure naming the stream's start.driver::tests::a_responses_start_inside_its_allowance_delivers_the_outputcovers the same metadata followed by output inside the allowance: the reply starts and delivers its text.driver::tests::a_stalled_error_body_keeps_the_response_statuscovers a 401 whose body stops after a partial error object: the call fails with status 401 andauth_rejected, not as an idle network failure.cargo test -p dim-agent-aimux --test agent_aimux_flow network_blockcovers the block reaching the connection a request resolves, and the values the transport cannot use failing the load next to the provider that states them.cargo test -p dim-agent-capabilities --test capabilities_flow idle_timeoutcovers the in-place retry before any committed event, and the turn ending after committed text without a replay.The stream cases that require a deadline fail by assertion, not by timing out, when the deadline arm is absent; the third pins that arriving parts keep the stream open. The response-header and stream-start cases fail the same way without their bounds, a report read after the allowance is failed as missing headers when its instant is ignored, and the error-body case fails on the status assertion because the idle failure replaces the status.