Skip to content

Fix realtime token mint failure diagnostics - #9102

Merged
Git-on-my-level merged 2 commits into
mainfrom
codex/fix-realtime-token-mint-9080
Jul 6, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
codex/fix-realtime-token-mint-9080

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Summary

Fixes #9080 by preserving safe, actionable realtime token-mint failure reasons from the desktop Rust backend through the macOS health event.

Root cause:

  • The 2026-07-05 telemetry spike came from managed realtime token minting, not expected idle websocket teardown.
  • A recent main change already fixed one concrete Gemini mint cause: the Gemini CreateAuthTokenRequest body now wraps settings under authToken, matching Google Live API docs.
  • The remaining problem was observability and recovery classification: non-2xx OpenAI/Gemini mint responses were mostly reduced client-side to unknown / generic transient failures, often without provider route, provider status, or retryability, so the July 5 failures could not be separated into provider auth/quota/outage/rejected-request/config cases.

What changed:

  • Rust /v2/realtime/session now returns structured safe mint error JSON: reason, backend_route, provider, provider code, upstream_status_code when available, and retryable.
  • macOS APIClient.mintRealtimeToken preserves those fields via RealtimeTokenMintError instead of erasing them in a generic catch.
  • RealtimeHubController records structured mint diagnostics for warm and barge-in token mint phases while preserving existing failover/fallback behavior.
  • DesktopDiagnosticsManager includes the new safe fields in realtime_token_mint_failed health snapshots.
  • Added focused Rust and Swift tests plus a desktop changelog fragment.

Verification

  • cargo fmt
  • cargo test routes::realtime
  • xcrun swift test -c debug --package-path Desktop --filter 'APIClientRoutingTests/testRealtimeMintStructuredFailurePreservesDiagnostics'
  • xcrun swift test -c debug --package-path Desktop --filter 'DesktopDiagnosticsManagerTests/testTokenMintFailureIncludesHttpStatusWhenKnown'
  • Pre-push fast checks passed, including desktop Swift build and desktop Rust check.

Note: a broader filtered Swift run of APIClientRoutingTests|DesktopDiagnosticsManagerTests exposed an unrelated existing failure in APIClientRoutingTests.testDeleteConversationRoutesToPython: the test expects ?cascade=true, while current deleteConversation sends /v1/conversations/conv-456. The new realtime mint test and diagnostics test both pass individually.

Review in cubic

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b2ab40748d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

statusCode: httpResponse.statusCode,
payload: payload,
provider: provider)
throw RealtimeTokenMintError(statusCode: httpResponse.statusCode, healthError: healthError, payload: payload)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve mint errors across auth retry

When the first mint attempt returns 401, the auth-refresh path recursively calls performRealtimeMintRequest; if that retry then gets any structured mint failure, this newly thrown RealtimeTokenMintError is not caught by the retry wrapper and falls into the generic catch, which rethrows CredentialHealthError.backendTransient. That discards payload.reason, backendRoute, upstreamStatusCode, and retryability, so common expired-auth-then-provider-failure cases still lose the diagnostics this change is trying to preserve.

Useful? React with 👍 / 👎.

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

5 issues found across 8 files

Confidence score: 3/5

  • In desktop/macos/Desktop/Sources/APIClient.swift, the 401 refresh-retry error path can drop RealtimeTokenMintError details when the retried call fails, so non-2xx mint failures lose structured diagnostics and become harder to classify/support — preserve and rethrow the structured mint error in the retry catch before merging.
  • In desktop/macos/Backend-Rust/src/routes/realtime.rs, Gemini error parsing prefers numeric error.code and then loses it via as_str() without falling back to error.status, which can strip provider-specific failure codes and blur quota/auth handling — parse string/numeric forms safely and fall back to error.status when needed.
  • Across desktop/macos/Desktop/Sources/FloatingControlBar/RealtimeHubController.swift and desktop/macos/Backend-Rust/src/routes/realtime.rs, provider metadata is still omitted in some structured responses (provider_code/code, and MissingKey(p) provider name), so incidents remain less actionable even though payload fields exist — include these fields in emitted JSON/UI logging to complete end-to-end diagnostics.
  • desktop/macos/Desktop/Sources/APIClient.swift currently exposes only message text in RealtimeTokenMintError.errorDescription, omitting status/reason; merged as-is, logs and surfaced errors may hide key context during outages — include HTTP status and structured reason in the description formatting.

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@Git-on-my-level

Copy link
Copy Markdown
Member Author

Addressed the review comments in f581aa9:\n\n- Preserve RealtimeTokenMintError across the 401 refresh retry path so structured mint failures are not flattened.\n- Include provider_code in desktop diagnostics and pass it from realtime mint failures.\n- Include provider on missing-key backend errors.\n- Prefer string provider status/code values over numeric HTTP-ish codes when parsing upstream error bodies, preserving values like RESOURCE_EXHAUSTED.\n- Add status/reason/code to RealtimeTokenMintError.errorDescription for clearer logs.\n\nValidation rerun locally:\n- cd desktop/macos/Backend-Rust && cargo fmt && cargo test routes::realtime\n- xcrun swift test -c debug --package-path desktop/macos/Desktop --filter 'APIClientRoutingTests/testRealtimeMintStructuredFailurePreservesDiagnostics'\n- xcrun swift test -c debug --package-path desktop/macos/Desktop --filter 'DesktopDiagnosticsManagerTests/testTokenMintFailureIncludesHttpStatusWhenKnown'\n- git diff --check\n- pre-push fast checks passed during push

@Git-on-my-level
Git-on-my-level merged commit 7bf057b into main Jul 6, 2026
3 checks passed
@Git-on-my-level
Git-on-my-level deleted the codex/fix-realtime-token-mint-9080 branch July 6, 2026 02:01
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.

macOS realtime token mint failures affect hundreds of 0.12.0 users across Gemini and OpenAI

1 participant