Skip to content

fix(app): stamp and confirm every conversation's pendant backup on one socket (#20365) - #24846

Closed
cocvn157 wants to merge 2 commits into
BasedHardware:mainfrom
cocvn157:fix/pendant-later-conversations-wal-stamp-20365
Closed

cocvn157 wants to merge 2 commits into
BasedHardware:mainfrom
cocvn157:fix/pendant-later-conversations-wal-stamp-20365

Conversation

@cocvn157

@cocvn157 cocvn157 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #20365
/claim #20365

Problem

When a pendant connection remains open across multiple conversations, _sessionStartSeconds was initialized only when the transcription socket opened and cleared by _resetStateVariables() when the server started processing the first conversation. For every subsequent conversation on the same socket, _sessionStartSeconds remained 0:

  1. _finalizeAndStampSession() and forceProcessingCurrentConversation() skipped stamping conversationId onto the session WALs.
  2. ConversationEvent confirmation skipped judging WAL coverage for later conversations.
  3. Single-slot pending close fields (_pendingAutoSyncSessionStart, _pendingAutoSyncConversationId, _pendingAutoSyncNeedsRepair) were overwritten if a later conversation closed before an earlier conversation's ConversationEvent arrived.
  4. Because unstamped WALs from earlier and later conversations share the same recordingSessionId, an unfenced or out-of-order stamp could attach WALs created after a close to the closing conversation.

Solution

  • Re-arm the conversation backup window (_startNextConversationWindow): When a conversation closes (ConversationProcessingStartedEvent or forceProcessingCurrentConversation) and capture continues on the open socket (_captureOutlivesClose), start the next conversation window at the close timestamp and increment _nextConversationWindows so activeCaptureSessionId stays unique even for same-second closes. Retain the recording's geolocation snapshot while capture continues.
  • Fence each stamp by WAL identity at close (walsNow() / walsAtClose): Capture an identity Set<Wal> snapshot right after finalizeCurrentSession() drains the closing conversation's tail (_drainClosingConversation()), and restrict stampConversationId to WALs present in walsAtClose so chunks created after the close stay with the next conversation.
  • Chain stamps in close order (_pendingFinalizeAndStamp): Chain each close's stamp (after: _pendingFinalizeAndStamp) across both server-driven closes and Process Now closes, and keep _pendingFinalizeAndStamp intact across confirmation/sync awaits so waiters never skip an in-flight stamp.
  • Per-conversation pending close map (_pendingCloses): Track sessionStart, needsRepair, and the 30-second fallback timer per conversationId so out-of-order ConversationEvent deliveries only complete their own close.
  • Tests: Add app/test/unit/wal_stamp_fence_test.dart and app/test/services/capture/capture_next_conversation_window_test.dart covering multi-conversation socket sessions, muted/interrupted closes, Process Now interleavings, late ConversationEvent deliveries, back-to-back closes, and WAL identity fencing.

Product invariants affected

  • INV-CAP-1

Line-Count-Exception: app/lib/services/capture/capture_controller.dart | 4855 -> 4938 | per-conversation close map, close-ordered stamp chain, and next-window re-arming for #20365
Line-Count-Exception: app/lib/services/wals/local_wal_sync.dart | 2707 -> 2728 | WAL identity fence and serialized finalize snapshot at close for #20365
UI-Evidence: none -- background capture and WAL stamping/confirmation service logic with no UI change
Failure-Class: none

@cocvn157
cocvn157 requested a review from mdmohsin7 as a code owner November 7, 2026 08:03

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 6 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread app/test/unit/wal_stamp_fence_test.dart Resolved
@Git-on-my-level

Copy link
Copy Markdown
Member

The design here is right, and the head commit resolves the earlier fence-snapshot race — leaving for maintainer sign-off because no CI has run on this head and this is data-persistence logic in the core capture pipeline.

What I verified:

  • app/lib/services/capture/capture_controller.dart — re-arming _sessionStartSeconds at each close (_startNextConversationWindow) with the _nextConversationWindows counter directly fixes the reported root cause (the window only started when a socket opened). activeCaptureSessionId changes format from live- to live-- after the first close; I checked its consumers (capture_provider.dart:56, live_transcript_view.dart:111, semantic_controls.dart, capture_speaker_assignment.dart) and all use it as an opaque identity key, so the extension is safe and actually fixes a latent collision for same-second windows. The _pendingCloses map keyed by conversation id correctly replaces the single-slot pending fields that earlier code overwrote when a later conversation closed before an earlier ConversationEvent arrived. Stamp chaining through the never-cleared _pendingFinalizeAndStamp guarantees close-order stamping; one nit — the chain accumulates one completed-future link per close for the life of the recording session (bytes each, fine in practice, just noting it is unbounded within a session).
  • app/lib/services/wals/local_wal_sync.dart — the important part of 9b2545e: finalizeAndSnapshotSession takes the walsNow() snapshot inside the serialized _enqueueBuffer closure, after _frames is drained into the tail WAL and before await _flush. That is the correct fence placement; the earlier review's P1 (snapshot read outside the drain could miss the tail or include post-close WALs) is resolved — verified in the diff. Set.identity() is the right tool because Wal.id is device_timerStart (two tails in one second share an id) and Wal defines no operator==. The fence is null-opt-out in prepareConversationStamp, so existing callers keep the old reach (covered by the third test in wal_stamp_fence_test.dart).
  • app/test/unit/wal_stamp_fence_test.dart — good unit isolation of the fence: backdated WALs, same-id tails, fence-only-once, and the sub-second tail case that time-based fencing cannot handle.
  • app/test/services/capture/capture_next_conversation_window_test.dart — 12 scenario tests driving the real controller and WAL sync: three conversations on one socket, muted close, Process-now interactions, late ConversationEvent, back-to-back closes, same-second windows, and phone-mic interrupt/resume. This is the right shape of coverage for the bug class.
  • app/test/support/capture/capture_replay_world.dart — additive, gated test-support extensions (processResponse, locationFix); no production behavior.
  • app/changelog/unreleased/20261002-pendant-later-conversations-not-reuploaded.json — present and accurately describes the user-visible fix.

