Skip to content

Fix desktop Gemini proxy timeout observability - #8911

Merged
kodjima33 merged 2 commits into
BasedHardware:mainfrom
tianmind-studio:codex/desktop-gemini-proxy-timeout
Jul 3, 2026
Merged

kodjima33 merged 2 commits into
BasedHardware:mainfrom
tianmind-studio:codex/desktop-gemini-proxy-timeout

Conversation

@tianmind-studio

@tianmind-studio tianmind-studio commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #8906.

Summary

  • reduce the non-streaming Gemini proxy upstream deadline from 120s to 90s so the Rust desktop backend returns a proxy-owned retryable timeout before the observed Cloud Run boundary
  • log non-streaming Gemini upstream failures through the same aggregate upstream_result shape as successful upstream responses, including provider/model/action/payload bucket/duration bucket/phase/status
  • avoid adding request bodies, provider responses, tokens, prompts, or user IDs to the aggregate upstream result log line
  • add a desktop changelog fragment for the faster retryable timeout behavior

Testing

  • git diff --check
  • PowerShell JSON parse for desktop/macos/changelog/unreleased/20260703-gemini-proxy-timeout.json
  • PRE_PUSH_SKIP_DESKTOP_RUST=1 scripts/pre-push -> passed non-Rust gates; desktop changelog fragment found

Note

This Windows machine does not have cargo/rustfmt installed, so I could not run the local desktop Rust checks. The GitHub Lint & Format Check desktop Rust job should run rustfmt --check and cargo check --locked for this PR.

Review in cubic

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @tianmind-studio — this is a clean, well-scoped fix for the #8906 regression.

What I like:

  • Reducing the non-streaming upstream timeout 120s -> 90s gives the proxy more headroom to return its own sanitized, retryable 504 (retry-after: 30) before the Cloud Run boundary kills the request. The updated test asserting <= 90s and < 120s documents the intent well.
  • Structuring upstream failure logging through map_upstream_error_with_context + the shared log_upstream_result helper is a real observability win — timeouts and transport errors now emit the same provider/model/action/payload_bucket/duration_bucket/phase/status shape as successful completions, which is exactly what the issue's acceptance criteria asked for.
  • Removing uid from the aggregate upstream_result line is a nice privacy improvement (it stays on the forwarded/degraded lines for correlation).
  • Dropping the unused user: &AuthUser param from gemini_proxy_server_key is a tidy cleanup with no behavior change.
  • Changelog fragment follows the repo schema.

Two non-blocking observations for a maintainer:

  1. The 120s -> 90s value is a production reliability tuning call — worth confirming against the real Cloud Run latency distribution from the Regression: desktop-backend Gemini proxy generateContent still returns 504s after v0.12 #8906 observability sweep so 90s comfortably sits below whatever boundary is producing the 504s (~120s sampled latency).
  2. The streaming paths (gemini_stream_proxy / gemini_stream_server_key) still use the older map_upstream_error without the new context logging, so this observability improvement is non-streaming-only. A follow-up that mirrors the same logging onto the streaming error paths would close the gap.

No security or supply-chain concerns on my read. Flagging for maintainer review because this touches the provider/model proxy surface and the timeout value is a prod tuning decision.

@Git-on-my-level Git-on-my-level added the needs-maintainer-review Needs a human maintainer to sign off before merge label Jul 3, 2026

@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.

Desktop bug fix (owner-override): improve Gemini proxy timeout observability/handling in local Rust proxy. Small, CI-green.

@kodjima33
kodjima33 merged commit d8180ff into BasedHardware:main Jul 3, 2026
2 checks passed
Git-on-my-level added a commit that referenced this pull request Jul 3, 2026
Closes #8950.

## Summary
- fix Gemini realtime ephemeral token minting by sending Google Live
API's documented `authToken` request wrapper instead of top-level token
fields
- move benign long-lived realtime idle teardown out of the failure-like
`realtime_provider_session_error` bucket into
`realtime_provider_expected_idle_teardown`
- add stable realtime diagnostics dimensions for auth mode, failure
class, HTTP status, and barge-in replacement mint failures so the daily
health report can separate actual provider/session failures from
lifecycle noise
- add focused Swift and Rust regression coverage plus a desktop
changelog fragment

## Recently merged coverage
- #8911 already addressed part of the broader July 3 Gemini picture by
improving non-streaming Gemini proxy timeout observability and retryable
timeout behavior.
- That did not cover this issue's realtime health stream or
`/v2/realtime/session` Gemini ephemeral-token mint path, which are fixed
here.

## Root cause
The Gemini realtime mint route posted `uses`, `expireTime`, and
`newSessionExpireTime` at the top level. Google's current Live API
`CreateAuthTokenRequest` requires those settings under `authToken`, so
managed Gemini realtime users could fail before opening the provider
session. Separately, expected Gemini idle closes were correctly
classified locally but still emitted into the failure-like health event
stream.

## Testing
- `git diff --check`
- `cargo test --manifest-path desktop/macos/Backend-Rust/Cargo.toml
gemini_auth_token_body_wraps_settings_under_auth_token`
- `xcrun swift test --package-path desktop/macos/Desktop --filter
'DesktopDiagnosticsManagerTests|RealtimeHubCloseClassifierTests'`
- `scripts/pre-push`



<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/8953?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. -->
kodjima33 added a commit that referenced this pull request Jul 12, 2026
… (#9583)

Fixes #9135.

## Bug (live on prod)

The desktop Gemini proxy returns persistent `504`s on
`/v1/proxy/gemini/models/gemini-2.5-flash:generateContent` while
`/health` stays green.

## Root cause

**The proxy — not the upstream — was the binding deadline.**

`GEMINI_UPSTREAM_TIMEOUT` was hardcoded to 90s, with the comment "keep
non-streaming upstream calls
below observed Cloud Run request boundaries". But `desktop-backend`'s
Cloud Run request timeout is
actually **300s** (`gcloud run services describe desktop-backend
--format='value(spec.template.spec.timeoutSeconds)'` → `300`),
and the Swift client waits **300s** (`GeminiClient.swift`) and
deliberately does not auto-retry timeouts.

So the 90s guess was ~3.3x tighter than the real bound, and it aborted
generations the model had
already spent the money to produce.

## Prod evidence (last 6h, `desktop-backend` Cloud Logging)

- **11 of 1000** `/v1/proxy/gemini` unary calls returned `504` (~1.1%).
- **Every** `504` had latency **90.03–90.13s** — our own timeout firing,
not an upstream failure.
- All were `phase=request status=timeout provider=vertex_ai
model=gemini-2.5-flash`,
  `payload_bucket` 16–512kb.
- Successful calls reach **84.5s**, and 6 completed in the `60-120s`
bucket — the latency tail
  straddles the cap, so the cap was slicing through live traffic.

## Upstream premise verified against real prod Vertex AI

Long-context 2.5-flash spends most of its wall-clock *thinking*, before
the first response byte:

| request | result |
|---|---|
| 181 KB / 40k prompt tokens | `200` in **64.3s** (7,863 thinking
tokens) |
| 741 KB / 150k prompt tokens | `200` in **95.5s**, full valid answer |

The second one **would have been 504'd at 90s** — a successful
generation thrown away, and the user
shown "AI request took too long".

## Fix

Derive the deadline from the platform bound instead of hardcoding a
guess:

```rust
const CLOUD_RUN_REQUEST_TIMEOUT: Duration = Duration::from_secs(300);
const GEMINI_UPSTREAM_HEADROOM_SECS: u64 = 60;
const GEMINI_UPSTREAM_TIMEOUT: Duration =
    Duration::from_secs(CLOUD_RUN_REQUEST_TIMEOUT.as_secs() - GEMINI_UPSTREAM_HEADROOM_SECS); // 240s
```

This closes the failure class rather than re-tuning a number: the
deadline can no longer drift above
the platform timeout, so the proxy always remains the component that
gives up first and clients keep
getting our typed, retryable `upstream_timeout` JSON instead of an
opaque platform 504.

Streaming is untouched (it correctly has no total-response timeout).
Error classification, structured
`upstream_result` logging, and the typed 504 body already landed in
#8911 — this fixes the remaining
defect: the deadline itself.

## Regression test

The existing test hardcoded the very bound that was wrong
(`GEMINI_UPSTREAM_TIMEOUT <= 90s`), so it
would have *locked the bug in*. It now asserts the real contract:
strictly below the platform
timeout, ≥30s flush headroom, and generous enough to cover the observed
completion tail.

## Verification

- `cargo test proxy::` → **78 passed**, 0 failed
- `cargo clippy` → clean (no warnings)
- `cargo check` → clean
- Prod log analysis + real prod Vertex timing runs above

**Not exercised:** an authenticated >90s request through the running
proxy — that needs a signed-in
desktop session and Omi Dev is not signed in on this machine. The
upstream premise and the constant
contract are proven; the passthrough itself is not path-exercised.

🤖 automated by hourly watchdog


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/9583?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. -->
Git-on-my-level added a commit that referenced this pull request Jul 13, 2026
## Summary

- replace the permanently cached Redis connection with a
generation-aware, single-flight recovery owner
- classify Redis failures, retry safe commands once, and never replay
outcome-ambiguous metering scripts
- fail managed Gemini/chat/TTS requests closed when Redis metering is
unavailable while preserving BYOK bypasses
- expose Redis dependency state at `/ready` without removing
Redis-independent traffic from Kubernetes service readiness
- give non-streaming Gemini work one 75-second end-to-end budget,
propagate downstream cancellation, preserve request correlation, and
emit bounded phase-owned outcomes

Addresses #9524.

## Root cause and recurrence

The Rust backend cached one multiplexed Redis connection for the process
lifetime. A broken pipe was returned to the caller, but no owner
invalidated that connection, so every later metered request reused the
stale generation until process restart. The same owner also allowed
concurrent cold-start connections.

The Gemini timeout class recurred after #8640 and #8911 because those
fixes only moved a per-attempt timeout to the current infrastructure
boundary. Token acquisition, provider fallback, dispatch, and body drain
did not share one logical deadline, and timeout outcomes were not
separated from auth or generic provider failures.

## Durable guard

- Redis leases carry generation and age; stale failures conditionally
invalidate only their own generation.
- Connection creation is single-flight with bounded connect/command
deadlines, per-instance jitter, and cooldown after exhaustion.
- Transport failures reconnect; auth/config, capacity, and command/data
errors do not masquerade as stale transport.
- Reads and idempotent final-state writes replay at most once.
Rate-limit Lua scripts and task acceptance never replay after an
outcome-unknown transport failure.
- Redis operation telemetry has bounded operation/failure/reconnect
fields and production-visible success denominators.
- Managed-key metering fails closed with retryable 503 responses; BYOK
remains Redis-independent.
- Gemini uses one logical deadline below the observed 90-second
boundary. Auth timeout, provider timeout, 429, provider 5xx, transport
failure, and cancellation are distinct bounded outcomes; provider/mode
changes use the shared fallback event.
- Request IDs are returned on proxy-owned provider errors and logged
without prompts, bodies, keys, or user content.

## Verification

- `cd desktop/macos && bash test.sh` — launcher checks passed, Rust
suite passed, and 237 Swift suites passed in isolation
- `cd desktop/macos/Backend-Rust && cargo test --locked` — 346 passed
- `cd desktop/macos/Backend-Rust && cargo check --locked` — passed
- `cd desktop/macos/Backend-Rust && cargo fmt -- --check` — passed
- `make preflight` — all 9 selected manifest checks passed; no locked
product invariants apply
- independent agent review — approved with no remaining blocker

The fault tests exercise the production Redis client against scripted
RESP sockets: first-command connection close, safe replay recovery,
non-replayable EVAL, eight concurrent stale callers, reconnect
exhaustion, repeated stale generations, and auth/config rejection.
Gemini tests exercise a hanging local upstream plus a real Axum HTTP
downstream disconnect, proving the upstream request is dropped without
detached work.

## Rollout notes

No production mutation is included in this PR. After deployment, verify
the exact revision with a controlled Redis connection close,
authenticated managed-key TTS, and a natural-traffic window longer than
the prior short soak. Roll back on retry amplification, duplicate
metering, or a new TTS failure cluster.

The repository does not own the external release-health dashboard/alert
consumer. This PR supplies bounded `gemini_provider_request` outcomes so
#9523 can exclude provider timeouts from release-regression aggregation
while continuing to report the provider SLO separately.


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/9533?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 added a commit to aryanorastar/omi that referenced this pull request Jul 23, 2026
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]>
aryanorastar added a commit to aryanorastar/omi that referenced this pull request Jul 23, 2026
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]>
aryanorastar added a commit to aryanorastar/omi that referenced this pull request Jul 23, 2026
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]>
aryanorastar added a commit to aryanorastar/omi that referenced this pull request Jul 23, 2026
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]>
aryanorastar added a commit to aryanorastar/omi that referenced this pull request Jul 24, 2026
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]>
aryanorastar added a commit to aryanorastar/omi that referenced this pull request Jul 24, 2026
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]>
aryanorastar added a commit to aryanorastar/omi that referenced this pull request Jul 24, 2026
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]>
aryanorastar added a commit to aryanorastar/omi that referenced this pull request Jul 24, 2026
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]>
aryanorastar added a commit to aryanorastar/omi that referenced this pull request Jul 26, 2026
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]>
aryanorastar added a commit to aryanorastar/omi that referenced this pull request Jul 26, 2026
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]>
kodjima33 pushed a commit that referenced this pull request Jul 28, 2026
…10054)

* fix(chat): consume one request deadline budget on the Anthropic path

The provider-timeout class (FC-per-hop-timeout: #8640, #8911, #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 (#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 #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: #8640/#8911/#9135/#9644 (#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 (#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]>
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: desktop-backend Gemini proxy generateContent still returns 504s after v0.12

3 participants