Skip to content

harden(app): own capture connect/reconnect and the session generation - #14394

Closed
Git-on-my-level wants to merge 13 commits into
task/msd-core-c1-compositionfrom
task/msd-core-c1-socket-generation
Closed

Git-on-my-level wants to merge 13 commits into
task/msd-core-c1-compositionfrom
task/msd-core-c1-socket-generation

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

What changed and why

C1 step 4: one owner for the conversation socket's connect and reconnect, and the capture
session generation applied across every await the contract names. This is the step the fix
history argues for most directly — async-lifecycle is the largest defect origin at 20% of 514
mobile fixes, and its two biggest reopened clusters are work that survives a session or
identity roll (18 rows) and keep-alive overlapping an in-flight connect.

Connect and reconnect have one owner. CaptureSessionOwner.connect joins callers that
share a generation and configuration, so a keep-alive tick arriving during an in-flight open no
longer opens a second socket, and two concurrent reconnect requests coalesce. A changed
configuration closes the late socket exactly once rather than leaking it. The tests assert the
behavior, not call-site counts, and the coalescing ones run against the real provider.

The session generation uses the idiom the providers already had rather than a new one:
CaptureSessionOwner.token / isCurrent / replaceSession, which is the existing
_sessionGeneration concept named. Codec fetch, keep-alive, location upload, a queued
replaceSession, and the coordinator wake each capture the token before their await and refuse
to write state after generation N+1.

Geolocation is preserved on the explicit path. The architect's conformance review flagged
that its own socket seam omitted the geolocation the real production call includes.
openConversationSocket now passes _sessionGeolocation the way production
socket.conversation already does, and the test asserts it against the real provider rather
than with a source-string check — the review was explicit that the forwarding assertions are
static tripwires and not behavioral coverage.

Two things deliberately not done. No file was extracted out of capture_controller.dart: the
owner already lived in capture_session_owner.dart, so that is where this landed, which avoids
churning the hottest file in the app for no behavioral gain. And the default CaptureProvider()
wiring is unchanged — keeping the defaults while the explicit path grows is the agreed sequence,
and the atomic cutover across roughly 90 construction sites is a later cut.

Product invariants affected

none

How it was verified

TZ=UTC bash app/test.sh → 2114 passed. python3 scripts/check_spine_contracts.py passes with
39 pending markers remaining — foreground-service ownership, the recovery wake, and the
keep-alive timer are explicitly later cuts and are not claimed here.
make mobile-verify ARGS="fast --paths …" → 20 of 20 journeys executed and passed, which
matters because this is capture code and the journeys are the only thing that exercises it end
to end.

make preflight failed once inside test_two_sessions_get_disjoint_ports_and_instances and
passed on retry. That is a pre-existing allocation defect on main, not this branch: two
distinct session offsets derive the same TCP port. It is fixed separately by the harness lane's
port-claim PR.

No simulator, device, or production host was involved.

Tests

capture_session_owner_test.dart (keep-alive joining a pending connect) and
capture_socket_generation_test.dart (concurrent reconnect coalescing, keep-alive during an
in-flight connect, ABA codec fetch, location upload, persistence, auth refresh, coordinator
wake, and the real-provider geolocation assertion), plus the matching C1 spine contracts whose
pending markers are retired by this implementation.

Failure class (fixes)

Failure-Class: none

🤖 Generated with Claude Code

Review in cubic

Keep-alive during an in-flight connect now joins one socket attempt, and
work started under generation N cannot publish after N+1. The explicit
conversation-open path forwards session geolocation the way production
already does, without changing default CaptureProvider() wiring.

Co-authored-by: Cursor <[email protected]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Architect conformance review: conforms, with required changes

Reviewed at 3900c5162b0f69db79d177aa9cbfc69894710579. The design is accepted and the mechanism
choice is explicitly endorsed: the existing token idiom is the right one, and the findings are
missing boundaries within it, not a request for a new generation counter.

What is credited: the 13 owner/provider tests pass; real-provider geolocation reaches the
injected socket callback, so the seam gap the earlier review flagged now has a behavioral
assertion rather than a source-string one; and coalescing, autonomous keep-alive retry, ABA
codec fencing, stale location/upload suppression, and preservation of an issued persistence
write are all genuinely exercised.

