Repository navigation
fix(listen): gate the drop hold on the reconnect switch again - #25599
Conversation
…anded stubs 9791f03 dropped listen_reconnect.enabled() from the teardown branch that holds a legacy capture open after a mobile socket drop. With the reconnect protocol off in prod nothing can end that hold, so since the 22:06Z 11-16 listen rollout every drop strands its row without a close barrier, and each reconnect rolls into another empty in_progress generation (~4.3k/h fleet). - Gate the hold on the switch again (off = finalize on drop, the pre-rollout behavior). - A live rollover seals and cleans the generation it displaces; sealing an archive that never committed a window clears the first-frame marker so empty cleanup admits it; the quiet check seals a producer-less empty capture at its deadline (from the incident lane's 67e7d3c, SCA-2773). - Stale recovery passes its cutoff: a producer-less server-batch row with no committed audio since the cutoff is treated as displaced, so empty stubs are sealed and deleted and stranded captures are finalized. Failure-Class: FC-kill-switch-keeps-the-gated-path 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: 967b053edb
ℹ️ 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".
| await self._finalize_isolated( | ||
| partial(self.process_conversation, displaced=True), conversation_id, stage='lifecycle_rollover' | ||
| ) | ||
| await self.create_new_in_progress_conversation(rollover=True) |
There was a problem hiding this comment.
Fence incoming frames before treating the current capture as displaced
During a live lifecycle rollover, this call marks the generation as displaced before create_new_in_progress_conversation() changes the capture target. receive_data() can therefore continue reserving and appending frames for this same conversation while close_batch_archive() flushes the archive and publishes its close barrier. The archive lock only protects the flush; it does not retire the receiver binding. This can admit empty cleanup while newly buffered audio remains uncommitted, or finalize committed audio before subsequent frames arrive. The existing recording-close fence is invoked by schedule_finalization() only after the barrier, and is skipped entirely for empty cleanup. Retire and drain the old frame binding before sealing it, rather than bypassing the live-target guard while it remains writable.
AGENTS.md reference: backend/AGENTS.md:L323-L323
Useful? React with 👍 / 👎.
| patch: dict[str, Any] = server_batch_audio.close_patch(row) | ||
| if listen_reconnect.end_due(row, now) and not listen_reconnect.enabled(): | ||
| patch[listen_reconnect.FIELD] = {**listen_reconnect.producer(row), 'phase': 'ended', 'deadline_at': now} | ||
| transaction.update(row_ref, patch) |
There was a problem hiding this comment.
Publish the close patch after the transactional storage proof
With QUIET_EMPTY_EXIT_ENABLED=true, an expired producer-less capture that already satisfies quiet_empty_candidate(row) now executes this write before calling empty_storage_proof(). The production proof in utils/conversations/quiet_finalization.py calls assert_batch_write_allowed(), which reads privacy documents using the same transaction; Firestore rejects those reads after a write. The proof catches that exception and returns false, so a genuinely empty archive cannot receive the proven_empty_storage exit and, with lifecycle V2 off, its check is retired as no_content without cleanup. Keep this patch pending until all proof reads have completed. The added quiet-check test does not expose this ordering failure because its fixture does not enforce transaction ordering.
AGENTS.md reference: backend/AGENTS.md:L232-L232
Useful? React with 👍 / 👎.
Panel review found the displaced-rollover sealing, first-frame marker clearing and stale-recovery sealing could seal a still-live capture, make rows with retained bytes deletable, or seal another socket's row without a lease fence. Remove them; keep only the re-gate of the drop hold on LISTEN_BATCH_RECONNECT_ENABLED, which restores the pre-22:06Z behavior. The existing hold test now enables the switch; a new case pins finalize on drop with the switch off. Failure-Class: FC-kill-switch-keeps-the-gated-path Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ehind the switch Panel review-20261117t124340-9f7e: amend the superseded switch-off contract sentences, keep the negative drop-hold guards exercised with the switch on, assert no hold side effects with it off, and name the lease renewal as the mechanism that kept held captures open. Failure-Class: FC-kill-switch-keeps-the-gated-path Co-Authored-By: Claude Opus 5.5 <[email protected]>
…quiet (#25633) ## Problem On batch-only sockets (all mobile pendant capture since Nov 2), a conversation never ended while the pendant kept streaming. These sockets run no live STT, so `lifecycle_loop` measured its 120 s quiet timeout from the last received audio frame, and a pendant sends frames even in silence. Separate conversations merged into one in-progress recording until the device disconnected. Prod evidence (2026-11-17): - One account: two conversations (1:09–1:30 PM and 1:33–2:43 PM NY) sat inside one recording that stayed `in_progress` from 1:06 PM for 1h43m and never appeared on Home. The device's own synced copies show the real boundaries: 2.5 min speech gaps at 1:30 and 1:33. - Fleet: 476 batch recordings had fresh audio. 142 of them (30%) had been open more than 1 h, and 16 more than 4 h. The audio-clock rule came in with ef2e2ed (2026-10-27, "route eligible platform capture to durable batch without live STT"). ## Change - `utils/stt/speech_clock.py`: per-socket `SpeechClock`. It runs the local Silero model that the VAD gate and sync segmentation already use (threshold 0.5, at least 3 consecutive 32 ms windows) over decoded audio, and records the wall time of the last sustained speech. Any model failure marks the clock failed and records a `vad` fallback. - `receiver.py`: batch-only sockets feed every decoded frame to the clock. Sockets with live STT are unchanged. - `conversations.py` `lifecycle_loop`: for batch-owned rows, quiet counts from `quiet_since(...)`: - **Last speech heard in this row.** The 120 s timeout now ends the conversation at real silence. - **No speech yet in a row this socket created.** The row stays open. Silence never closes an empty recording every 2 minutes. - **Row resumed from an earlier socket.** The resume counts as speech, so a reconnect cannot pin an ended conversation open. - **No clock or a failed clock.** The previous audio-clock rule applies. ## Cost - Real Silero on a 16 kHz sample fed in 20 ms frames costs about 6.4 ms CPU per audio second, roughly 0.6% of a core per stream. - This is inline on the receive loop, the same pattern as `VADStreamingGate._run_vad`. Prod listen runs that gate with `VAD_GATE_MODE=active`. - At about 476 concurrent batch sockets fleet-wide, the total is about 3 cores. - Windows and inference seconds go to the existing `record_vad_windows` metric, so the load is visible. ## Speech threshold The threshold and model are the ones the sync segmentation uses (`local_vad.segments_from_16khz_samples`, Silero at 0.5 on raw PCM). On 2026-11-17 that segmentation split this same pendant audio at the right places: 2.5 min gaps at 1:30 and 1:33 PM. Within the 70-minute conversation it found no 120 s gap. ## Validation - `tests/unit/test_listen_batch_speech_quiet.py`, 13 cases: - sustained speech vs a blip; partial windows and odd bytes; 8 kHz resampling; failure fallback; real Silero on silence; - the `quiet_since` rules; - `lifecycle_loop`: streamed silence after speech closes the row; recent speech, an all-silent row, a missing clock, a failed clock and a calendar meeting window keep it open, including a row created before its meeting started (the window counts from the last speech, since a live batch row's stored recorded_end is its creation). - Real model on recorded speech: first speech mark at 0.14 s, last at 19.98 s (speech ends at 20 s), nothing in the following 10 s of silence. - All listen, receiver, batch, VAD, quiet and local-preview unit files: 2127 passed, 1 skipped. - Prod baseline before the fix, on the same path the pendant uses (ios, source=omi, pcm16, one socket: 30 s speech, then 150 s of streamed silence frames, then 30 s speech): one conversation (074fe865), still `in_progress` afterwards, never cut. The same e2e runs again after the listen roll; it should give two. ## Deploy Listen only. Rides the next listen roll after the 22:00Z freeze, together with #25599 (re-gated drop hold, merged 13:51Z). The two are independent: #25599 makes a socket drop end the conversation; this makes streamed silence end it. ## Not in this PR - The time from cut to summary and the Processing row are handled separately. Line-Count-Exception: backend/routers/listen/receiver.py | 3064 -> 3072 | batch-only sockets feed decoded audio to the new speech clock; the logic lives in utils/stt/speech_clock.py ## Product invariants affected none ## Failure class (fixes) Failure-Class: new 🤖 Generated with [Claude Code](https://claude.com/claude-code)
…tates (#25607) ## What changed The exact requested runtime fix is already on the freshly fetched base: PR #25599, merged as `0ff616e7dfd23b14a1ff6da30019040aa445f665`. This follow-up strengthens its regression test rather than adding a duplicate gate. No serving code changes. The test now runs real `ListenSessionRuntime._teardown_components`, `LiveConversationController.disconnect_batch_producer`, `process_conversation`, and the archive-close helper. It retains the sibling test's mocked socket/cleanup harness, fakes persistence side effects, and mocks the `schedule_finalization` admission boundary. The same mobile batch capture is tested with `LISTEN_BATCH_RECONNECT_ENABLED` unset, `false`, and `true`, for iOS/Android and `omi`/`phone` sources. Unset/false must close the archive and schedule finalization once; true must flush the tail and skip scheduling. ## Mechanism and scope verification - Before #25599, `backend/routers/listen/runtime.py` took the `batch_disconnect == 'legacy'` / `resumable_after_drop(...)` arm without consulting the flag. That arm only flushed speaker assignments; it did not call `process_conversation` or `schedule_finalization`. It is an `elif` branch, not an immediate function return: later teardown cleanup still runs. - Current `runtime.py:1503-1505` already gates that arm with the real `config.listen_reconnect.enabled()` accessor (`backend/config/listen_reconnect.py:16`). The accessor defaults to false and enables only the normalized value `true`. - `backend/routers/listen/batch_close.py:12-38` requires quiet ownership, mobile platform, server-batch ownership, no explicit finalization reason, and a fresh `in_progress` row with `has_audio(...)`. That audio predicate requires `has_content` and finite, increasing audio bounds; `server_batch_audio_received=True` alone is insufficient. - Quiet admission **can** admit the stated committed-audio rows after their quiet deadline and recording-session lease expire, provided dispatch is configured and lifecycle/privacy/content guards pass. `evaluate_quiet_check` checks those conditions (`backend/database/conversation_quiet_checks.py:210-223,270-294`); `quiet_finalization.run` requests `SERVER_RECOVERY` finalization with an expired-lease requirement (`backend/utils/conversations/quiet_finalization.py:184-194`). The existing `test_quiet_check_finalizes_an_open_phone_batch_capture_with_committed_audio` exercises actual admission and job creation with no producer metadata or close barrier. A renewed live lease defers admission. The quiet evaluator publishes the batch close barrier only when `listen_reconnect.end_due(...)` is true, which a producer-less row cannot satisfy. - Desktop, non-legacy disconnect outcomes, and captures without audio keep their existing runtime behavior. This PR changes tests only. ## Validation From the task lane root, each test file in its own pytest process: ```sh /Users/dazheng/workspace/omi/bin/omi-heavy run -- backend/.venv/bin/python -m pytest backend/tests/unit/test_mobile_batch_disconnect.py -q # 28 passed /Users/dazheng/workspace/omi/bin/omi-heavy run -- backend/.venv/bin/python -m pytest backend/tests/unit/test_listen_batch_reconnect_grace.py -q --disable-warnings # 52 passed ``` Mutation proof: temporarily removed only `and listen_reconnect.enabled()` from the runtime branch and ran: ```sh /Users/dazheng/workspace/omi/bin/omi-heavy run -- backend/.venv/bin/python -m pytest backend/tests/unit/test_mobile_batch_disconnect.py -q --tb=short --disable-warnings -k 'schedules_finalization_only_with_reconnect_off and false' ``` All four explicit-false mobile/source combinations failed at `schedule_finalization.assert_awaited_once_with`: zero calls. Original runtime bytes were restored in `finally`; there is no runtime diff. `make preflight`: passed, 37 checks. PR metadata preflight: passed. The complete bounded pre-push hook also passed at commit `3a695d5c58b709d69a413b8385f4be93444bcb20` (including selected backend tests and pinned formatting). Local hermetic validation only. No production reads or writes, no GCP tier used, no deployment or merge. The supplied production metrics, flag state, and rollout timestamp were not independently remeasured. The scoping was stale about the missing gate: it is already fixed on current main. It also described the skip as a return; the actual branch continues with cleanup. Quiet admission is conditional, not structurally impossible for every row matching the hold predicate. ## Rollback Revert this test-only commit; serving behavior remains the #25599 gate. To restore the original runtime defect, reverting #25599's `and listen_reconnect.enabled()` line would re-enable the ungated hold; that is not part of this PR. <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/25607?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/25607?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F25607&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. -->
What broke
Since the 2026-11-16 22:06Z backend-listen rollout (235baea), mobile pendant captures pile up as empty
in_progressconversations: about one every 2 minutes per affected device.in_progressshare of finishedbatch_live_v1captures went from ~10% per hour to 51% in the 22:00Z hour, and 83–90% every hour since. That is ~4.3k new stuck rows per hour, ~45k so far. Measured with Firestorecount()aggregations at 11:11Z on 11-17.audio_files=[],server_batch_audio_received=True, no close barrier and no committed window.Why
9791f032ef5removedlisten_reconnect.enabled()from the teardown branch that holds a legacy (producer-less) capture open after a socket drop.LISTEN_BATCH_RECONNECT_ENABLEDis unset in prod.server_batch_audio_closed.Analysis: SCA-2773 (empty-transcripts incident lane), confirmed independently here.
Change
Re-gate the drop hold on
LISTEN_BATCH_RECONNECT_ENABLED.Tests are in
backend/tests/unit/test_mobile_batch_disconnect.py:Not in this PR
This PR does not close the rows the storm already left: the empty stubs, and the stranded captures that still hold audio. An earlier revision did, through rollover
displacedsealing, clearing the first-frame marker, and stale-recovery sealing. Panel reviewreview-20261117t120639-6aa7found that those paths could:They were removed. Cleanup will follow separately, with a lease and storage-proof fence.
Risk and rollback
Failure-Class: FC-kill-switch-keeps-the-gated-path
Line-Count-Exception: backend/routers/listen/runtime.py | 1570 -> 1576 | restores the reconnect-switch gate (import, condition and its reason) on the drop-hold branch; no new behavior is added to the file
🤖 Generated with Claude Code