Performance: removes the redundant re-upload (and server re-transcription) of already-transcribed audio — this is a cost reduction, not an added cost. Security: no new data leaves the device and no new surfaces; blast radius if the fence were wrong is audio misattributed between adjacent conversations on one socket, which is why CI plus an owner's look matters.

USER IMPACT: During long pendant sessions, conversations after the first stop appearing twice, and their audio is no longer uploaded a second time.

What I would still want before merge: (1) CI — this head has zero check runs, so none of the new tests have executed in CI (workflows may be awaiting first-time-contributor approval); a green app-test run on 9b2545e is required, and (2) a sign-off from whoever owns the capture/WAL pipeline on the identity-fence approach.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added needs-maintainer-review Needs a human maintainer to sign off before merge flutter flutter work labels Nov 7, 2026
@cocvn157 cocvn157 closed this Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Hey @cocvn157 👋

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!

aryanorastar added a commit that referenced this pull request Nov 22, 2026
…#26035)

Fixes #20365.

After the first conversation closes on a continuing pendant socket,
capture currently clears its WAL window and never rearms it. Later saved
conversations leave their backups unlinked and eligible for duplicate
upload. A single pending-close slot also loses earlier evidence when
results arrive out of order.

This change rotates a distinct conversation window without reconnecting,
seals an exclusive WAL cut before any queued I/O, and retains per-close
transcript/interruption/socket-mode evidence. Saved transcript coverage
and existing committed-receipt rules still control retention. Partial,
interrupted, held and uncertain audio remains recoverable, and upload
preferences remain authoritative. Process Now reserves its own cut and
resolves overlapping server events against every relevant outstanding
response ID; ambiguous audio is never guessed into another conversation.
Account retirement fences the writes and cancels pending timers. A
failed disk snapshot still waits for its predecessor, so errors cannot
detach the ordered tail.

The close lifecycle is isolated in a small capture part, and exact WAL
cut ownership lives beside the ledger. Existing lifecycle/checkpoint
finalization remains separate. Architecture, custody documentation and
the implementation checklist are updated.

Credit: this builds on Ashwin's #20380 and cocvn157's #24846
rollover/snapshot work, adapted to current custody and typed Process Now
contracts.

Validation:
- Original main controller fails the new three-conversation replay: c2
backups remain unlinked.
- 16 new production-controller/ledger/disk/recovery replays cover
sequential closes, reverse confirmations, partial coverage, duplicate
events, queued disk barriers, delayed/failed and overlapping Process
Now, account retirement, stop/dispose, restart and both Custom STT
raw-audio settings.
- 10 new snapshot ownership tests and 40 existing WAL regressions
passed. The failed-middle-drain regression fails with the predecessor
wait removed and passes with it restored.
Caption-store/provider/coalescing consumers pass 115 tests using the
authoritative window key.
- All 31 hermetic mobile journeys passed (0 failed/skipped); analyzer
ratchet, generated-output checks and all 27 preflight checks passed
locally.
- Full Flutter and Android CI on the final immutable head remain merge
gates (see Checks). An initial broad local run overlapped final edits
and is not claimed as frozen-head evidence.
- Replay substitutes socket/native/device boundaries; no physical
pendant, live provider, production recordings or store release is
claimed.

INV-CAP-1: Every admitted frame stays in the owner-scoped ledger; exact
sealed cuts establish lineage only. Unconfirmed or partial audio stays
readable/recoverable and existing policy alone releases confirmed copies
into synced retention.

Failure-Class: none
The existing buffer-clear-after-async-flush and cross-device
duplicate-capture classes have different failure mechanisms/prevention:
this defect is a missing conversation-window rollover plus overwritten
close evidence, resolved with per-close snapshots rather than content
dedupe or cleanup policy changes.

UI-Evidence: none -- capture and ledger behavior only; no Flutter view
or user-facing layout changed.

Line-Count-Exception: app/lib/services/wals/local_wal_sync.dart | 3155
-> 3196 | Keep admission sealing beside the existing frame buffer and
extension paths; token handling is extracted into
conversation_wal_snapshot.dart and the capture controller shrinks.
Git-on-my-level pushed a commit to Git-on-my-level/omi that referenced this pull request Nov 22, 2026
…rdware#20365)

Rotate conversation windows on continuing sockets and retain per-close evidence. Reserve exact WAL identities before queued persistence; keep uncertain Process Now audio recoverable and fence account changes.

Based on prior work in BasedHardware#20380 and BasedHardware#24846.

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

Co-authored-by: cocvn157 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flutter flutter work needs-maintainer-review Needs a human maintainer to sign off before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flutter transcription: later conversations on one pendant connection never get their backup tagged, so they are re-uploaded as duplicates

2 participants