Three required changes:

  1. Socket drain and publication. A completion that finishes after its generation is no
    longer current must be blocked at publication, not only refused at admission — and it must
    keep its original operation generation rather than adopting the latest.
  2. Late stop invalidation. A stop arriving after work is already in flight has to invalidate
    that work's right to publish, not merely prevent new work from starting.
  3. Stale persistence fingerprint. The persistence fingerprint can be written from a
    superseded generation; it needs the same publication-time check.

Twelve new oracle cases across this review reproduce the defects; the existing protected tests
are unchanged.

The pattern across all three is one boundary: this PR correctly fences work at admission, and
the remaining gap is fencing at publication. Worth reading alongside #14362's first required
change, which is the identical distinction in the harness — _assert_generation checks
admission, not completion. Same class, two subsystems.

🤖 Generated with Claude Code

Git-on-my-level and others added 5 commits September 18, 2026 03:55
Admission already captured generation; publication after every await now
keeps that original operation generation. Stop invalidates in-flight work
before WAL teardown, and a skipped persist cannot occupy the fingerprint.

Co-authored-by: Cursor <[email protected]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Three required changes addressed — 9eaac6f1dc

All three are the same boundary the review named, now fenced at publication rather than
only at admission:

  • A connect that finishes after its generation is no longer current keeps that original
    operation generation
    and is closed instead of returned.
  • close() joins a late open before it returns.
  • stopStreamRecording and stopStreamDeviceRecording roll the session before WAL and native
    teardown, so a late stop invalidates in-flight work's right to publish.
  • _lastPersistedFingerprint is written only after a current persist succeeds, so a skipped
    queued-old can no longer suppress the next generation.

The three new C1 spine tests are retired. app/test.sh 2124 passed; spine 0 pending;
make preflight 21/21; mobile-verify 20/20.

The builder generalized this rather than patching three sites, and it is worth recording
because #14362 has the identical hole in the harness:

final captured = token;            // pin (generation, identity, epoch) at admit
await work();
if (!isCurrent(captured)) return;  // refuse to publish; never adopt the latest

CaptureSessionOwner.prepareCurrent was already that shape for a synchronous commit; connect,
stop and fingerprint now use it after their awaits. The harness lane has since landed the same
fencing in live_session.py and credited this PR for the pattern, so the two subsystems express
the boundary identically instead of each inventing one. It is now written up as a lesson, since
async-lifecycle is 20% of 514 mobile fixes and "work survives a session or identity roll" is
its largest cluster.

🤖 Generated with Claude Code

Git-on-my-level and others added 7 commits September 18, 2026 07:43
…ket-generation

Co-authored-by: Cursor <[email protected]>

# Conflicts:
#	app/test/spine/c1_persistence_fingerprint_test.dart
#	app/test/spine/c1_socket_drain_test.dart
#	app/test/spine/c1_stop_generation_test.dart
The merge commit's dart format rewrapped c1_lifetime_review_test.dart.
Spine originals may only drop pending markers, so restore the lifetime
bytes.

Co-authored-by: Cursor <[email protected]>
pre-commit dart format rewrapped this protected original. Restore the
lifetime bytes; spine allows pending-marker removal only.

Co-authored-by: Cursor <[email protected]>
composeCaptureProvider is the seam; the provider import is leftover.

Co-authored-by: Cursor <[email protected]>
…canonical

These entered at this commit's parent merge. The merge resolution needed
OMI_SKIP_DART_FORMAT=1 so the pre-commit hook could not rewrite a digest-pinned
spine oracle (c1_lifetime_review_test.dart) — but that skip is all-or-nothing, so
it also left analytics_manager.dart and omi_double_tap_goldens_test.dart
unformatted, and they rode up the rest of the C1 chain.

Formatter only, no semantic change. origin/main formats both paths with 0
changed, so this is the merge-collateral class, not new content.

Co-Authored-By: Claude Opus 5 <[email protected]>
@Git-on-my-level
Git-on-my-level deleted the branch task/msd-core-c1-composition September 18, 2026 10:47
@github-actions

Copy link
Copy Markdown
Contributor

Hey @Git-on-my-level 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

@Git-on-my-level

Copy link
Copy Markdown
Member Author

Auto-closed when base branch was deleted after its parent squash-merged. Head unchanged at b26c1176c; continued as #14550 targeting main.

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