Repository navigation
fix(conversations-v3): rotate long v3 recordings at speech pauses (default off, cohort canary) - #25726
Merged
Conversation
…rived conversations appear during a long capture
…arget; default off with cohort canary
…fused seals and drains them at teardown
…son-enum rotation counter
kodjima33
added a commit
that referenced
this pull request
Nov 18, 2026
## Problem Follow-up to #25726 (merged as `ae68d3176d`, rotation off). The round-4 review found these failure paths in `_rotate_v3_recording` and the supersede step. They have to land before the one-owner canary. ## Change 1. **Pointer move failure** (`routers/listen/conversations.py`, supersede block in `create_new_in_progress_conversation`). The `supersede_live_continuation` call runs after the switch. It is now wrapped in try/except: a failure is logged and counted as `pointer_failed`, and the create always continues to its tail (capture timeline, admission attach, `_refresh_speakers`, `send_conversation_session`). Test: `test_a_failed_pointer_move_still_finishes_the_successor_and_counts_it`, using the real create path in `CaptureHarness`. The successor is fully bound, the old row is sealed, the phone gets the session event, and the Redis id names the successor. 2. **Redis restore can't mask the error.** The restore moved into `_clear_failed_successor`, where any failure is caught and logged. A `WebSocketException` from the create is still re-raised. Test: `test_a_failing_redis_restore_never_masks_ownership_loss`. 3. **Empty successor after a bound-then-failed create.** - `_clear_failed_successor` first publishes the successor's close barrier (`close_server_batch_audio`, with its producer token if it has one), then calls `delete_empty_recording_conversation(..., allow_empty_server_batch=True)` and checks the result. - The barrier is required because the delete only accepts a closed, never-received batch row (`database/recording_sessions.py:294-310`). - A row the delete keeps (it has audio) is counted as `successor_kept` and logged. It is `in_progress` and not current, so stale recovery seals or deletes it. - Tests use the real `tombstone_and_delete_empty_conversation` on `_FakeFirestore`: - `test_a_failed_create_publishes_the_barrier_then_deletes_its_empty_successor`: the unclosed owned successor is deleted. With the barrier call removed, this test fails, because the delete is a no-op. - `test_a_failed_create_keeps_a_successor_that_has_audio`: the successor is kept when it has `has_content`, `server_batch_audio_received` or `server_batch_audio_start/end`. - The earlier test that monkeypatched the delete is removed. - **Residual label window:** between the start of the create and the restore, `host.recording_session_id` already names the successor's session while frames still go to the old row. That label feeds telemetry (`receiver.py:886`) and the recording-session lease renewal, never audio binding: the archive binds by `current_conversation_id`, which never names a failed successor. - `test_frames_during_a_failed_create_never_bind_to_its_successor` runs 40 frames through a real `LiveAudioArchive` while the create fails, with the session label observed as `session-2`. Every frame lands in the old row's window, the successor is deleted, and nothing stays uncommitted. - After an ownership loss (`WebSocketException`), the Redis restore is skipped, because another socket owns the recording. Test: `test_ownership_loss_skips_the_redis_restore`. 4. **`skipped_producer` outcome.** It is counted once per row (the set keeps the last 64 row ids; `test_producer_skips_stay_bounded`) when the reconnect producer protocol blocks rotation, and only for owners rotation admits. `pointer_failed`, `skipped_producer` and `successor_kept` are added to `RecordingRotationOutcome`. Test: `test_a_reconnect_protocol_skip_is_counted_once_per_row`. Rotation stays off in every environment (`CONVERSATIONS_V3_RECORDING_ROTATION=off`). No flag, chart or runtime env value changes. ## Before widening (design only, not in this PR) A crashed v3 socket leaves its recording `in_progress`, whether or not rotation ran. Only listen stale recovery seals it: `recover_stale_in_progress` (`routers/listen/conversations.py`), on the owner's next connection, after an hour of quiet. The durable quiet check armed at creation refuses it. In `recovery_admission_refusal` (`database/conversation_finalization_jobs.py:380`), `if conversation.get(TERMINAL_NO_DERIVED_EFFECTS_FIELD): return 'terminal_no_derived'` matches every v3 recording, because `utils/conversations/v3/triggers.py:61` (`mark_new`) stamps `terminal_no_derived_effects=True` at creation. The quiet check reaches it at `database/conversation_quiet_checks.py:212`. **Smallest fix:** exempt only v3 recordings with server-batch audio from that refusal: ```python if conversation.get(TERMINAL_NO_DERIVED_EFFECTS_FIELD) and not ( conversation.get('recording') is True and server_batch.has_audio(conversation) ): return 'terminal_no_derived' ``` For a recording the marker means it never takes derived effects. It does not mean the row is already finalized. Processing still goes through `recording_short_path` (`utils/conversations/v3/service.py:54`): no model, apps, memories or webhooks, then `lifecycle.complete` plus the v3 builder trigger. The refusal is shared with `database/stuck_backfill.py:59`, so the fix needs one test per caller: - the quiet check admits a v3 recording with audio, after its lease expires; - the admitted job completes through `recording_short_path` with no derived effects; - stuck backfill and legacy terminal rows are unchanged. A separate sweeper would duplicate the quiet check's lease and fence logic, so I'd not build one. Ownership: lane/conversations-v3. Until this lands, widening past a canary leaves any crash-orphaned v3 recording invisible until the owner reconnects. ## Verification - Unit: `test_listen_batch_speech_quiet.py`, `test_listen_v3_rotation_custody.py`, `test_listen_v3_rotation_continuation.py` and `test_reason_label_enums.py` all pass. Listen, v3, quiet-finalization, desktop-batch, recording-session and query-shape suites: 2572 passed, 1 skipped. - `backend/scripts/typecheck.sh`: 0 errors. - `scripts/pr-preflight --pr-body-file`. - No device or prod run. Rotation is off. Line-Count-Exception: backend/routers/listen/conversations.py | 1458 -> 1519 | rotation failure handling (pointer-move guard, failed-successor cleanup, producer-skip count) stays beside the create path it guards ## Product invariants affected none ## Failure class (fixes) Failure-Class: FC-transport-liveness-read-as-speech-activity 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This was referenced Nov 19, 2026
Git-on-my-level
added a commit
that referenced
this pull request
Nov 21, 2026
…behaviour for the listen roll (#25954) ## Summary backend-listen still serves `backend:44d0a4f` (18 Nov). On current main, the listen values would switch three things on at the next listen roll (SCA-3516). Release's installed preflight refuses all three. This PR pins each one **by effect**, so the roll preserves today's behaviour. Shipping ruled at 2026-11-21 13:25Z on SCA-3516 that no activation rides the listen roll. | Key | What 44d0a4f does today | Main without this PR | Pinned | Why the pin matches | | --- | --- | --- | --- | --- | | `BATCH_ACCOUNT_PRIVACY_WRITER_ENABLED` | Nothing. The account privacy writer (`database/batch_account_authority.py`, kill switch in `config/policy/kill_switches.py`) is not in 44d0a4f. | `true` (kill switch default on) | `false` | `false` keeps the legacy writer routing that 44d0a4f has. A first activation on listen is a custody decision (David). | | `BATCH_PIPELINE_PACKING_SAMPLE_RATE` | Nothing. `config/batch_pipeline_packing.py` is not in 44d0a4f. | `0.001` | `0` | `sample_rate()` accepts 0, and `packing_counterfactual` gates on `bool(sample_rate())`, so 0 means no sampling. | | `UNLIMITED_V2_BACKFILL_HOURS_CAP_ENABLED` | The cap exists in 44d0a4f and its chart renders `"false"` (live: false). | `true` (#25677) | `false` | Same as live. Listen also admits sync backfill uploads (`/v2/sync-local-files`), so listen admission stays **uncapped exactly as today**; Cloud Run sync stays capped. Capping listen is the follow-up below. | Rotation: `CONVERSATIONS_V3_RECORDING_ROTATION` already renders `off`, with `CONVERSATIONS_V3_ROTATION_MIN/MAX_SECONDS` at 180/300. `rotation_seconds()` reads those two values only at `routers/listen/conversations.py:1273` and `:1412`, and both calls sit behind `recording_rotation_enabled()`. With rotation off, nothing reads them. 44d0a4f does not contain #25726. Changed: prod overlay `backend/deploy/runtime_env/prod.overlay.yaml` (gke/backend-listen), the regenerated `backend/deploy/runtime_env.yaml`, the listen prod chart values, the regenerated flag registry doc, the listen contract doc line, a change note under `backend/docs/listen_pusher_pipeline/changes/`, and the backfill-cap validator test. The test now carries a dated exception for prod backend-listen and asserts all three pins on both the composed manifest and the listen chart. The floor is kept at >= 5 surfaces. ## Follow-up after the listen roll This is a cost-control item: listen backfill admission is uncapped today and stays so until then. Turn the backfill cap on for listen as its own config change: David's 2026-11-18 support-packet decision 13 intends it on for every prod surface. Then remove the test exception. The privacy writer on listen stays off until David decides it. ## Verification - `bash test.sh` changed-file selection under `bin/omi-heavy`: passed (rc 0). `tests/unit/test_backend_runtime_env_validator.py`: 300 passed. - Release's installed preflight render is the acceptance check at the exact head. ## Product invariants affected - INV-MEM-4: the change touches a locked deploy path (runtime manifest) but changes no memory intake or promotion behaviour. Each value is pinned to what the serving listen image already does, and no code path changes. ## Rollback Revert this PR. The listen roll itself rolls back with `mode=rollback` to the prior Helm revision. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.
Problem
Conversations v3 is on for TestFlight. A pendant capture is a batch-only recording. It has no transcript until it seals, and it seals only after 120 s of speech quiet (#25633) or at socket close. In a cafe the speech never pauses for 120 s. Nik's recording
4170f9cfran 19:01:54 to 19:35:31Z (33.6 min). His chat ended 19:09:50Z, and its derived rows appeared at 19:40:52 and 19:43:08Z. Home showed nothing for 31 minutes.Change (ships OFF)
Rotation (
routers/listen/conversations.py_v3_rotation_due,_rotate_v3_recording,_seal_rotated,_seal_rotated_recording;utils/stt/speech_clock.pyrotation_due). A batch-owned row withrecording: true(the v3 marker) seals at the first 1.5 s speech pause once it isCONVERSATIONS_V3_ROTATION_MIN_SECONDSold (default 180), or atCONVERSATIONS_V3_ROTATION_MAX_SECONDS(default 300) without a pause. A row never rotates if it is a legacy row, an onboarding capture, has no speech of its own, has a pending client stop (finalization_reason), is under an episodehold, or is inside the 60 s backoff after a failed rotation. A tick that is already a quiet seal or a producerboundary_attakes the existing path. A failed or absent SpeechClock uses only the cap.Cut order (fixes the custody blocker). This is the order
rollover_after_transcript_decode_failurealready uses:in_progressand keeps receiving audio untilcurrent_conversation_idswitches.LiveAudioArchive.retarget(old, successor)(utils/other/live_audio_archive.py), under the archive lock. From then on, any frame still addressed to the old id is appended to the successor. This covers a frame the receiver bound before the switch and appended after it.finish_recording(old)flushes and commits the old row's packs. Its custody is then final.v3_rotation_cap_seconds, then runprocess_conversation(old). The old row is no longer current, soclose_batch_archiveskips the global close, exactly as in the decode-failure rollover.A custody timeout leaves the old row queued and retries it on the next tick (at most 8 queued). After socket close, the old row's armed quiet check and stale recovery own it. A successful seal drops the old producer token, so the 64-token cap is not reached on long sockets.
Supersede mode (
create_new_in_progress_conversation(rollover=True, supersede=previous_id),database/listen_continuations.pysupersede_live_continuation).client_conversation_id. Without this mode, the create first resolved the origin'slive_continuationpointer, which named the still-open current row, and resumed that same row. So a long recording rotated at most once.current_conversation_id, in one transaction. A failed create therefore never leaves the pointer on a dead empty row.other_owneris counted and logged, and another generation's pointer is never taken.Successor failure. If the create raises, or returns without switching, the current recording is kept.
recording_session_id,batch_record_capture,recording_session_ids_by_conversationand the Redis in-progress id are restored, and rotation backs off 60 s (ROTATION_RETRY_SECONDS). AWebSocketException(ownership changed, or the 64-token cap) is re-raised after the restore, so the socket closes as it would on any other create.No rotation on reconnect-protocol rows. A row carrying
listen_batch_producernever rotates. Its producer token would fence both the seal retries and stale recovery of an orphan. The flag is unset in prod, so this is inert today.Seal retries. A retired recording stays in
_unsealed_rotationsuntilprocess_conversationreturns True.routers/listen/runtime.py, before the current row is handled) runsdrain_rotationsfor one last attempt.in_progressforLiveConversationController.recover_stale_in_progress(routers/listen/conversations.py). That runs inprocess_pendingon the owner's next listen connection, for rows quiet for an hour, and seals throughprocess_conversation.recovery_admission_refusalreturnsterminal_no_derived, becausetriggers.mark_newstampsterminal_no_derived_effectson every v3 recording. This holds for any crashed v3 socket today, not only for rotation.omi_listen_v3_rotation_total{outcome=rotated|same_row|create_failed|seal_failed|seal_retry|handed_off|other_owner}through the reason-enum core (RecordingRotationOutcome, familyrecording_rotation).Builder (
database/conversations_v3.py_mark_successor_pending). It applies only when the latest spoken recording carriesv3_rotation_cap_seconds, which only rotation writes. In that case it keeps the stretch open while a later recording is in progress under that cap + 15 s, or processing for under 15 min. With rotation off, no row has the stamp, and the builder behaves exactly as on main. The successor query is.select()over 8 metadata fields, limit 8, single-fieldstarted_atindex. It is registered in the query-shape drivers.Switches.
CONVERSATIONS_V3_RECORDING_ROTATION:off(default),cohort(members of thev3-recording-rotationrollout cohort) oron.rollout_cohortscollection. No uid goes in deploy source.deploy/runtime_env/_base.yaml(composedruntime_env.yaml) and both listen chart values files, asoff/180/300. They are also inconfig/feature-flags.yaml, the rendered registry anddeployment-setting-classification.json.Canary for one owner
backend/deploy/runtime_env/_base.yaml(gke backend-listen env) andbackend/charts/backend-listen/prod_omi_backend_listen_values.yaml, setCONVERSATIONS_V3_RECORDING_ROTATIONtocohort. Recompose withpython3 backend/deploy/compose_runtime_env.py, merge, then roll listen withgcp_backend_listen_helm.yml(environment=prod, branch=main, expected_sha, mode=deploy, image_tag). With an empty cohort this is still off for everyone.GCP_AGENT_TIER=prod-operator backend/.venv/bin/python backend/scripts/rollout_cohort.py --uid-file <file> --cohort v3-recording-rotation --project based-hardware --environment prod --add --applyIt takes effect within 60 s. To undo, use
--remove, or set the env back tooff.The image must contain this PR first:
gcp_backend.ymlmode=build-only, then the listen helm deploy. The builder change is inert until rotation stamps a row, so its deploy order does not matter.Checks
server_batch_audio_closedis not set while the socket is active (batch_close.py:46). With the reconnect flag off, late frames extended aprocessingrow's window. With it on,note_server_batch_audiorefused them and poisoneduncommitted. The new order makes it impossible for a frame to join the old row once its seal starts.tests/unit/test_listen_v3_rotation_custody.py, parametrized withLISTEN_BATCH_RECONNECT_ENABLEDoff and on.LiveAudioArchive(durable outbox on the hermeticremotebucket), the realnote_server_batch_audio/_receivedonStrictFirestore, and the real_rotate_v3_recording→finish_recording→process_conversation→close_batch_archive.uncommittedis empty; the archive did not fail; the old producer token is dropped._note_accepted_frame) only place live-STT transcripts, which batch-only sockets do not run. The custody ACK checkpoints per-channel frame sequence numbers, not conversation ids.started_atequals itsserver_batch_audio_start, which is the frame right after the sealed window, within one 10 ms frame of it.create_new_in_progress_conversationis a binding-equivalent stub. The real create path is covered by the continuation test below. It creates the server-batch row with yields that stand in for Firestore round trips, then switchescurrent_conversation_id.schedule_finalizationis stubbed to record the window and setprocessing. The full create path needs the recording-session, Redis and calendar stack and was not exercised.1b. Rotation on a phone socket, through the real create path (
tests/unit/test_listen_v3_rotation_continuation.py). This uses the repo'sCaptureHarness: the realcreate_new_in_progress_conversation, realresolve_live_continuationonStrictFirestore, andclient_conversation_id='original'.supersederemoved, the test fails withsealed == [].supersede_live_continuationrefuses a pointer owned by another generation and returnsabsentfor a missing origin.1c. What the phone does. The app parses
conversation_sessionasUnknownEventand ignores it (app/lib/backend/schema/message_event.dart).memory_processing_startedfor the retired recording. That is the same event and the sameprocess_conversation→schedule_finalizationpath a quiet seal uses today, so the quiet seal is the precedent.CaptureController.onMessageEventReceived(app/lib/services/capture/capture_controller.dart:4089) stamps the session's WALs with the recording id (_finalizeAndStampSession) and starts a new session.app/lib/pages/conversations/conversations_page.dart:411).memory_createdarrives only after GPU transcription, which takes more than 30 s. So the 30 s fallback runs_confirmSessionWalsRetained(..., failClosedReason: 'missing_conversation_event')and auto-syncs the retained WAL for every rotated recording, as it already does after each quiet seal.outline.stretchessplits only on a 5 min gap or a manual cut, so recording boundaries do not split a conversation.planner.windows/buildcopy lines in order across recordings. The finish rule is what could false-split: the commit clearsv3_pendingon an untranscribed live successor._mark_successor_pendinghandles that for rotation-sealed rows. Tests:test_untranscribed_successor_keeps_the_stretch_open(7 cases),test_a_recording_rotation_did_not_seal_keeps_the_five_minute_ruleandtest_rotated_recordings_stitch_into_one_stretch_in_order.batch_target_contains(utils/sync/live_overlap.py:105-131) refuses a piece that starts before a target, or ends after a sealed one. Prod sample, Nik, 2026-11-18, metadata only:e87bfed218:57→19:33 starts before4170f9cf, and09be1e39covers three recordings.80484b85against4170f9cf).on. The cohort canary should watch for these duplicates. Fleet-wide frequency was not measured: no collection-group index exists to query bridges across owners.recording is Trueplusserver_batch_ownedis required. Tests:test_legacy_row_never_rotatesandtest_off_is_the_old_lifecycle(unset,offand empty-cohortall keep the main lifecycle, including the quiet seal). The builder gate is the row stamp.test_a_calendar_meeting_does_not_block_v3_rotation). v3 conversations come from transcript windows, andcreate_new_in_progress_conversationre-attaches the active meeting to the successor.SPEAKER_0in recording N is notSPEAKER_0in N+1. The owner (is_user) and named people (person_id) are resolved per recording from embeddings (utils/conversations/speaker_resolution.py), so they stay consistent.recording_carrycopies manual speaker assignments into the successor. What breaks: unnamed voices get different S-numbers every 3-5 min inside one derived conversation, both in the copied transcript and in the outline input. The outline prompt already treats S-numbers as unreliable. Shorter recordings also give speaker resolution less audio per voice. That may lower wearer recognition, which v3 needs before it hides background talk. Not measured.Latency, from "conversation ends" to "derived row visible"
Related
David's lane: #25714 and #25659 touch the v3 store and service, not this
load()tail orlifecycle_loop. #25633 introduced SpeechClock.routers/conversations.pyget_live_conversationis not touched.Verification
test_cloud_run_metrics_egress_workflowfails on macOS bash 3.2 (empty array underset -u), andtest_rollout_cohortsflakes under xdist but passes alone. Neither touches these files. Earlier round: 3113 passed and 1 skipped across everyconversations_v3*,listen_*, archive, outbox, desktop-batch, cohort, runtime-env, flag and query-shape file, including the new custody and lifecycle cases.boundary_at, exact threshold boundaries, env tunables, cohort membership, and off equal to main.backend/scripts/typecheck.sh: 0 errors.scripts/pr-preflight --pr-body-file: green.quiet.arm/quiet.runrefuse it (test_a_rotation_orphan_is_left_for_listen_stale_recovery_not_the_quiet_check), andrecover_stale_in_progressseals it on a later connection (test_a_rotation_orphan_is_sealed_by_stale_recovery_on_a_later_connection);drain_rotations;_persist_policy_and_arm_quiet_checkleaves the pointer on the old row, and the retry moves it;own_idsacceptance;WebSocketExceptioncloses the socket;Line-Count-Exception: backend/routers/listen/runtime.py | 1576 -> 1578 | teardown drains retired v3 recordings before it handles the current row
Product invariants affected
Cited because
backend/deploy/runtime_env.yamlchanged. The change only adds three backend-listen env entries; memory intake and promotion are unchanged.Failure class (fixes)
Failure-Class: FC-transport-liveness-read-as-speech-activity
🤖 Generated with Claude Code