Skip to content

SCA-5262: Pace live listen retries and preserve sockets - #26585

Merged
Git-on-my-level merged 5 commits into
BasedHardware:mainfrom
Git-on-my-level:agent/m1-studio-codex-luna/581dcacf572d
Nov 28, 2026
Merged

Git-on-my-level merged 5 commits into
BasedHardware:mainfrom
Git-on-my-level:agent/m1-studio-codex-luna/581dcacf572d

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

What changed and why

Fix SCA-5262 by keeping healthy /v4/listen sockets 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 text ping heartbeat.

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

  • Reproduced the C1 keepalive/reconnect timer failure on M1 at the previous PR head; the original C1 test failed with one socket open instead of two.
  • cd app && flutter test --no-pub test/spine/c1_composition_test.dart — 4 tests passed on repaired source committed as f0baa0f6947e494f07f99a1a004cc852c49dc4aa, 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 on d5eeef05ba; the retry regression now asserts the one-second retry timer directly. The previous count assertion failed on both f0baa0f and 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 on d5eeef05ba.
  • 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-pub on the three production capture files, formatting, git diff --check, and python3 -m unittest test_perf_gate.RunnerTests.test_stale_evidence_cannot_launch_flutter passed. That negative-path unit test deliberately prints PERF_SCORECARD_DIR must contain no previous scorecards; use a fresh directory while rejecting stale evidence; it is not a perf-runner failure and is separate from the socket retry issue.
  • The panel returned REVIEW: FIX-FIRST on d5eeef05ba with 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 in 572de0f835.
  • Dart Analyze & Tests passed on Mobile App Checks run 46144912507 on exact head 572de0f83514fbde83769d2ba423e8eb577b2513 (analyzer, Flutter tests, and non-UTC checks all succeeded).
  • Mobile Release Eligibility passed on the same workflow run and exact head.
  • The panel runner recovered review-20261128t123934-bc8b on a clean checkout pinned to this SHA; saved review materials matched, and the independent verdict is REVIEW: 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 on 572de0f835, 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 on 572de0f835.
  • The 1002 close cause, fixed-build iPhone run, production LB comparison, and app 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

View guided diff

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T12:40:36.454431Z 572de0f New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

Comment on lines +99 to +101
if (_liveRecovery.kickTimer?.isActive ?? false) {
return;
}

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 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 👍 / 👎.

Comment on lines +115 to +118
if (previous != null && identical(previous.value, result)) {
_published = _PublishedConnect(result, (dynamic value) => close(value as T));
if (!completer.isCompleted) completer.complete(result);
return;

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 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 👍 / 👎.

@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: 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 &&

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 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 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit fbdb559 into BasedHardware:main Nov 28, 2026
52 checks passed
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.

1 participant