Repository navigation
fix(chat): FC-4 request deadline budget for the Anthropic chat path - #10054
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks for the careful write-up here — the shape of the fix makes sense to me: a single request-level budget admitted before auth/body extraction, a narrow send_with_deadline seam for Anthropic sends, preserving no total timeout after visible streaming progress, and a CI tripwire to prevent future direct sends all line up with the FC-per-hop-timeout class this is trying to close.
A few maintainer notes before merge:
- This touches auth/paywall timing, Anthropic provider transport, CI enforcement, and a new dev-dependency feature, so I’m not formally approving it from automation. A human maintainer should review the runtime policy and deployment assumption (notably the 240s budget under a presumed 300s Cloud Run bound) before merge.
- The added Python tripwire and its unit tests pass in my review environment, and the static scan finds no direct
.send()calls underroutes/chat/after the change. - I could not run the Rust chat tests here because this review environment does not have
cargoinstalled, so please require the targeted Backend-Rust tests/checks in CI or a maintainer environment before merging.
Overall this looks like a cohesive and well-tested fix direction; the remaining review is mainly human confidence around the timeout contract and release/platform configuration.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
|
@Git-on-my-level Noted. We'll wait for a human maintainer to review the runtime policy. |
|
Thanks. Agreed the one runtime assumption worth a maintainer eye is the 240s request budget under the presumed 300s Cloud Run bound. The Rust chat tests pass locally ( |
51cdb8d to
c16021f
Compare
kodjima33
left a comment
There was a problem hiding this comment.
Anthropic chat deadline budget — approved; not auto-merged (large backend change)
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks for the follow-up on the deadline budget and CI tripwire. I found one blocking edge case in the streaming path:
ThinkingDeltachunks are emitted to clients asreasoning_content, but they do not refresh the new semantic-progress timer. After the initial role chunk, a long reasoning phase that keeps sending visiblereasoning_contentcan still be terminated onceSTREAM_IDLE_TIMEOUTelapses, even though the client is receiving semantic output. That regresses the intended “long visible streaming is not an error” contract for Anthropic/Claude reasoning streams. Please update the timer when a reasoning chunk is yielded, and add/adjust a paused-time streaming test that advances beyond 60s while reasoning deltas are flowing.
I verified the new Python tripwire locally (test_check_chat_send_deadline.py and check_chat_send_deadline.py both pass), but I still can’t run the Rust chat tests in this environment because cargo is not installed. This also continues to need human maintainer review for the auth/paywall/provider timeout policy, CI workflow enforcement, and the 240s-under-300s platform assumption; I’m not formally approving from automation.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
|
Good catch — that was a real regression in my change, and you called the mechanism exactly right. Fixed.
The fix refreshes the timer when a reasoning chunk is yielded, matching the text-delta path. Regression test ( I verified it actually catches the bug rather than just passing: Full crate on the rebased head: Still agreed this wants the human maintainer pass on the auth/paywall/provider timeout policy and the 240s-under-300s platform assumption — that one needs someone with deployment visibility. |
c16021f to
a58c23d
Compare
…nded deadline (#10101) # Summary - Four desktop-backend call sites built reqwest clients with **no connect timeout and no total-request deadline** — screen-activity Pinecone upserts, both Sentry fetches (webhook enrichment + feedback poll), and the Crisp session lookup. One hung upstream pinned its handler or background task until the platform killed it, holding the connection slot the whole time. - `services::http::bounded_client(total_timeout)` is now the one owner of outbound client construction: connect capped at 10s, every request failing after the caller's total budget (Pinecone 30s; Sentry/Crisp 15s). No caller can opt out of having a deadline. - `realtime.rs`'s private duplicate helper (identical 10s/15s values) folds onto the primitive; `tts.rs` keeps its deliberate retry-shaped 30s client unchanged — it already had both bounds. **Scope:** this establishes bounded connect + total timeouts for the bare `reqwest::Client::new()` call sites the helper replaces, and steers new *non-streaming* integrations to `bounded_client(total_timeout)`. It is **not** a repo-wide 'every client' invariant — streaming transports (Anthropic/Gemini chat) deliberately omit a client-level total timeout and bound their budget at the route/request level. # Why a primitive, not four timeouts The repo's own FC-per-hop-timeout class (evidence: #9835) names the pattern: per-call-site retail timeouts drift and new call sites ship bare. After this PR the bare `reqwest::Client::new()` call sites this helper covers carry bounded connect + total deadlines, and the next non-streaming outbound integration reaches for the bounded constructor because it is the one that exists. Cited, not declared — this is a `harden:` commit with no triggering incident, per the contribution guide's fix/harden distinction. # Product invariants affected none (verified with `scripts/pr-preflight --suggest`) Failure-Class: none # Validation - New hermetic regression test drives the primitive against a **stalled local upstream** (TCP listener that accepts, reads the request, and never responds — the exact shape a bare client hangs on forever) and asserts the client-side deadline fires, as a timeout error, within budget. No network, no sleeps on the assert path. - `cargo test` → **377 passed** (full crate, includes the new test). - `cargo clippy` clean on the crate; the `--all-targets` `unwrap()` lints in `src/routes/chat/tests/all.rs` are pre-existing on main (from the #9851 module split), untouched here. - `rustfmt --edition 2021` applied to all changed files. - Behavior at the four migrated sites is unchanged on the success path; the only new behavior is that a hung upstream now errors at its budget instead of hanging forever — exercised directly by the test above. # Out of scope, named - **Three bare `reqwest::Client::new()` sites remain in the crate** — `services/firestore.rs:81`, `auth.rs:120`, `routes/auth.rs:847` (verified against the current head). They sit on auth/Firestore surfaces rather than the non-streaming outbound-integration surface this helper covers, and migrating them changes behavior on credential/data paths that deserve their own review — so they are named follow-up, not bundled into an already-approved hardening PR. - The pre-existing `--all-targets` clippy lints in `routes/chat/tests/all.rs` — separate cleanup, not this PR's surface. - Per-request deadline propagation (deadline budgets flowing across hops, FC-per-hop-timeout's full shape) — #10054/#10056 own that for the chat/proxy paths. <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/10101?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
a58c23d to
36d0b4a
Compare
|
Both are already in the current tip (
A fresh CI run against the current tip should be green on this. Thanks for the careful read on the reasoning-stream contract. |
Resolved on current head 36d0b4a: ThinkingDelta/reasoning_content now refreshes semantic progress, with paused-time regression coverage.
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks for the update — the blocking issue I raised on the prior head looks resolved on 36d0b4a2de.
I re-checked the current diff: ThinkingDelta now refreshes the semantic-progress timestamp after yielding reasoning_content, and the new paused-time regression test covers a reasoning-only stream across 200s with each visible delta inside the 60s idle window. The Python send-deadline tripwire and its unit tests also pass locally in this review environment, and the static scan still finds no direct provider .send() calls under routes/chat/.
I dismissed my stale automation change-request review for the old reasoning-stream blocker. I’m still not formally approving from automation because this remains a security/workflow-sensitive runtime-policy change with maintainer-review labels, the Swift CI checks are currently failing, and the 240s-under-300s platform timeout assumption needs human maintainer/deployment sign-off before merge. Overall, this is now a positive implementation signal from my side; remaining sign-off is human policy/CI validation rather than the previous code blocker.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
The provider-timeout class (FC-per-hop-timeout: BasedHardware#8640, BasedHardware#8911, BasedHardware#9135, chat path now owns one admission budget instead: - RequestDeadline (240s inside the 300s platform bound, mirroring the Gemini proxy) is created in route middleware before extractors and body extraction; auth, BYOK, and paywall waits are bounded by it and budget exhaustion returns a typed 504 instead of a 401. - All provider sends go through send_with_deadline; the retry loop is a budget-aware policy: attempts never start on an expired budget, a retry or pause_turn continuation starts only above a 10s floor, and backoff sleeps truncate at the budget edge. A transient status on the final available attempt still passes through unchanged. - The budget governs everything before the first client-visible semantic SSE event. The stream idle timer now measures SEMANTIC progress: raw bytes and Anthropic ping events no longer reset it, closing the live gap where a ping-only upstream could hold a client forever with nothing visible. Streaming still has no total response timeout by design (BasedHardware#9135): a visible-delta stream survives budget expiry. - The detached Firestore usage write runs through a spawn seam that never inherits the request deadline. Behavioral tests drive the policy and the real stream translator with tokio::time::pause: budget-floor retry stop, backoff truncation at the edge, long visible streams surviving expiry, ping-only turns ending in a typed terminal SSE error, semantic-idle stalls independent of budget, and detached-write completion after expiry. Fixes BasedHardware#9835. Co-Authored-By: Claude Fable 5 <[email protected]>
Static tripwire (labeled as such): raw reqwest builders are not covered by signatures alone, so new direct .send() calls in routes/chat/ fail the manifest lanes. Behavioral coverage lives in the paused-time deadline tests. Caught class: BasedHardware#8640/BasedHardware#8911/BasedHardware#9135/BasedHardware#9644 (BasedHardware#9835). Co-Authored-By: Claude Fable 5 <[email protected]>
ThinkingDelta chunks reach the client as `reasoning_content`, but they did not refresh the semantic idle timer — only text deltas did. So after the initial role chunk, a Claude reasoning phase that kept emitting visible reasoning for longer than STREAM_IDLE_TIMEOUT was ended as "no semantic progress" while the client was actively receiving output, regressing the "a long visible stream is not an error" contract (BasedHardware#9135) for reasoning streams. Refresh the timer when a reasoning chunk is yielded, matching the text-delta path. Regression test drives a reasoning-only stream 200s past the 60s idle bound on the paused clock: it fails on the old code (1 of 4 reasoning deltas delivered, turn killed at the bound) and passes with the fix. Co-Authored-By: Claude Opus 4.8 <[email protected]>
36d0b4a to
f9c1230
Compare
|
Rebased onto current main (head The separate server-tool entry point is gone. This PR originally dispatched The mid-stream continuation deliberately does NOT inherit the request budget. Also: Verified on the rebased tip: |
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks for rebasing this. I re-checked the current head (f9c1230) and the code direction still looks coherent: the chat route admits one deadline before auth/body extraction, provider sends go through send_with_deadline, reasoning deltas now count as semantic progress, and the post-first-visible pause-turn continuation is intentionally given its own bounded budget rather than inheriting the request deadline.
One merge-blocking item from current CI needs fixing:
- The
Hygienejob is failing infailure-class-guard-artifact-ratchet:FC-per-hop-timeoutnow crosses the recurrence threshold, but.github/failure-classes/FC-per-hop-timeout.jsondoes not record acanonical_prevention_artifact. Since this PR adds the reusable guard surface (.github/scripts/check_chat_send_deadline.pyplus the manifest entry), please update the failure-class record to cite the canonical artifact path (or whatever field shape the ratchet expects) so the guard is durable and CI is green.
I verified locally that the Python tripwire and its unit tests pass, and the static scan finds no direct .send() calls under routes/chat/. I still cannot run the Rust tests in this environment because cargo is not installed.
This still needs human maintainer/deployment sign-off before merge for the runtime timeout contract: the 240s-under-300s Cloud Run assumption, auth/paywall/provider timing behavior, CI enforcement, and especially the newly called-out choice that mid-stream server-tool continuations get a fresh bounded budget after visible output rather than inheriting the original request budget. Once the hygiene ratchet is fixed, this looks like a positive implementation signal from automation, but not something automation should formally approve.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
Failure-Class: FC-per-hop-timeout
kodjima33
left a comment
There was a problem hiding this comment.
Real fix with a stated root cause and tests, but 918 lines puts it past the scoped-diff bar for an unattended backend merge — approving; landing it is Nik's call.
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks for the update. I re-reviewed the current head (1368b30c85174d53dd6fce346cc452b2f9342a2f) and the prior automation blocker is resolved: FC-per-hop-timeout now records .github/scripts/check_chat_send_deadline.py as the canonical prevention artifact, the manifest registers both the tripwire and its tests, and the current GitHub checks are green.
Local/static verification from this review environment:
python3 .github/scripts/test_check_chat_send_deadline.pypasses.python3 .github/scripts/check_chat_send_deadline.pypasses and finds no direct provider.send()calls underroutes/chat/.- I still cannot run the Rust suite locally here because
cargois not installed, so I’m relying on the green Rust/Backend CI for that part.
I’m dismissing my stale change-request review because it was specifically about the missing failure-class guard artifact and that is now fixed on this head.
I’m still not formally approving from automation: this remains a security/workflow-sensitive backend runtime-policy change touching auth/paywall timing, provider transport, CI enforcement, and the 240s-under-300s Cloud Run timeout assumption. A human maintainer should also explicitly sign off on the current streaming policy that post-first-visible server-tool continuations get a fresh bounded budget rather than inheriting the original request budget. From automation, this is a positive implementation signal with human deployment/runtime-policy review still required before merge.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
Resolved on 1368b30: FC-per-hop-timeout now records .github/scripts/check_chat_send_deadline.py as the canonical_prevention_artifact and the current checks are green; current automation recommendation is positive-signal/human-review, not request-changes.
…asedHardware#10054) * fix(chat): consume one request deadline budget on the Anthropic path The provider-timeout class (FC-per-hop-timeout: BasedHardware#8640, BasedHardware#8911, BasedHardware#9135, chat path now owns one admission budget instead: - RequestDeadline (240s inside the 300s platform bound, mirroring the Gemini proxy) is created in route middleware before extractors and body extraction; auth, BYOK, and paywall waits are bounded by it and budget exhaustion returns a typed 504 instead of a 401. - All provider sends go through send_with_deadline; the retry loop is a budget-aware policy: attempts never start on an expired budget, a retry or pause_turn continuation starts only above a 10s floor, and backoff sleeps truncate at the budget edge. A transient status on the final available attempt still passes through unchanged. - The budget governs everything before the first client-visible semantic SSE event. The stream idle timer now measures SEMANTIC progress: raw bytes and Anthropic ping events no longer reset it, closing the live gap where a ping-only upstream could hold a client forever with nothing visible. Streaming still has no total response timeout by design (BasedHardware#9135): a visible-delta stream survives budget expiry. - The detached Firestore usage write runs through a spawn seam that never inherits the request deadline. Behavioral tests drive the policy and the real stream translator with tokio::time::pause: budget-floor retry stop, backoff truncation at the edge, long visible streams surviving expiry, ping-only turns ending in a typed terminal SSE error, semantic-idle stalls independent of budget, and detached-write completion after expiry. Fixes BasedHardware#9835. Co-Authored-By: Claude Fable 5 <[email protected]> * harden(ci): reject chat provider sends that bypass send_with_deadline Static tripwire (labeled as such): raw reqwest builders are not covered by signatures alone, so new direct .send() calls in routes/chat/ fail the manifest lanes. Behavioral coverage lives in the paused-time deadline tests. Caught class: BasedHardware#8640/BasedHardware#8911/BasedHardware#9135/BasedHardware#9644 (BasedHardware#9835). Co-Authored-By: Claude Fable 5 <[email protected]> * fix(chat): count reasoning deltas as semantic progress ThinkingDelta chunks reach the client as `reasoning_content`, but they did not refresh the semantic idle timer — only text deltas did. So after the initial role chunk, a Claude reasoning phase that kept emitting visible reasoning for longer than STREAM_IDLE_TIMEOUT was ended as "no semantic progress" while the client was actively receiving output, regressing the "a long visible stream is not an error" contract (BasedHardware#9135) for reasoning streams. Refresh the timer when a reasoning chunk is yielded, matching the text-delta path. Regression test drives a reasoning-only stream 200s past the 60s idle bound on the paused clock: it fails on the old code (1 of 4 reasoning deltas delivered, turn killed at the bound) and passes with the fix. Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(chat): register deadline guard artifact Failure-Class: FC-per-hop-timeout --------- Co-authored-by: Claude Fable 5 <[email protected]> Co-authored-by: Max Carter 祁明思 <[email protected]>
Summary
RequestDeadlinebudget (240s inside the 300s platform bound, mirroring the Gemini proxy's ad hoc deadline) admitted in route middleware before extractors and body extraction on/v2/chat/completions, stored in request extensions.PaywalledAuthUserare bounded by the budget on this route; exhaustion returns a typed504(request_deadline_exceeded) instead of a misleading 401. Routes without the middleware are untouched.send_with_deadlineseam. The retry loop becomes a budget-aware policy (retry_with_budget): an attempt never starts on an expired budget, a retry orpause_turncontinuation starts only above a 10s floor (the connect bound), and backoff sleeps truncate at the budget edge. A transient status on the final available attempt still passes the upstream error through unchanged.pingevents no longer reset it — closing the live gap where a ping-only upstream held a client forever with nothing visible. Pre-first-event budget exhaustion emits a typed terminal SSEupstream_timeouterror (HTTP 200 is already on the wire).message_stopruns through a spawn seam that never inherits the request deadline..send()calls inroutes/chat/that bypass the seam (local+cilanes).Fixes #9835.
Root cause
Registry class FC-per-hop-timeout (#8640, #8911, #9135, #9644): each fix moved a per-attempt timeout to the current infrastructure boundary because no request-level budget existed on the Anthropic chat path. Pre-first-byte work — auth/JWK waits, paywall lookups, retries, up to three server-tool continuations — each owned a private constant with no shared clock, and the stream idle timer reset on every raw upstream byte while
pingevents emitted nothing downstream, so a pinging provider could hold a request indefinitely with zero client-visible progress.Failure class
Failure-Class: FC-per-hop-timeout
Durable guard
src/request_deadline.rsowns the budget type (remaining()/derive(cap)/expired()on the tokio clock, so tests drive it withtokio::time::pause), the admission middleware, and thesend_with_deadlineseam.tokio::time::pausetests execute the real retry policy and the real stream translator; the diff-scoped checker is a static tripwire for the one thing signatures can't see (raw reqwest builders), citing the caught class.Product invariants affected
none (verified with
scripts/pr-preflight --suggest)Validation
cargo test --locked(Backend-Rust) → 381 passed (92 in the chat module, including the six new deadline tests and the existing byte-chunk→SSE characterization tests unchanged in their assertions).tokio::time::pause(test-file header cites [codex] Fix Gemini proxy timeout handling #8640/Fix desktop Gemini proxy timeout observability #8911/desktop-backend Gemini proxy returns persistent 504s while /health stays green #9135/fix(desktop): restore Gemini platform deadline #9644):retry_chain_stops_at_budget_floor— with 7s remaining against the 10s floor, a transient error passes through after one attempt instead of starting an attempt it can't finish.retry_backoff_truncates_at_budget_edge— 250ms backoff, 100ms budget: exactly 100ms elapses, no second attempt.visible_stream_survives_budget_expiry— visible deltas continue 200s past a 5s budget and finish normally; noupstream_timeoutanywhere.ping_only_stream_hits_budget_with_typed_error— ping-only upstream ends at the 5s budget edge with a typed terminal SSE error (the live gap this closes).post_first_event_stall_dies_from_semantic_idle_timer— with a 100,000s budget, a post-first-event ping-only stall dies at the 60s semantic idle bound; pings do not reset it.detached_usage_write_completes_after_deadline_expiry— the spawn seam completes under its own policy long after the budget expired.cargo check --lockedclean;cargo fmt --checkclean. (cargo clippyis red on currentmain— 271 pre-existingunwrapdenials in tests; this PR adds no new clippy class and clippy is not a repo lane.)python3 .github/scripts/check_chat_send_deadline.py→ clean on the new module; its fixtures (test_check_chat_send_deadline.py) → 3 passed.python3 .github/scripts/test_run_checks.py→ 20 passed (manifest contract with the two new entries).make preflight(local lane, this PR body) → all selected checks pass.Deployed platform timeout config: not verifiable from this environment (external contributor, no production access). The 300s figure is the code-side constant
PLATFORM_REQUEST_TIMEOUT, consistent withproxy.rs'sCLOUD_RUN_REQUEST_TIMEOUT; per the issue's proof list, the deployed Cloud Run value (including its behavior on streaming connections) needs maintainer verification and recording before the FC-4 registry clock starts.Not exercised live: a real Anthropic streaming turn through a dev build (no API keys in this environment). The paused-time tests drive the real production stream translator and retry policy through the same seams production uses.
Cut list (per the issue)
RequestDeadlineis the named follow-up;proxy.rskeeps its working ad hoc deadline.