Skip to content

Desktop backend: recover stale Redis connections and isolate Gemini timeout failures from release health #9524

Closed

Description

@Git-on-my-level

Summary

Close two runtime failure classes observed around the v0.12.70 stable release:

  1. The Rust desktop backend caches a Redis multiplexed connection and does not invalidate/reconnect it after transport failures. Once stale, TTS and other metered paths can fail repeatedly with broken pipe.
  2. Gemini proxy requests repeatedly time out at the infrastructure boundary. These inherited provider failures must have explicit timeout/fallback ownership and must not be conflated with desktop-release regressions.

This issue is independently deployable from the release-platform work. It should land before the next stable desktop release so candidate probes can enforce the corrected behavior.

Evidence: stale Redis connection

Before the .70 backend cutover, revision desktop-backend-00883-tcp produced at least 74 POST /v1/tts/synthesize 503 responses from 00:41:53Z to 01:08:30Z. Each paired with:

tts_synthesize: Redis rate-limit error ... broken pipe

The failures were fast 503s from the fail-closed rate-limit path, not OpenAI TTS latency.

The first known broken pipe on the old revision appeared roughly 31 hours after its deploy. Restarting via the .70 deployment established a fresh connection and immediately restored TTS, but did not prove durable closure.

Code inspection at exact .70 source 2bdd18a7e397b4c7aab8199443def178c0e9b0e0 showed:

  • one cached Redis multiplexed connection;
  • no invalidation/reconnect path after command transport error;
  • TTS rate-limit failure maps to 503 to avoid unmetered server-key use.

The exact ten-minute post-cutover soak on desktop-backend-00884-wvg processed 1,477 requests. TTS was 342/342×200 with zero broken-pipe/TTS-error logs. Later monitoring produced another 353×200 and one expected rate-limit 429 with zero broken pipes. This proves immediate recovery after restart, not long-lived resilience.

Evidence: Gemini timeout class

During the same ten-minute new-revision window:

  • 11 requests returned 504;
  • all were POST Gemini 2.5 Flash generateContent;
  • each failed at approximately the 90-second upstream timeout;
  • the same class existed on .0 before cutover.

These timeouts were unrelated to release identity, update feeds, Redis or TTS. They need separate ownership so release dashboards do not report one undifferentiated 5xx signal.

Required Redis changes

  • Wrap connection acquisition behind a recoverable owner rather than exposing one permanently cached connection.
  • Classify Redis command errors into:
    • retryable transport/connection errors;
    • non-retryable command/data errors;
    • capacity/auth/configuration errors.
  • On retryable transport error:
    1. invalidate the cached connection generation;
    2. reconnect with bounded jitter;
    3. retry only operations that are safe/idempotent;
    4. allow one caller to reconnect while others wait or fail boundedly.
  • Do not fail open for metering/rate limiting.
  • Prevent retry amplification during Redis outage.
  • Expose bounded telemetry:
    • operation;
    • failure class;
    • reconnect attempted/succeeded/exhausted;
    • outcome recovered/degraded/exhausted;
    • connection generation/age bucket, not credentials or user data.
  • Apply the common recovery path to TTS, chat/Gemini metering and every Rust desktop Redis consumer.
  • Add readiness/dependency state that distinguishes service process health from Redis operational readiness.

Required Gemini changes

  • Define an intentional client timeout below the infrastructure hard ceiling.
  • Propagate cancellation when callers disconnect.
  • Bound retries to safe request types and total deadline.
  • Use shared fallback telemetry when provider/mode changes; do not invent an unbounded metric.
  • Decide the user-visible outcome for:
    • provider timeout;
    • caller cancellation;
    • rate limit;
    • upstream 5xx;
    • exhausted fallback.
  • Separate provider timeout SLO/alerts from release health.
  • Preserve request correlation without logging prompts or response bodies.

Fault-injection tests

Redis tests must cover:

  • server closes an established connection;
  • broken pipe on the first command;
  • concurrent callers during reconnect;
  • reconnect succeeds and the original safe operation recovers once;
  • reconnect exhausts and TTS remains fail closed;
  • non-idempotent operations are not duplicated;
  • auth/configuration error is not retried as transport;
  • repeated stale cycles do not leak tasks/connections;
  • process restart is not required for recovery.

Gemini tests must cover:

  • upstream hangs past client deadline;
  • caller disconnect cancels upstream;
  • retry/fallback stays inside total budget;
  • timeout telemetry is attributed to provider/model/route with bounded labels;
  • release-health aggregation excludes known provider timeouts while still reporting them.

Production verification

  • Deploy as a named candidate/zero-traffic revision when the promotion engine supports it; until then use a controlled backend rollout with exact rollback revision.
  • Force a Redis connection close in a safe test seam and prove reconnect without process restart.
  • Exercise authenticated TTS through the real rate-limit path.
  • Observe representative natural traffic for longer than the prior short soak; record connection age.
  • Verify Gemini timeout rate and latency distribution separately.
  • Roll back on retry amplification, duplicate metering, unmetered fail-open, or a new TTS failure cluster.

