Skip to content

perf(mobile): share connectivity observation across environments - #25492

Open
saphid wants to merge 1 commit into
pingdotgg:mainfrom
saphid:perf/mobile-shared-connectivity-20261027
Open

saphid wants to merge 1 commit into
pingdotgg:mainfrom
saphid:perf/mobile-shared-connectivity-20261027

Conversation

@saphid

@saphid saphid commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Problem

Each mobile environment independently acquires connectivity and network-path observation. With several environments, the same native event fans out through duplicate registrations and repeats network-state reads on resume.

Change

Share live connectivity and account/path changes within the mobile runtime, with reference-counted acquisition, no replay and no idle grace. Keep status reads fresh and application resume timing local to each subscriber, so a newly opened connection retains its own probe/reconnect decision. Final release removes observation; later readers acquire it again.

Scope and approval

This is a focused reduction of duplicate work in the existing mobile connection adapter. It adds no setting, protocol or retry policy. Audit tracker: #189.

Verification

  • CI=true vp run check:changed f0dd86f16482595c6cfffe0ac64dc12bffb634f9: passed, including affected typecheck and all ten focused tests.
  • A separate GPT-6.1 Sol/high review session inspected the full contribution, found no actionable issues and independently passed all ten tests. Coverage includes late readers, short/long resumes, credential fan-out, delayed seeds, final release/reacquisition, old callbacks, native read failures, synchronous native registration events and slow consumers.
  • A count harness executes the exact baseline/candidate stream and layer bodies with real Effect service layers and mocked Expo/AppState boundaries. For ten supervisor-shaped readers plus one registry-shaped connectivity reader:
JavaScript operation Baseline Candidate
Network listener registrations 21 2
AppState listener registrations 21 11
Initial path-state reads 10 1
Network-state reads per active resume 11 1

The same harness also checks one and three supervisor-shaped readers. Every current reader receives the expected short-resume and path-change events, and final scope release leaves zero registrations. Fresh startup status reads are excluded from this count. These are JS API calls and registrations, not independent OS monitors or physical battery measurements.

A separate probe runs the actual EnvironmentSupervisor.make with a healthy mocked transport. A connection opened one second before resume stays open and receives a health probe on both baseline and candidate:

baseline: 1 connection, 0 releases, 1 probe
candidate: 1 connection, 0 releases, 1 probe

Native APIs and transport are mocked; device, full-registry and physical-energy behavior were not measured. No visible UI change is intended. Independent review ran against the preceding base; the only intervening upstream change is a web callback fix, and the full contribution bytes remain unchanged.

The separate Android lifecycle work in #24783 remains unmerged. When combining it, its fresh suspension read and per-subscriber initial reconciliation must remain local alongside application resume classification, outside the no-replay share. This PR does not establish combined-stack correctness.

Implemented and independently reviewed in separate GPT-6.1 Sol/high sessions through Codex in T3 Code.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Oct 26, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs Human Approval

Macroscope's review found this PR requires human approval — This PR changes the production mobile connection adapter to share connectivity and wakeup observation across environment supervisors, altering native listener lifetimes, event fan-out, and resume handling. Although the extensive tests cover the intended lifecycle cases, the cross-environment runtime semantics are substantial enough for human review.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between f0dd86f and b618499.

Files selected for processing: 2
  • apps/mobile/src/connection/platform.test.ts
  • apps/mobile/src/connection/platform.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

Walkthrough

The mobile platform now shares connectivity and wakeup observations across readers. Application-active wakeups are acquired per connection, preserving per-reader resume classification. New tests cover stream sharing, event ordering, cleanup, read failures, and resume behavior.

Changes: Mobile connection observations

Layer / File(s) Summary
Shared connectivity and wakeup streams
apps/mobile/src/connection/platform.ts, apps/mobile/src/connection/platform.test.ts
The platform provides shared connectivity and wakeup streams with unbounded buffering and no replay. Tests cover shared native acquisition, late readers, event ordering, cleanup and reacquisition, read failures, and reader delivery.
Per-connection resume classification
apps/mobile/src/connection/platform.ts, apps/mobile/src/connection/platform.test.ts
Application-active wakeups are acquired per connection and merged with shared wakeup changes. Tests cover short and long resumes and readers joining while the app is backgrounded or inactive.

Priority: Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Possibly related issues

  • pingdotgg/t3code issue 24796 — The change shares native listeners and status reads, which relates to the issue’s concern about unnecessary Android client work. The change does not establish an effect on battery use.

Possibly related PRs

  • pingdotgg/t3code#24783 — Both PRs change mobile connection lifecycle wakeups and use AppState behavior.
  • pingdotgg/t3code#19426 — Both PRs change application-active wakeup behavior and rely on wakeup classification.

Suggested labels: size:M

Suggested reviewers: macroscopeapp

Merge Risk: Minimal · up to b6184

The shared observations are wired into the mobile runtime, with no identified issue that needs resolution before merging.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title is concise, conventional, and accurately identifies the main change: sharing mobile connectivity observation across environments.
Description check Passed The description includes all required sections and clearly explains the problem, implementation, scope, verification results, measured impact, limitations, and related work. It links issue #189 and ex…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description includes all required sections and clearly explains the problem, implementation, scope, verification results, measured impact, limitations, and related work. It links issue #189 and explains the focused scope, although it does not include an explicit maintainer approval comment.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant