Repository navigation
SCA-5262: Pace live listen retries and preserve sockets - #26585
Git-on-my-level merged 5 commits into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 25644b2908
ℹ️ 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".
| if (_liveRecovery.kickTimer?.isActive ?? false) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
Scope retry coalescing to the current capture session
If capture is stopped/restarted or its device/source is replaced while an 80/160-second retry is pending, _rollCaptureSession changes the owner token without cancelling this timer. This unconditional coalescing guard then ignores recovery signals for the new session, and the periodic keepalive also skips every tick while the stale timer is active. When the timer finally fires, _runKickedReconnect rejects its captured token without reconnecting, so the defunct session can suppress the new capture's recovery for minutes. Coalesce only retries belonging to the current token, or cancel/rebind them when the session retires while retaining the authorization cooldown, consistent with the C1 ownership contract referenced in app/AGENTS.md.
AGENTS.md reference: app/AGENTS.md:L111-L111
Useful? React with 👍 / 👎.
| if (previous != null && identical(previous.value, result)) { | ||
| _published = _PublishedConnect(result, (dynamic value) => close(value as T)); | ||
| if (!completer.isCompleted) completer.complete(result); | ||
| return; |
There was a problem hiding this comment.
Restore controller readiness when reusing a published socket
After a settings-forced reconnect, the old socket's queued SocketClosed can clear _transcriptServiceReady after the replacement is published. The next keepalive gets that same connected replacement from SocketServicePool; this new fast path preserves it, but CaptureController._publishTranscriptionSocket only restores readiness inside its !identical(_socket, socket) block, and reuse emits no new onConnected. Readiness therefore remains false while the transport is healthy, leaving the capture marked as reconnecting and repeatedly running recovery. Restore readiness on successful same-instance publication and cover this through the composed provider rather than only the owner unit test, following the C1 testing guidance in app/AGENTS.md.
AGENTS.md reference: app/AGENTS.md:L111-L111
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 572de0f835
ℹ️ 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".
| if (!force && | ||
| _socket?.codec == codec && | ||
| _socket?.sampleRate == sampleRate && | ||
| _socket?.language == language && |
There was a problem hiding this comment.
Compare against the resolved Custom STT language
When a Custom STT provider's effective language differs from the app's primary language—for example, a provider override uses en while primary is multi—this new reuse check can never pass. Capture supplies the primary language, but TranscriptSocketServiceFactory.createFromCustomConfig() stores config.effectiveLanguage on the returned service (transcription_service.dart:679–694). Consequently, an unchanged, non-forced request stops and recreates the healthy custom-STT connection instead of reusing it, interrupting transcription unnecessarily. Compare against customConfig?.effectiveLanguage ?? language, or rely on the custom language already included in sttConfigId.
Useful? React with 👍 / 👎.
What changed and why
Fix SCA-5262 by keeping healthy
/v4/listensockets alive across geolocation refreshes and pacing reconnects after failures. Retries are single-flight and share a 20-second floor with the periodic fallback; the app no longer sends a binary data frame in response to the textpingheartbeat.Product invariants affected
INV-CAP-1 — pendant audio remains retained through the existing WAL/ring fallback while the live socket recovers.
How it was verified
cd app && flutter test --no-pub test/spine/c1_composition_test.dart— 4 tests passed on repaired source committed asf0baa0f6947e494f07f99a1a004cc852c49dc4aa, including the C1 keepalive/reconnect case.cd app && flutter test --no-pub test/services/capture/capture_live_recovery_test.dart— 19 tests passed.cd app && flutter test --no-pub test/services/capture/capture_session_owner_test.dart— 5 tests passed.cd app && flutter test --no-pub test/providers/capture_provider_test.dart— 103 tests passed ond5eeef05ba; the retry regression now asserts the one-second retry timer directly. The previous count assertion failed on bothf0baa0fand its parent because it counted the keepalive and continuity timers with the retry.cd app && flutter test --no-pub test/spine/c1_socket_drain_test.dart test/services/capture/capture_live_recovery_test.dart test/services/capture/capture_session_owner_test.dart test/services/capture/capture_socket_generation_test.dart— 50 tests passed ond5eeef05ba.cd app && flutter analyze --no-pub lib/services/capture/capture_controller.dart lib/services/capture/capture_coordinator.dart lib/services/capture/capture_live_recovery.dart— no issues found.flutter analyze --no-pubon the three production capture files, formatting,git diff --check, andpython3 -m unittest test_perf_gate.RunnerTests.test_stale_evidence_cannot_launch_flutterpassed. That negative-path unit test deliberately printsPERF_SCORECARD_DIR must contain no previous scorecards; use a fresh directorywhile rejecting stale evidence; it is not a perf-runner failure and is separate from the socket retry issue.REVIEW: FIX-FIRSTond5eeef05bawith F1 (initial phone-mic handshake failure can strand live capture without a retry) and F2 (connectivity/resume cannot shorten a pending long backoff). Both findings are addressed in572de0f835.572de0f83514fbde83769d2ba423e8eb577b2513(analyzer, Flutter tests, and non-UTC checks all succeeded).review-20261128t123934-bc8bon a clean checkout pinned to this SHA; saved review materials matched, and the independent verdict isREVIEW: SHIP 572de0f83514fbde83769d2ba423e8eb577b2513. F1 is minor and F2 is a test nit; neither is FIX-FIRST.cd app && flutter test --reporter compact test/services/capture/capture_live_recovery_test.dart test/services/capture/capture_one_source_test.dart test/services/capture/capture_session_owner_test.dart test/services/capture/capture_socket_generation_test.dart— 69 tests passed on572de0f835, including new initial phone-mic retry and connectivity/handover/resume backoff regressions.cd app && flutter analyze lib/services/capture/capture_controller.dart lib/services/capture/capture_live_recovery.dart— no issues found on572de0f835.SERVING:line remain unverified and are follow-up release acceptance.Tests
Regression tests cover retry coalescing/backoff, same-instance socket ownership, and ignoring application text heartbeats without sending fake binary data.
UI evidence
UI-Evidence: none -- no UI changes.
Failure-class transition narrative
The violated contract is that app retry sources could independently reconnect
/v4/listen, producing a handshake rate above the server's per-authorization budget while healthy sockets were also replaced on geolocation refresh. The canonical guard is one single-flight recovery coordinator with coalesced signals, shared cooldown/backoff, stable healthy-socket reuse, and no synthetic data frame for application heartbeats. The regression evidence is the capture recovery, session owner, socket lifecycle, and replay test coverage in this PR.Failure-Class: new
Line-Count-Exception: app/lib/services/capture/capture_controller.dart | 5149 -> 5234 | tags socket lifecycle callbacks and starts recovery at transport close and phone capture activation to prevent the reproduced C1 timer race
Line-Count-Exception: app/lib/services/capture/capture_coordinator.dart | 3261 -> 3266 | carries socket callback generations through serialized lifecycle events so stale callbacks cannot affect the active capture