Repository navigation
fix(conversations-v3): plan at most one open window per owner - #25800
Conversation
commit_projection refuses a plan with more than one in-progress row (multiple_open_conversations) and parks the owner. The plan is the same on every retry, so the park never self-heals and the owner's Home freezes. Three planner shapes produced several open windows: - preserve_finished_windows cut an open window into one fresh fragment per gap between retained finished rows, and every fragment kept the window's open state. An open window's boundaries are not final, so its unmatched lines now stay one window, as a manual stretch's already do. A finished window still splits exactly as before. - A backlog page's continuation marker held open every stretch that ends in the page's latest recording, not only the last one. - Speech stamped in the future kept stretches open across recorded silence. A later stretch begins only after recorded silence or a manual cut, so every stretch but the last is now finished. Together these keep at most one open window in any plan. Speech custody is unchanged: no line moves between retained and fresh windows, retained rows keep their ids and claims, and the open window claims only unpublished audio. Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 78b08e41fc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # An open window's boundaries are not final, so its unmatched lines stay one window: the open | ||
| # edge. A fragment per gap between retained rows left several open windows, which the commit | ||
| # refuses (multiple_open_conversations) on every pass. A finished window splits as before. | ||
| together = window.get('_keep_unmatched_together') or window.get('finished') is False |
There was a problem hiding this comment.
Add the required conversation-lifecycle change note
This changes conversation lifecycle behavior by keeping unmatched speech together while a window is open and finishing earlier stretches, but the commit includes only planner code and tests. backend/AGENTS.md explicitly requires lifecycle changes to add a note under backend/docs/listen_pusher_pipeline/changes/ in the same PR. Add a dated note describing the changed boundaries, rollout/flag state, and verification evidence so the pipeline documentation records this recovery behavior.
AGENTS.md reference: backend/AGENTS.md:L164-L164
Useful? React with 👍 / 👎.
Panel review of 78b08e4 (F3): keeping an open window's unmatched lines together widened its time range across retained rows, so service._match could time-match a deletion tombstone inside it and the plan would skip the whole open window, not only the lines in the deleted range. Split an open window around retained rows exactly as a finished window splits, with the same fragments, lines and time matching, and keep only the last fragment in the window's open state. Published speech follows every earlier fragment, so none of them can be the open edge. The regression now also covers a stored open row from the previous pass (the open edge keeps its id), and checks that the retained row keeps its claims and audio (F1, F4). Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]>
… five minutes (#25829) Builds on #25794 (merged as 755558a): sit-down cutting when its silence gap is set above five minutes. ## DESIGN: - **What changes.** When `CONVERSATIONS_V3_SILENCE_GAP_SECONDS` (#25794's setting) is over 300 s, v3 cuts at sit-downs instead of at the silence itself. At the default of 300 s nothing changes, so this PR alone changes nothing in production; the gap setting is the switch, and setting it back to 300 is the rollback. - The outline sees pauses of 2 minutes or more as marker lines (`---- 4 min without speech ----`). A sit-down rule replaces the "N of recorded silence is a hard boundary" sentence. Line numbering is unchanged. - Neighbouring `conversation` entries of one stretch join into one card, with topics as sections. Dictation under the Home word minimum that sits between two of them joins as a section. Media, background and longer dictation stay separate. Manual-end stretches keep their existing single card. - Under a long gap, each card meets the Home word minimum on its own words. Otherwise #25786's stretch-level total lets every piece of a two-hour stretch onto Home. - **Two-hour cap, at any timing.** A stretch over two hours is cut after the longest prefix that ends within two hours of its start, then again from there. The cut ignores the outline and does not move as live speech arrives; main's middle cut moved every pass and stranded one-line cards (traced on 11-18, 13:54–14:04). The cap and the projection share one ownership rule and one index per plan (`planner.Ownership.owner_of`, built once in `plan()` and passed to both projections): an exact hold (id and timing) wins first, across open and locked rows, with a row naming the line's recording in `v3_recording_ids` ahead of a legacy row naming none; only without one does containment in a row's window and audio claim decide, locked rows first, so a revised turn stays with its row. A deleted locked row (tombstone) still owns its lines, so the deleted speech stays isolated in its own skipped window and never joins the valid speech either side; the cap never reuses a tombstone's cut. Deleted open rows own nothing, as before (left to the time-matched tombstone path). When a locked row owns a part's first line, the part ends at the first line it does not own: rows main already cut, or an earlier pass cut, keep their cut after upgrade and on backfill resume, even when a turn straddles it or a held turn is revised. A locked row that owns none of the stretch's lines never cuts it. The plain duration branch (no locked owner of the part's first line) still finishes every part but the last without consulting later lines' owners: with no locked owner there is no committed cut to keep, and the projection still routes each finished part's lines through `owner_of`, so a line a protected row owns is retained by that row and only lines no protected row owns can land in the finished part. A stretch over two hours has to be cut somewhere, so this is the existing cap behaviour. - **One owner per segment.** A row that already holds a segment keeps it on later passes, even when overlapping turns put it inside a neighbour's window and clipped claim; a turn published in the open tail stays there even when its audio lies inside the locked prefix's claim. - **Lock clock under custom timing.** With either setting off 300, the lock delay counts from the later of the last speech and `v3_speech_landed_at`. That field is written in the same transaction as the speech (live transcript write, sync assignment, batch recording create), only when the speech changed, so a reconcile between the commit and the re-arm already sees it. Offline batches of old speech no longer lock on arrival. Default timing and backfill derive still count from the last speech. - **Reads and writes.** No new query, document or transaction. Speech transactions on v3 recordings carry one more timestamp field. - **Model calls.** Outline calls per stretch are unchanged, and a long gap means fewer, longer stretches. Each prompt grows by the marker lines, under 1% of tokens. Notes calls fall with the card count. - **Latency.** No change of its own. Lock timing is #25794's `CONVERSATIONS_V3_LOCK_SECONDS`. - **Invariant kept.** At most one open window per owner plan (#25800). Joining works inside one stretch and never holds an earlier stretch open. There is a test for it. - **Production number that proves it.** `READBACK:` Home cards per active v3 owner-day, and the `below_word_minimum` share of derived rows. Both fall, while the visible cards' word share of the day's speech stays within 5% of baseline. ## Lab evidence Pipeline lab (m5-mbp): the owner's real days, replayed offline through each ref's own `outline`, `planner` and `visibility` code with real outline calls. Scored against a reviewed ideal Home: 11-17 and 11-18 were reviewed by the owner, and 11-19 was judged by Fable. Dictation is excluded. No production reads or writes, and no transcripts leave the lab host. **Whole finished day** (3 runs each, gap 900 s / lock 900 s, on #25794's head c9e058c, which is identical in v3 code to 755558a): | Day | Arm | Home cards | Whole ideal cards | Home precision | |---|---|---|---|---| | 11-19 | #25794 | 8-9 | 4/6 | 0.56-0.62 | | 11-19 | + this PR | 9 | 4/6 | 0.56 | | 11-18 | #25794 | 19-23 | 3-5/9 | 0.56-0.67 | | 11-18 | + this PR | 10-13 | 5-7/9 | 0.54-0.70 | | 11-17 | #25794 | 24-33 | 0/2 | 0.29-0.46 | | 11-17 | + this PR | 7-12 | 0/2 | 0.22-0.43 | Ideal Home recall is equal, except one of three 11-17 runs of this PR, which missed one of the 2 ideal Home cards. **Full live replay of 11-18** (incremental arrival, real locking, gap 900 / lock 900): #25794 gives 213 cards, 16 on Home, 6/9 recalled, 3/9 whole, precision 0.62. With this PR: 210 cards, 10 on Home, 5/9, 4/9, precision 0.70. Live fragmentation, which neither ref changes, dominates the live score; it is being traced separately. Replays at main 755558a+ against this PR, at default timing and at gap 900 / lock 3600, are running. Results go in a comment before merge. At default timing this PR is inert by construction: `outline.sitdown()` is false at 300 s. ## Tests - `test_conversations_v3_sitdown.py` (new): the 300 s threshold, the prompt rule swap and gap markers, joining, long dictation, manual end, the per-card word gate, and one open window. - `test_conversations_v3_lock_timing.py`: the prompt-threshold test now uses a 240 s gap, where the hard-boundary sentence still applies. - `test_conversations_v3_live_passes.py` (new): real `reconcile` + `commit_projection` passes on the strict fixture. One open card while live speech stays inside the lock delay; offline batches of old speech at 900 and 300; the cap cut survives the first paid outline, and ignores a section a later outline drops (300 and 900); a reconcile between the speech commit and the re-arm does not lock; derive ignores the landing clock; overlapping turns at the cap keep one owner across passes with non-overlapping claims; rows cut by main's middle cap keep boundaries, segments and claims after upgrade, also when a turn straddles the old cut or a held turn is revised (300 and 900); a turn published in the open tail inside the prefix's claim stays in the open tail with no finished fragment (300 and 900); a full write that changes no speech keeps the landing time; resuming a main-cut backfill run keeps its rows. Each was checked to fail with its fix removed. - Tombstone and precedence: valid speech either side of a deleted card in one stretch survives in live cards and the deleted speech does not reappear (300 and 900); a tombstone never pins a cap cut; a source-qualified exact hold beats an earlier legacy one; a deleted open row never owns a line; an exact hold needs the same timing; one `Ownership` per plan. - Mutation pass over the ownership rule (14 mutations, every one caught by at least one test): tombstones dropped; cap reusing a tombstone cut; legacy before source-qualified; exact ignoring the recording; claim before exact; no claim fallback; a separate locked-only cap rule; no cut reuse; a locked run ignoring an owner change; the projection retaining open-owned lines; the projection building its own index; service passing no index; deleted open rows owning lines; exact ignoring timing. - `test_sync_assignment_recovery.py`: the landing time commits with assigned speech for recordings only, and an exact retry preserves it. - `test_conversations_v3_engine.py`: a locked row holding none of an over-cap stretch never cuts it (control), and one holding the stretch start keeps its cut; an exact hold on a later locked row beats an earlier row's claim, for the cap and the projection, and needs the line's own recording. With `test_conversations_v3_stretch_cohesion.py`, expectations moved to the stable cut. - All v3 suites pass together (728 tests); the sync assignment, cross-job, live transcript, manual speaker, batch projection, listen failover and lifecycle files pass one file at a time. Their combined xdist run has order-dependent failures and a hang that reproduce on main without this PR (`test_sync_assignment_recovery.py` leaks state into later files on the same worker). Line-Count-Exception: backend/database/conversations.py | 5293 -> 5307 | the landing stamp must commit inside update_conversation_segments' speech transaction, gated on a speech change Line-Count-Exception: backend/utils/sync/assignment.py | 1610 -> 1617 | the landing stamp must commit inside the sync assignment transaction that writes the speech ## Follow-ups (not in this PR) - The retained-row duplicate check ignores speaker identity, so it can suppress a distinct speaker's near-identical turn. This predates this PR (reviewer note on #25829); it needs its own fix and test. ## Product invariants affected none ## Failure class (fixes) Failure-Class: none 🤖 Generated with [Claude Code](https://claude.com/claude-code)
…5895) ## Summary - Finish fresh fragments that end before the original planned window's last line. If retained speech owns the final line, its fresh prefix enters processing on the current reconcile pass. - Add the dated lifecycle note for #25800 and this follow-up, including rollout state, rollback, and recovery evidence. ## Verification - The regression reproduces on `main`, where the prefix is `in_progress`. With the fix, the same prefix is `processing` and the finished row retains its ID and speech. - `bash backend/test.sh backend/tests/unit/test_conversations_v3*.py` passed all 578 tests across 19 files. - `scripts/pr-preflight --pr-body-file ../pr-body.md` passed all 38 checks. ## Product invariants affected none Failure-Class: none <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/25895?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> <!-- End of auto-generated description by cubic. -->
DESIGN:
outline.stretches,planner.preserve_finished_windows). It adds no query, document read or transaction round trip.v3_pendingbacklog is bounded by what is there now: at most 200 pending sources per owner, read 32 per pass.READBACK:Builder leases parked withv3_blocked_reason=multiple_open_conversationsdrop to about 0 within 1 h of serving. Today's count is 41 at 17:2xZ, among the 483 owners holdingv3_pendingsources. Theomi_conversations_v3_blocked_total{reason="multiple_open_conversations"}rate also stays at about 0. On b45a0c9 the log shows a median of 88 events per full hour, with 364 owners blocked at least once since 2026-11-18T21:44Z.Summary
commit_projectionrefuses a plan with more than one in-progress row (backend/database/conversations_v3.py:545-547,Conflict('multiple_open_conversations')). The reconcile parks the owner (service.py:46,BLOCKED), backs off 5 min to 1 h, then replans the same inputs. The plan comes out the same every time, so the park never self-heals and the owner's Home freezes.Measurement (prod, read-only)
Tiers:
ro-prodfor logs,prod-operatorfor Firestore REST metadata. In-process replay: every writer was stubbed and every Firestore write method raised.ENCRYPTION_SECRETwas held in memory only. Uids were hashed in-process; no transcripts, titles or summaries were printed.v3 reconcile blocked reason=multiple_open_conversationsevents from 364 distinct owner tags, all on backend-sync. The first was at 2026-11-18T21:44Z, the all-users stage, and events occurred every hour after that. The problem predates the 16:16Z deploy of fix(conversations-v3): honor manual cuts and preserve exclusive audio claims #25764 and fix(conversations-v3): load a heavy owner's closure by claims, bounded by size (v3_derived_budget) #25753.v3_blocked_countdistribution: 1 (9 owners), 2 (12), 3 (1), 4 (4), 5 (4), and 16-28 (14). The 14 long-parked owners all have more than 32 pending sources.omi.v3_manual_end.A second replay on the deployed b45a0c9 code, about 40 minutes later, found 25 of the 41 owners still planning more than one open window.
Root cause
planner.preserve_finished_windows(planner.py:482-485on main) flushes the unmatched lines before each retained row's line as a fresh window built from{**window}. Only a manual stretch or its after-cut continuation (_keep_unmatched_together, fix(conversations-v3): honor manual cuts and preserve exclusive audio claims #25764) keeps them together. That path is unchanged here. Every fragment of an open window inheritsfinished=False, so a live stretch that contains published speech (interleaved or late-synced capture, an on-open chapter, a backlog page held open) plans one open window per gap.outline.stretches(outline.py:137-141on main) computesfinishedper stretch fromnow - end >= SILENCEand the continuation marker. A continuation marker on the page's latest recording holds open every stretch whose last line is in that recording. Speech stamped in the future is never 5 minutes old. Both cases ignore the fact that a later stretch exists, and a later stretch begins only after recorded silence or a manual cut (outline.py:121-131).Fix
outline.stretches: every stretch but the last is finished. Only the last stretch can still be held open, by recency, page continuation or a pending manual state.preserve_finished_windows: an open window splits around retained rows exactly as a finished window does, with the same fragments, lines and time matching. Only the last fragment keeps the window's open state; published speech follows every earlier fragment, so none of them can be the open edge. Those fragments are the same ones the window would produce once its stretch goes quiet, so the end state is unchanged; they just finish sooner.service._matchcould match a deletion tombstone inside it and skip the whole open window. This head drops that approach.planner.windowsand_cohesive_groupsalready leave only the last part open. Retained windows are always finished.What does not change:
finisheddiffers. Retained rows keep their ids, claims and audio. The open edge keeps the stored open row's id and claims only unpublished audio. The test asserts all of this. The fix(conversations-v3): honor manual cuts and preserve exclusive audio claims #25764 claim rules (no duplicate audio, earliest id kept) are untouched.No kill switch. Every changed plan except that one edge case is a plan
commit_projectionrefuses today. Rollback is a revert.Recovery (no manual unpark)
The parked owners recover on their own after deploy:
v3_pendingmarkers are still owed, and the backoff expires within 1 h.v3_blocked_count,v3_blocked_reasonandv3_backoff_until(conversations_v3.py:698).Replaying the fixed code against the same 41 owners runs the real
commit_projectionagainst an in-memory copy of each closure (all writers stubbed, reads from prod). Replay of head 3db0387 (~18:45-19:30Z), on the 41 owners parked at 17:20Z:target_exists, because a real pass committed for those owners during the replay. Both leases were already cleared in prod, and re-running the replay committed each with one open row.Recount at 19:25Z: 57 owners parked, 22 of them from the 17:20Z set and 35 new. On the deployed code, 25 of the 35 new owners already plan at most one open window, so they are transient parks that recover after backoff; the other 10 are preserve splits. The same replay of the fix on all 35 new owners: all 35 commit, 11 with one open row and 24 with none.
To unpark without waiting for the backoff, an operator deletes the three fields on
users/{uid}/conversation_v3_leases/builder, as the runbook describes. That is not needed here.Out of scope, noted
finishedline, addinglock_delay. Withlock_delay > silence_gap, several unlocked stretches would be open at once, and the commit refuses that. Whichever PR lands second has to keep the rule that only the last stretch is open.Tests
test_published_speech_inside_an_open_stretch_leaves_one_open_window: a published row and a stored open row, then late capture around and inside the published row. Red on main (three open fragments). Green here, with these properties:test_only_the_last_stretch_stays_open: page continuation and future-dated speech, plus the cohesion windows. Red on main, green here.test_conversations_v3_*,test_listen_v3_*, record-close and batch-projection admission.bash test.shviaomi-heavy) picked 152 files, the same set CI runs, and 7,038 tests passed. One file failed only the local 1.00 s CPU guard:test_conversation_processing_retryable_timeout.py, on the/v1/conversationsOpenAPI case at 1.14 s. That is the same known local guard hit recorded on fix(conversations-v3): honor manual cuts and preserve exclusive audio claims #25764, and this change does not touch it.Panel triage
Panel review-20261119t180246-a22d returned SHIP on 78b08e4 (luna, deepseek and glm-flash all completed).
Panel review-20261119t184151-fa1e returned FIX-FIRST on the final head 3db0387 (luna, deepseek and glm-flash all completed). No code changed after it.
_matchtombstone rule is the same as for a single-fragment plan on main. It is a candidate follow-up: prefer an in-progress prior over a tombstone.Product invariants affected
none
Failure class (fixes)
Failure-Class: none
🤖 Generated with Claude Code