Repository navigation
Description
Summary
Cloud Run request logs show a recurring desktop-backend failure cluster where Gemini proxy calls to gemini-2.5-flash:generateContent hit 504s at roughly the 300s Cloud Run boundary, plus some 502s. This appears in both prod and dev. Users likely see stuck/failed desktop AI/chat operations when these requests time out.
No existing issue found for desktop-backend Gemini 504 / gemini-2.5-flash:generateContent timeouts. Related closed issue #7624 added UID logging for successful Gemini proxy requests, but this is specifically about timeout/failure handling.
Evidence
Sanitized observability sweep run: 2026-06-29 UTC.
Cloud Logging query shape: Cloud Run severity>=ERROR, 24h window, sanitized/bucketed by status + method + path. Request bodies, user IDs, IPs, and tokens are intentionally omitted.
Prod: project based-hardware, service desktop-backend
| Status | Endpoint | Sampled count |
|---|---|---|
| 504 | POST /v1/proxy/gemini/models/gemini-2.5-flash:generateContent |
102 |
| 502 | POST /v1/proxy/gemini/models/gemini-2.5-flash:generateContent |
13 |
Representative sanitized shape:
- latency around
300.0sfor many 504s - request sizes observed in the hundreds of KB in the Cloud Run metadata
- response size small, indicating error response rather than successful model output
Dev: project based-hardware-dev, service desktop-backend
| Status | Endpoint | Sampled count |
|---|---|---|
| 504 | POST /v1/proxy/gemini/models/gemini-2.5-flash:generateContent |
192 |
| 502 | POST /v1/proxy/gemini/models/gemini-2.5-flash:generateContent |
4 |
Related product analytics
PostHog macOS, latest 24h:
| Event | Events | Users |
|---|---|---|
chat_agent_error |
124 | 49 |
chat_agent_query_completed |
406 | 59 |
chat_tool_call_completed |
2,074 | 52 |
Top chat_agent_error messages included Response stopped., AI not available: bridge failed to start, Something went wrong. Please try again., and AI service is temporarily unavailable. Please try again later. These are not proven one-to-one with the Gemini timeout bucket, but they are consistent with desktop AI reliability issues in the same window.
Suggested investigation / fix direction
- Inspect desktop-backend Gemini proxy route for timeout policy, request-size limits, retry behavior, and whether the client waits synchronously for the full model response.
- Add structured logging around upstream Gemini duration/result buckets without logging prompt/body content.
- Decide whether requests near the Cloud Run deadline should be rejected earlier with a clear retryable error, streamed, chunked, or moved to an async/job path.
- Check whether very large request payloads correlate with the 300s timeouts and whether the desktop client can trim context or cap payload size.
- Ensure desktop clients show a specific recoverable message for proxy timeout instead of a generic bridge failure.
Acceptance criteria
- 504s on
POST /v1/proxy/gemini/models/gemini-2.5-flash:generateContentdrop materially in prod and dev Cloud Run logs. - The proxy has explicit upstream timeout/error mapping and does not simply hit the Cloud Run request deadline.
- Large/slow requests are handled with a clear user-facing retry/cancel path.
- Add regression coverage for timeout/error mapping in desktop-backend, using sanitized fake payloads.
Related existing issues checked
- Desktop Rust backend: add UID logging on successful Gemini proxy requests #7624 — closed, added UID logging on successful Gemini proxy requests; does not cover timeout mitigation.
- Desktop Rust backend: BYOK keys not used for Gemini/Anthropic proxy routes, paywall doesn't exempt BYOK users #7357 — closed, BYOK/paywall routing for Gemini/Anthropic proxy routes; related proxy area, not this timeout cluster.
- desktop-backend: Stripe webhook 500s and stale URL 503s #7282 — closed, older desktop-backend Stripe/stale URL 503s; not this endpoint/status pattern.
Activity
Git-on-my-level commentedon Jun 29, 2026
Additional code pointers from the repo:
Client side:
desktop/macos/Desktop/Sources/ProactiveAssistants/Core/GeminiClient.swift:323-325builds proxy URLs asv1/proxy/gemini/models/<model>:<action>.GeminiClient.swift:424-430sends image/structured requests togenerateContentwithurlRequest.timeoutInterval = 300.GeminiClient.swift:498-504sends text requests togenerateContentwith a defaulttimeoutof300seconds.GeminiClient.swift:350-359maps non-2xx responses toGeminiClientError.apiError("HTTP <status>: <body>").Server side:
desktop/macos/Backend-Rust/src/routes/proxy.rs:77-87definesPOST /v1/proxy/gemini/*path.proxy.rs:111-116sanitizes/caps the Gemini body.proxy.rs:149-157forwards non-BYOK requests viagemini_proxy_server_key.proxy.rs:175-201handles BYOK Gemini proxying.proxy.rs:236-310sends the upstream Vertex/AI Studio request using freshreqwest::Client::new()calls with no obvious per-upstream timeout in the call path.proxy.rs:312-315maps upstream request failures to502 Bad Gateway.proxy.rs:317-339passes through upstream status/body.Why this matters for the 504 evidence: many prod/dev Cloud Run request logs were exactly at the ~300s boundary. The desktop client and Cloud Run request deadline are both effectively waiting for a full response. A likely fix is to add explicit upstream timeout/error mapping before Cloud Run kills the request, plus client UX that treats this as retryable/cancellable. Streaming (
/v1/proxy/gemini-stream/*path) may also be relevant for long-running calls.No prompt/request body content was included in the issue evidence. Please keep any new logs to sanitized fields such as model, action, payload byte size bucket, upstream provider, duration bucket, status, and timeout reason.
[codex] Fix Gemini proxy timeout handling (#8640)