Skip to content

harden(app): fence retired websocket connection attempts - #14843

Merged
Git-on-my-level merged 1 commit into
mainfrom
codex/mobile-battery-lifecycle-20260919
Sep 19, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
codex/mobile-battery-lifecycle-20260919

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 19, 2026 •

Copy link
Copy Markdown
Member

Problem

PureSocket.connect() could be retired while asynchronous auth or WebSocket readiness was still pending. A later callback could then install or publish a stale channel, concurrent callers could open duplicate handshakes, and a connecting channel was not always closed on teardown. Those paths retain socket work after capture stops and can duplicate the heartbeat/recovery work that the mobile battery investigation is tracking.

Change

  • Reserve a connection generation before awaiting auth and fence every later callback to that generation.
  • Subscribe once per channel, retain the subscription, and retire/cancel it together with the channel.
  • Close connecting channels on stop, handshake failure, stream close, and stream error; keep the existing 20-second ping and 15-second connect timeout unchanged.
  • Add loopback lifecycle tests for teardown during auth/handshake, concurrent connects, stale callbacks, failed-handshake retry, synchronous stop, audio delivery, remote close, and reconnect recovery.

Verification

  • Focused transport tests: 12 passed (pure_socket_lifecycle_test.dart and pure_socket_auth_test.dart).
  • Full app suite: 2,357 passed.
  • Spine suite: 138 passed.
  • dart analyze lib/services/sockets/pure_socket.dart test/unit/pure_socket_lifecycle_test.dart: passed.
  • bash scripts/analyze_ratchet.sh: passed.
  • git diff --check: passed.
  • A regression comparison recorded against the pre-fix source reproduced 7 focused lifecycle failures; the fixed source passes all 12 focused tests.

Scope and limits

This changes transport lifecycle ownership only; reconnect and ping cadence are unchanged. The physical-device battery baseline remains unmeasured on this machine, so the PR claims reduced stale background work and preserved capture/recovery behavior rather than a phone battery percentage. Follow-up measurement should use a physical iPhone with fixed app/OS/firmware versions and repeated disconnected-idle, connected-muted, live-speech, connected-silence, offline-catch-up, and weak-network runs while recording Instruments Energy Log, network activity, process wakeups, and Omi lifecycle counters.

Relates to #5491, #11307, and #5221. #14688 is intentionally outside this change.

@Git-on-my-level
Git-on-my-level merged commit d60ddd7 into main Sep 19, 2026
47 of 48 checks passed
@Git-on-my-level
Git-on-my-level deleted the codex/mobile-battery-lifecycle-20260919 branch September 19, 2026 11:26
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