Acceptance criteria

  • Forced stale Redis connection recovers without process restart.
  • TTS never bypasses metering.
  • Safe operations retry at most once per bounded policy.
  • Non-idempotent operations are not duplicated.
  • Reconnect concurrency is bounded.
  • All Redis consumers use the shared recovery owner.
  • TTS/Redis metrics have honest denominators.
  • Gemini timeout policy is explicit and tested.
  • Provider timeouts and release regressions are separately visible.
  • Production evidence includes exact revision, fault injection and natural-traffic window.

Related issue pack

Dependency graph

#9526 ──> #9525 ──> blocking phase-aware gates in #9523
   └────────────────> canonical identity checks in #9523

#9524 ── independent implementation lane
   ├────────────────> semantic runtime probes consumed by #9525
   └────────────────> bounded runtime telemetry consumed by #9523

Dependencies and rollout ordering

Activity

  1. added
    bug
    maintainer
    p1
    needs-tests
    on Jul 12, 2026
  2. Git-on-my-level commented on Jul 13, 2026

    @Git-on-my-level
    MemberAuthor

    Implementation packet — live rollout state and fresh bounded telemetry (2026-07-13)

    Code versus deployment status

    Therefore, this is no longer an open-ended implementation-discovery task. The code path is available in dev; the remaining work is behavioral qualification and a separately approved production rollout.

    Fresh six-hour error snapshot

    Environment Sampled Cloud Run 5xx evidence
    dev 365 rows: 359 Gemini 2.5 Flash proxy 504s, 2 Gemini 502s, plus 4 screen-activity sync 503s
    prod 500-row query cap reached: at least 463 Gemini 2.5 Flash proxy 504s, 33 TTS synthesize 503s, and smaller residual buckets

    The dev sample is below the query cap; production counts are lower bounds. The merged change must therefore be evaluated by bounded reconnect/fallback behavior and user-visible outcome, not by expecting upstream Gemini 504s to disappear.

    Implementation/qualification direction

    1. Do not open a duplicate reconnect implementation unless a focused fault-injection test demonstrates Recover stale Redis connections and isolate Gemini timeouts #9533 fails its intended contract.
    2. In dev, inject/observe Redis reconnect and Gemini-timeout paths; assert bounded retries, fallback/response behavior, metric cardinality, and no request wedging.
    3. Record the exact candidate revision, comparison window, route/error buckets, and rollback revision before a prod promotion.
    4. Promote only through the established backend workflow with a separately approved production plan; then verify TTS recovery and Gemini outcomes independently.

    No additional cloud discovery is required for an implementer to understand the remaining work. A production traffic change remains an approval-gated operation.

  3. Git-on-my-level commented on Jul 13, 2026

    @Git-on-my-level
    MemberAuthor

    Root cause confirmed — current dev 504s are a self-imposed 70-second cutoff

    Fresh dev evidence establishes a concrete regression:

    • Cloud Run desktop-backend allows timeoutSeconds: 300.
    • The serving dev revision is desktop-backend-00507-sjh and runs the current proxy contract with GEMINI_ATTEMPT_TIMEOUT = 70s and outer GEMINI_TOTAL_TIMEOUT = 75s.
    • An eight-hour read-only log sample returned 522 Gemini Flash generateContent 504s. Their request latencies cluster at approximately 70.0s, and matching application logs state gemini_proxy: upstream request timed out: error sending request: operation timed out.

    This is not a Cloud Run deadline and should not be treated as generic provider instability. The proxy is cutting off work that the infrastructure and client are prepared to wait for.

    Existing precedent and repair shape

    Closed #9135 previously fixed this exact class by deriving the proxy deadline from Cloud Run's 300-second contract, reserving 60 seconds of response headroom (about 240 seconds usable), with evidence that valid long-context Gemini calls complete beyond 90 seconds. That timeout contract is no longer present in the current proxy implementation after later parallel proxy changes.

    Repair by restoring the platform-derived deadline contract on top of the current telemetry/metering/error-classification code; do not revert the newer proxy work wholesale.

    Required dev-first tests/qualification:

    1. Regression test: non-streaming deadline remains below Cloud Run but at least 180 seconds, with explicit response headroom.
    2. Preserve no unsafe post-dispatch retry, typed timeout response, rate limiting, request IDs, and current telemetry.
    3. Deploy dev only, then compare a matched window for Gemini 504 rate, 60–120s successful calls, outcome/duration distribution, and TTS separately.
    4. Do not promote to prod until the dev 504 reduction and user-visible fallback behavior are qualified.
  4. added a commit that references this issue on Jul 13, 2026
    f349c9b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdesktopmacOSmaintainerneeds-testsp1reliabilitystability

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions