Skip to content

Recover stale Redis connections and isolate Gemini timeouts - #9533

Merged
Git-on-my-level merged 6 commits into
mainfrom
codex/issue-9524
Jul 13, 2026
Merged

Git-on-my-level merged 6 commits into
mainfrom
codex/issue-9524

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Jul 12, 2026 •

Copy link
Copy Markdown
Member

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.

Review in cubic

Git-on-my-level and others added 4 commits July 12, 2026 10:40
Parenthesize reconnect jitter so -D warnings clippy passes in CI, and
label missing Redis as not_configured instead of auth_config.

Co-authored-by: Cursor <[email protected]>
Missing vertex_auth is steady-state AI Studio routing at boot, not a mid-request heal. Keep record_fallback only for Vertex token failure (reason=auth).

Co-authored-by: Cursor <[email protected]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

@cursor resolve merge conflicts

@cursor

cursor Bot commented Jul 12, 2026 •

Copy link
Copy Markdown

Merge conflicts are resolved and pushed to codex/issue-9524.

Conflicts resolved

Two files conflicted when merging origin/main:

  1. desktop/macos/Backend-Rust/src/services/redis.rs — Kept this PR’s generation-aware Redis recovery (single-flight reconnect, replay policies, fail-closed metering). Main’s simpler ConnectionManager approach was dropped in favor of the more complete fix in Desktop backend: recover stale Redis connections and isolate Gemini timeout failures from release health #9524.

  2. desktop/macos/Backend-Rust/src/routes/proxy.rs — Kept this PR’s 75s end-to-end Gemini deadline model (GEMINI_TOTAL_TIMEOUT / GEMINI_ATTEMPT_TIMEOUT with within_gemini_deadline). Main’s 240s GEMINI_UPSTREAM_TIMEOUT (from desktop-backend Gemini proxy returns persistent 504s while /health stays green #9135) was not adopted, since this PR intentionally replaces that with a unified deadline and bounded phase outcomes.

Verification

cd desktop/macos/Backend-Rust && cargo test --locked
# 348 passed

The merge commit is on the branch: a99bd7fff. PR #9533 should show as mergeable once GitHub finishes recalculating status.

Open in Web Open in Cursor 

Resolve conflicts in Backend-Rust by keeping the PR's generation-aware
Redis recovery owner and the 75s Gemini end-to-end deadline model.

Verification: cd desktop/macos/Backend-Rust && cargo test --locked (348 passed)

Co-authored-by: David Zhang <[email protected]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

@cursor address merge conflicts

@cursor

cursor Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

Merge conflicts are resolved and pushed to codex/issue-9524 (commit c9d279c94). PR #9533 is now mergeable (GitHub may still show BLOCKED until CI/review gates pass).

What conflicted

main had moved forward with the dormant data-plane cleanup (refactor(desktop-backend): delete dormant data plane), which collided with this PR’s Redis and config work.

Resolution

  1. redis.rs — Kept this PR’s generation-aware recovery, replay policies, and fail-closed metering. Adopted from main:

    • #![deny(dead_code, unreachable_pub)]
    • pub(crate) visibility
    • Removal of unused conversation/task/app Redis methods (already deleted on main)
    • rate_limit_keys / tts_rate_limit_keys helpers
  2. config.rs — Kept PR semantics (encryption_secret, fail-closed Redis warning) and restored ENCRYPTION_SECRET loading that the merge had dropped.

  3. .env.example — Kept the PR version with ENCRYPTION_SECRET and the expanded Redis readiness/metering comment.

Verification

cd desktop/macos/Backend-Rust && cargo test --locked
# 339 passed
Open in Web Open in Cursor 

Resolve conflicts by keeping generation-aware Redis recovery and fail-closed
metering while adopting main's dormant-data-plane deletion and pub(crate)
visibility lint. Restore encryption_secret config loading dropped in the merge.

Verification: cd desktop/macos/Backend-Rust && cargo test --locked (339 passed)

Co-authored-by: David Zhang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants