Repository navigation
fix(conversations-v3): keep a stretch open for the capture after a reconnect - #26749
Merged
Merged
Conversation
…connect A socket reconnect mid-speech seals the current batch recording and opens the next one on the same device at once. The next recording has no transcript until it seals, so the builder read it as silence, locked the first card at the five-minute rule, and the rest of the conversation became a second card when it landed. _mark_successor_pending held a stretch only behind a rotation-stamped seal (rotation is off in prod). Under CONVERSATIONS_V3_CAPTURE_CONTINUITY it now also holds when the seal came within 90 s of the last line (a quiet seal comes at least 120 s after the last speech) and the next batch capture from the same client_device_id opened within 90 s of that line and is still in flight: capturing for at most 15 minutes after it opened, or sealed without its projection receipt for at most 15 minutes. A batch capture that closed before its transcript landed now counts as awaiting for rotation successors too. Quiet seals skip the successor read, so normal conversation ends keep their latency and read cost. Failure-Class: FC-live-settlement-uses-capture-clock
…s devices, bound by server stamps Round 2 of the reconnect hold, from the independent review of dfc50c5: - Every loaded recording whose server seal cut live speech is a predecessor, not only the latest one, and the hold keeps the last stretch holding it open whichever device spoke last (outline.SUCCESSOR_HOLD). The successor read covers a time window of at most 32 metadata documents, so cards and other devices' rows cannot hide it. - policy.successor_hold_until uses absolute deadlines on server stamps: 15 minutes from created_at while capturing, and a close inside that window waits 15 minutes (5 after a Finish on it), never past both. A late close, reseal or retry cannot restart an expired hold. Failure receipts come first; future stamps never hold. - The seal clock is record_sealed_at, else home_transcription_pending_at, never finished_at, with two-sided skew; a quiet seal reads nothing. - Release needs the whole capture: proven silence, or every unit of the latest seal projected (capture_end.seal_proof, one ledger read while partly projected). A first projected unit proves nothing. - Adds the reconnect_successor_lands_late pipeline lab scenario and moves the tests to test_conversations_v3_successor_hold.py. Failure-Class: FC-live-settlement-uses-capture-clock
… and a durable landed proof Round 3 of the reconnect hold, from the independent review of 5a03416: - A Finish bounds the hold to 5 minutes after its trusted request (v3_finish_requested.at); the ordinary wait runs from a stable first close (record_admitted_at, home_transcription_pending_at or record_sealed_at, whichever came first), so a moved seal cannot extend it. The first successor the user ended fences off every later capture. - Each live seal gets its own started_at window lookup, most recent first, read in pages of 16 with at most 64 documents per pass; the rotation lookup is main's query again. Unrelated rows cannot hide a successor or starve another cut's lookup. - Batch projection stamps record_units_landed_seal_at, the seal whose every unit landed, in the transaction that commits the sibling completion. The hold releases on that proof or on proven silence; the ledger's best-effort transcribed is only a fallback, read once per successor per pass with a 3 s timeout. An absent ledger or a unit held for recovery no longer counts as complete. - The pipeline lab's transcript stand-in stamps the same proof. Failure-Class: FC-live-settlement-uses-capture-clock
…essor's Finish fence Round 4 of the reconnect hold, from the independent review of d5c20e5: - Rotation keeps main's lookup and hold: a successor still capturing within the cap, or processing within 15 minutes of finished_at, marks a page continuation exactly as main does (policy.awaiting_transcript is back). Only where main lets go does a successor that closed inside the cap window wait on trusted stamps. A same-device batch successor still in finalization past the cap, with no close stamp, holds again. - On the reconnect path a discarded successor that kept its stored Finish still fences off later captures without holding the source; any other discarded successor never holds. Failure-Class: FC-live-settlement-uses-capture-clock
Round 5 of the reconnect hold, from the independent review of 17a21f9: - The rotation scan no longer calls policy.successor_hold_until. Its loop is main's, line for line, except that it stops at the silence gap with break so the reconnect lookup still runs. After a rotation, a capture from another device that closed into the server-batch handoff no longer holds the rotated stretch, with capture continuity on or off. - The reconnect clocks, the durable proof and the Finish fence apply only on the reconnect lookup, after the continuity flag and the same-device live-batch match. Failure-Class: FC-live-settlement-uses-capture-clock
kodjima33
marked this pull request as ready for review
November 30, 2026 03:46
This was referenced Nov 30, 2026
This was referenced Nov 30, 2026
kodjima33
added a commit
that referenced
this pull request
Nov 30, 2026
…onnect hold (#26762) ## What changed and why Follow-up to #26749, from its round-5 review. Listen rotation seals a recording at its cap, often mid-speech, and opens the next one on the same device at once. Such a seal can fall within 90 s of the last line, so `_live_cut` counted it as a reconnect cut, and the reconnect hold took over wherever `main`'s rotation check let the recording go. Synthetic case: A rotates at 300 s and B opens on the same device. B enters the completed server-batch handoff at 400 s (`completed` with `home_transcription_pending_at`) before its transcript lands. With capture continuity off, and before #26749, A's card locks at 621 s with its notes queued. With continuity on, the reconnect wait kept A open until B's transcript landed, or until about 1,300 s. The fix, in `backend/database/conversations_v3.py`: - `_live_cut` rejects a recording with a valid rotation stamp. Rotation's own hold (`policy.awaiting_transcript`) alone decides it, under either setting. - The other recordings in the load are still checked for reconnect cuts. - `_rotation_cap` is the one definition of a valid stamp (an `int` or `float` with 0 < cap <= 3600). The rotation check and `_live_cut` both use it, so the two paths cannot disagree about which one owns a recording. The rotation check behaves as before. ## Expected latency cost - **Rotation-sealed recordings:** as before #26749. Rotation is off by default (`CONVERSATIONS_V3_RECORDING_ROTATION`). - **Reconnect cuts:** unchanged. - **Reads:** a rotation seal no longer opens a reconnect window query. Nothing else changes. ## Product invariants affected none ## How it was verified - **The regression fails on current `main`.** On `main`'s loader (`743bd94141`), the same-device replay with capture continuity on fails as the review found, while the cross-device arms and continuity off pass. The new loader test fails there too: the rotation-sealed recording is held. On this head every case passes. - **Mutation check.** Returning early when the latest recording is rotation-sealed, instead of rejecting it in `_live_cut`, passes the replay but fails the loader test, because the earlier reconnect cut loses its hold. - **Pipeline lab.** All 17 committed scenarios, `--jobs 4 --repeat 2 --stt replay`, passed in both runs (89.6 s). `reconnect_successor_lands_late` passes 9/9 at 367 reads, and every scenario's checks and counts match the #26749 head. - **Unit suites.** 158 suites under the CI per-test budget (`BACKEND_UNIT_TEST_FILE_LIST=... bash test.sh`): all `test_conversations_v3*`, `test_pipeline_lab*`, `test_batch_pipeline_projection*`, capture-end, record-seal and server-batch-completion files. All 158 files passed: 5,113 tests, none failed. - **Firestore index guard set** (7 files): 928 passed, including 644 query-shape tests. Neither query shape changes. - **Type check:** `scripts/typecheck.sh` reports 0 errors. - **Preflight:** `make preflight` with this body passed 40 of 41 checks, including the line-count exception, the failure class and the index guard. The one failure is `feature-flag-registry` at today's UTC date: 82 flag entries due 2026-11-22 are past their grace, repo-wide, and this PR changes no flag. `scripts/check_feature_flag_registry.py --as-of 2026-11-29` passes, and metadata-only preflight passes 4 of 4. - **Not yet seen in production.** This is not deployed. ## Tests `backend/tests/unit/test_conversations_v3_successor_hold.py` (74 cases, 3 new): - `test_rotation_lets_a_closed_capture_go_as_main_does` now runs B on the same phone as well as on another device, each with capture continuity on and off. At 621 s A's card is locked with its notes queued in all four. - `test_a_rotation_seal_is_no_live_cut_while_other_cuts_still_hold`: a rotation-sealed latest recording whose successor closed into the handoff is not held, while an earlier reconnect cut in the same load still holds on its capturing successor. Each test runs at or under the 1.0 s CPU budget. ## UI evidence UI-Evidence: none -- backend-only change ## Failure class (fixes) Failure-Class: FC-live-settlement-uses-capture-clock Line-Count-Exception: backend/database/conversations_v3.py | 2667 -> 2675 | one shared rotation-stamp check, used by the rotation check and `_live_cut`, beside the loader's successor checks that already live here 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/26762?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/BasedHardware/omi/26762?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F26762&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
Git-on-my-level
pushed a commit
to Git-on-my-level/omi
that referenced
this pull request
Nov 30, 2026
…onnect hold Follow-up to BasedHardware#26749, from its round-5 review. A recording listen rotation sealed at its cap could also read as a live cut: its seal lands right after its last line when the speech goes on. Wherever main's rotation check let it go, the reconnect hold took over. A same-device successor that closed into the server-batch handoff before its transcript landed then kept the rotated stretch open for up to 15 minutes after that close, where main queues its notes. - _live_cut rejects a recording with a valid rotation stamp; the other recordings in the load are still checked for reconnect cuts. - _rotation_cap is the one definition of a valid stamp, used by the rotation check and _live_cut, so the two cannot disagree about which owns a recording. The rotation check behaves as before. Failure-Class: FC-live-settlement-uses-capture-clock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed and why
A socket reconnect mid-speech seals the current batch recording and opens the next one on the same device at
once. The next recording has no transcript until it seals, so the v3 builder read it as silence: the first card
locked at the five-minute rule, and the rest of the conversation became a second card when it landed.
CONVERSATIONS_V3_CAPTURE_CONTINUITY(on by default) did not cover this.load()kept a stretch open only for afollowing recording that was already
v3_pending._mark_successor_pendingheld one only behind arotation-stamped seal, which is off in prod, and only when that source spoke last.
Synthetic shape of the incident: recording A runs 0:00 to 2:56, the socket drops, and A seals at 3:00 as B opens
on the same phone. B captures ten more minutes of the same talk and lands 11 minutes after A ended. On
main,A's card locks and gets notes about five minutes after A landed, and B becomes card 2.
The fix, under
CONVERSATIONS_V3_CAPTURE_CONTINUITY:(
policy.LIVE_SEAL_GAP, either way within 10 s,policy.CAPTURE_SKEW).record_sealed_at, elsehome_transcription_pending_at. It is neverfinished_at, which isthe last archived audio frame.
database/conversations_v3.py_mark_successor_pending): the nextbatch_live_v1capturefrom the same
client_device_idthat opens within 90 s of that line.started_atwindow query anchored at its last line, most recent seal first, readin pages of 16 (
SUCCESSOR_PAGE).SUCCESSOR_READS; an empty query counts as one).once it is discarded with its Finish kept. Any other discarded successor never holds.
main's, under either setting. Its lookup and hold aremain's code: a successor still capturingwithin the cap, or processing within 15 min of
finished_at, marks a page continuation(
policy.awaiting_transcript, unchanged). The clocks and proof below apply only to the reconnect lookup, afterthe continuity flag and the device and lane match.
outline.SUCCESSOR_HOLD. The last stretch holding it stays openwhichever device spoke last. Earlier stretches settle.
policy.successor_hold_until, absolute deadlines on server stamps that do not move):created_at.earliest of
record_admitted_at,home_transcription_pending_atandrecord_sealed_at.retry.
FINISH_WAIT) after its trusted request time,v3_finish_requested.at.Without that stamp, the bound runs from the first close.
_capture_landed):empty_transcription.terminal, whose empty spans cover the closed audio.capture_end.units_landed. Batch projection nowwrites
record_units_landed_seal_at(the seal the job covered) in the transaction that commits theauthoritative sibling completion (
database/batch_pipeline_projection.py), last in that transaction and onlywhile the row still carries that seal.
transcribedtransition afterthe latest seal (
capture_end.seal_proof). It is one read with a 3 s timeout and no retry, memoized persuccessor per pass.
units_held).Round 5: the two review items on
17a21f9e3dmain's. The rotation scan no longer callspolicy.successor_hold_until; its loop ismain's, line for line, except that it stops at the silence gap withbreakso the reconnect lookup still runs.server-batch handoff (
completed,home_transcription_pending_at, no speech yet). At 621 s A's card lockswith its notes queued, with capture continuity on or off, as on
main.finished_at610 s and no close stamp keeps A open at620 s, and B joins it at 650 s.
backend/database/conversations_v3.pyis 2,678 lines (2,511 onmain), and the exception below says so. Validated with this body bymake preflight.Round 4: the two review items on
d5c20e5eb9main's rotation wait is back. Rotation successors no longer go through the reconnect policy first.policy.awaiting_transcript(main's rule) decides and marks_v3_page_continues, as onmain. Where it letgo, the reconnect wait still ran; Round 5 removes that.
finished_at610 s and no closestamp, capture continuity off. At 620 s A stays open, and B joins it at 650 s.
test_conversations_v3_review.pyaremain's again, unchanged.carrying its Finish ends the scan without holding A.
A is not held at 529 s or 598 s.
Round 3: the three review items on
5a03416141v3_finish_requested.atis projected and drives the 5 min bound.releases by 670 s; with B finished at 228 s and C opened at 229 s, A is not held at 529 s.
main.started_atranges, so no index is needed.units_heldno longer releases.once.
Expected latency cost
the capture lands.
socket created that has heard no speech stays open while the socket streams
(
utils/stt/speech_clock.quiet_since,FC-transport-liveness-read-as-speech-activity).never lands.
resuming the same recording on reconnect would remove that case.
transcribed): it waitsout its bound, 15 min after its first close.
windows, at most 64 metadata documents (usually one or two), plus, without the durable proof, one ledger
document per partly projected successor.
backend-sync.Until the writer is live, holds release on the ledger's
transcribedor wait out their bound.Product invariants affected
none
How it was verified
Firestore rows, with the real
service.reconcileandcommit_projection.17a21f9e3d), the round-5 regression fails with capture continuity on and off, as thereview found. On
main's loader it passes with both. The round-3 rotation cases pass on all three.d5c20e5eb9), the round-4 regressions fail as the review found: the rotationsuccessor still in finalization past the cap (loader case and continuity-off replay), and the discarded B whose
Finish must fence C. The ordinary-discard control passes on both.
5a03416141), the round-3 replays fail: a silent first unit with no ledger, a stale ledgerwith all speech landed, and a Finish with the close 160 s after the request.
on. Each round-4 rule was removed in turn, and each removal failed its own test:
mainrotation rule;--jobs 4 --repeat 2 --stt replay: every check passed in both runs(552.8 s on a loaded host).
account_deletionsread between repeats, theaccount-deletion check's wall-clock cache. Rerun alone, all three passed deterministically with the same counts.
reach.json, which listsutils/sync/capture_end.pyfor the four reconnectscenarios. Rounds 4 and 5 add no file to any scenario's reach, so it stands.
reconnect_successor_lands_latepasses 9/9 within budget, at 367 reads.BACKEND_UNIT_TEST_FILE_LIST=... bash test.sh): alltest_conversations_v3*,test_pipeline_lab*,test_batch_pipeline_projection*, capture-end, record-seal andserver-batch-completion files. All 158 files passed: 5,042 tests, none failed.
_mark_successor_pendingdriver runs a rotation source and a live-cut source, and records both shapes:started_at >with limit 8, and thestarted_atwindow with limit 16. Both are single-field ranges, so nocomposite index is needed.
scripts/typecheck.shreports 0 errors.make preflightwith this body passed 40 of 41 checks, including the line-count exceptions,the failure class, the index guard and the lifecycle write guard. The one failure is
feature-flag-registryat today's date: 82 flag reviews due 2026-11-22 are past their grace, repo-wide, and this PR changes no flag.
scripts/check_feature_flag_registry.py --as-of 2026-11-29passes.it. The hold runs on
backend-sync; the proof writer runs wherever batch projection completes.Tests
backend/tests/unit/test_conversations_v3_successor_hold.py(71 cases):Round 5: rotation lets a closed capture from another device go as
maindoes: a multi-pass replay of thereview's case, with capture continuity on and off.
Round 4:
main's wait for a same-device batch successor still in finalization past the cap, as a loadercase and a continuity-off multi-pass replay.
Loader matrix:
capturing, and a future Finish.
A finished successor fences off a later capture (B finished at 228 s, C opened at 229 s, A free at 529 s).
Crowding: 24 other-device captures plus 16 cards are paged through in three pages; past 64 documents the lookup
stops.
Lookup order: the newest cut is looked up before an older crowded one, and rotation keeps its own lookup
beside a crowded earlier cut.
Twelve sources matching one successor: one ledger read, with the 3 s timeout; zero reads with the durable proof.
The real projection completion stamps the seal it proves after the last sibling, and writes nothing for a job
admitted before a reseal.
Round 2 cases kept:
Multi-pass replays:
Each test runs at or under the 1.0 s CPU budget.
Elsewhere:
test_conversations_v3_review.py: back tomain's rotation tests.MemoryQueryaccepts read options (timeout,retry) and
<.test_batch_pipeline_projection.py: the completion helper takes an optionaljob.UI evidence
UI-Evidence: none -- backend-only change
Failure class (fixes)
Failure-Class: FC-live-settlement-uses-capture-clock
Line-Count-Exception: backend/database/conversations_v3.py | 2511 -> 2678 | the successor hold extends the loader's existing check in place beside #26705's edits to the same file; splitting the store is out of scope for an incident fix
Line-Count-Exception: backend/database/batch_pipeline_projection.py | 1567 -> 1582 | the completion proof must commit in the sibling-completion transaction that already lives here
🤖 Generated with Claude Code