Skip to content

fix(chat): FC-4 request deadline budget for the Anthropic chat path - #10054

Merged
kodjima33 merged 4 commits into
BasedHardware:mainfrom
aryanorastar:fix/9835-chat-request-deadline
Jul 28, 2026
Merged

kodjima33 merged 4 commits into
BasedHardware:mainfrom
aryanorastar:fix/9835-chat-request-deadline

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Jul 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Adds a RequestDeadline budget (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.
  • Auth, BYOK-state, and paywall waits inside PaywalledAuthUser are bounded by the budget on this route; exhaustion returns a typed 504 (request_deadline_exceeded) instead of a misleading 401. Routes without the middleware are untouched.
  • All chat provider sends go through a narrow send_with_deadline seam. The retry loop becomes a budget-aware policy (retry_with_budget): an attempt never starts on an expired budget, a retry or pause_turn continuation 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.
  • The budget governs everything up to 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 held a client forever with nothing visible. Pre-first-event budget exhaustion emits a typed terminal SSE upstream_timeout error (HTTP 200 is already on the wire).
  • Explicitly preserved: streaming has no total response timeout (desktop-backend Gemini proxy returns persistent 504s while /health stays green #9135 — a long answer is not an error); a stream emitting visible deltas survives budget expiry, proven by test.
  • The detached Firestore usage write on message_stop runs through a spawn seam that never inherits the request deadline.
  • A manifest-registered static tripwire (labeled as such) rejects new direct .send() calls in routes/chat/ that bypass the seam (local + ci lanes).

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 ping events 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.rs owns the budget type (remaining() / derive(cap) / expired() on the tokio clock, so tests drive it with tokio::time::pause), the admission middleware, and the send_with_deadline seam.
  • Policy clocks are explicitly out of the budget: the unknown-kid refresh cooldown, cache TTLs, the idle-timer policy value, and startup retries stay independent (documented in the module).
  • Enforcement is layered per Failure-class protocol and recurrence ratchets #9822's rule: the behavioral tokio::time::pause tests 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).
  • New behavioral tests, all under 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):
    • (a) 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.
    • (b) retry_backoff_truncates_at_budget_edge — 250ms backoff, 100ms budget: exactly 100ms elapses, no second attempt.
    • (c) visible_stream_survives_budget_expiry — visible deltas continue 200s past a 5s budget and finish normally; no upstream_timeout anywhere.
    • (d) 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).
    • (e) 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.
    • (f) detached_usage_write_completes_after_deadline_expiry — the spawn seam completes under its own policy long after the budget expired.
  • cargo check --locked clean; cargo fmt --check clean. (cargo clippy is red on current main — 271 pre-existing unwrap denials 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 with proxy.rs's CLOUD_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)

  • Gemini proxy unification onto RequestDeadline is the named follow-up; proxy.rs keeps its working ad hoc deadline.
  • No retry-policy redesign — counts and backoff shape unchanged, only budget-awareness.
  • No per-user/per-model budgets; one admission constant for the route class.
  • No streaming total timeout — explicitly preserved as absent.

Review in cubic

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@Git-on-my-level Git-on-my-level added needs-maintainer-review Needs a human maintainer to sign off before merge security-review Touches auth, provider routing, secrets, or security-sensitive surfaces workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior labels Jul 19, 2026

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 under routes/chat/ after the change.
  • I could not run the Rust chat tests here because this review environment does not have cargo installed, 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.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level Noted. We'll wait for a human maintainer to review the runtime policy.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

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 (cargo test), and the Python send_with_deadline tripwire + its unit tests are green in CI on this head.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Anthropic chat deadline budget — approved; not auto-merged (large backend change)

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the follow-up on the deadline budget and CI tripwire. I found one blocking edge case in the streaming path:

  • ThinkingDelta chunks are emitted to clients as reasoning_content, but they do not refresh the new semantic-progress timer. After the initial role chunk, a long reasoning phase that keeps sending visible reasoning_content can still be terminated once STREAM_IDLE_TIMEOUT elapses, 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.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Good catch — that was a real regression in my change, and you called the mechanism exactly right. Fixed.

ThinkingDelta yields reasoning_content to the client but was the only client-visible chunk that didn't refresh first_visible_at. I checked every yield site rather than just patching the reported one — the role chunk, text deltas, tool deltas and the finish chunk all refresh it; ThinkingDelta was the sole gap (the remaining un-refreshed yield is the terminal usage chunk at message_stop, where the turn is already ending). So after the initial role chunk, a reasoning-only phase was killed at STREAM_IDLE_TIMEOUT while the client was actively receiving reasoning output.

The fix refreshes the timer when a reasoning chunk is yielded, matching the text-delta path.

Regression test (reasoning_only_stream_survives_the_semantic_idle_timer, paused clock): a reasoning-only upstream emits thinking_delta every 50s across 200s — well past the 60s idle bound, each gap inside it — then finishes. It asserts all four reasoning deltas reach the client, the turn ends with finish_reason: stop and [DONE], and no upstream_timeout.

I verified it actually catches the bug rather than just passing:

without the fix → FAILED: assertion `left == right` failed
                  left: 1   right: 4      (turn killed at the idle bound)
with the fix    → ok. 1 passed

Full crate on the rebased head: cargo test --locked → 404 passed, cargo fmt --check clean. Also rebased onto latest main.

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.

@aryanorastar
aryanorastar force-pushed the fix/9835-chat-request-deadline branch from c16021f to a58c23d Compare July 24, 2026 01:26
undivisible added a commit that referenced this pull request Jul 24, 2026
…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. -->
@aryanorastar
aryanorastar force-pushed the fix/9835-chat-request-deadline branch from a58c23d to 36d0b4a Compare July 24, 2026 09:05
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Both are already in the current tip (36d0b4a2de) — I think the review predates the rebase I pushed earlier today:

  • Code: ThinkingDelta refreshes the timer — streaming.rs:393 sets first_visible_at = Some(now()) right after yielding the reasoning_content chunk, so a long reasoning phase resets the idle bound exactly like text deltas.
  • Test: reasoning_only_stream_survives_the_semantic_idle_timer (tests/all.rs:2323, #[tokio::test(start_paused = true)]) streams reasoning-only deltas across 200s — past the 60s bound, each gap inside it — and asserts all 4 reach the client, the turn finishes stop, and no upstream_timeout.
cargo test reasoning_only_stream_survives ... test result: ok. 1 passed

A fresh CI run against the current tip should be green on this. Thanks for the careful read on the reasoning-stream contract.

@Git-on-my-level
Git-on-my-level dismissed their stale review July 24, 2026 18:22

Resolved on current head 36d0b4a: ThinkingDelta/reasoning_content now refreshes semantic progress, with paused-time regression coverage.

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

aryanorastar and others added 3 commits July 26, 2026 22:13
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]>
@aryanorastar
aryanorastar force-pushed the fix/9835-chat-request-deadline branch from 36d0b4a to f9c1230 Compare July 26, 2026 16:44
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Rebased onto current main (head f9c1230) — it had gone CONFLICTING because main's paused-turn work (#10637, #10549 and the surrounding web-search commits) reshaped the same files. One design decision in here needs your eyes, because it changes where the budget applies:

The separate server-tool entry point is gone. This PR originally dispatched requires_public_web to its own handle_server_tool_streaming. Main has since folded that path into handle_streaming, so that function and the route-level branch are deleted — the deadline now threads into main's two existing entry points instead. Net simplification.

The mid-stream continuation deliberately does NOT inherit the request budget. complete_anthropic_server_tool_turn is now also called from inside the SSE stream (streaming.rs, paused-turn resume). Its own comment assumes "a continuation is pre-first-visible-event work" — that was true when I wrote it, and is false at main's new call site. Passing the request deadline there would kill a long stream whose turn pauses for web search past the 240s budget, i.e. it would give streaming the total-response timeout this PR explicitly says it does not add (the budget governs only until first_visible_at, then STREAM_IDLE_TIMEOUT takes over). So that call gets its own fresh budget: a stuck continuation stays bounded, the stream does not gain a total cap. Main had no bound there at all, so this is strictly tighter than main and strictly looser than inheriting the request deadline — flagging it since it is exactly the externally visible timeout semantics you asked to sign off on.

Also: AnthropicSendError gained #[derive(Debug)] so the continuation's failure log distinguishes DeadlineExpired from Gateway(status).

Verified on the rebased tip: cargo test --locked → 390 passed, 0 failed (main's paused-turn/continuation suites and this PR's deadline suite green together), cargo check --locked clean with no warnings, cargo fmt --check clean, and the line-count ratchet passes on every changed file.

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 Hygiene job is failing in failure-class-guard-artifact-ratchet: FC-per-hop-timeout now crosses the recurrence threshold, but .github/failure-classes/FC-per-hop-timeout.json does not record a canonical_prevention_artifact. Since this PR adds the reusable guard surface (.github/scripts/check_chat_send_deadline.py plus 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 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.py passes.
  • python3 .github/scripts/check_chat_send_deadline.py passes and finds no direct provider .send() calls under routes/chat/.
  • I still cannot run the Rust suite locally here because cargo is 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.

@Git-on-my-level
Git-on-my-level dismissed their stale review July 27, 2026 23:57

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.

@kodjima33
kodjima33 merged commit 5e9c0d5 into BasedHardware:main Jul 28, 2026
31 checks passed
undivisible added a commit to Archit-lal/omi that referenced this pull request Jul 29, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-maintainer-review Needs a human maintainer to sign off before merge security-review Touches auth, provider routing, secrets, or security-sensitive surfaces workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FC-4: request deadline budget for the Anthropic chat path — stop fixing per-hop timeouts retail

4 participants