Repository navigation
v3: Finish a sealed recording before its first live window - #26288
Git-on-my-level merged 8 commits into
Conversation
Failure-Class: none Co-Authored-By: Codex <[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: e170dcadf7
ℹ️ 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".
Failure-Class: none Co-Authored-By: Codex <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e19a45697a
ℹ️ 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".
Failure-Class: none Co-Authored-By: Codex <[email protected]>
Failure-Class: none Co-Authored-By: Codex <[email protected]>
Failure-Class: none Co-Authored-By: Codex <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1f823dbe6b
ℹ️ 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".
Failure-Class: none Co-Authored-By: Codex <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1e13d2d95a
ℹ️ 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".
Failure-Class: none Co-Authored-By: Codex <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c073bdeb72
ℹ️ 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".
Failure-Class: none Co-Authored-By: Codex <[email protected]>
…4) (#26379) ## What changed and why Follow-up to #26344, which is now merged; the base is `main`. SCA-4434: about 1.5× as many long manual Finishes fit under the same daily fast-STT cap, and the cap stays strict. Before, a long pass (over 20 min) reserved `2 × planned + 30 s` at admission, so its one retry per chunk was paid for up front. At the 7,200 s default (`CONVERSATIONS_V3_FAST_FINISH_LONG_DAILY_SECONDS`), only one 30-minute pass (3,666 s) fit at a time, and about two fit in a day. Now: - **Admission** reserves `planned + 30 s` (each chunk once, plus the probe clip). Admission screening (`screen` / `room`) checks against the same amount. - **Each chunk retry** first reserves its own seconds on the pass's key, `v3_fast_finish:long_audio_seconds:<day>`. It uses the same `INCRBYFLOAT` with an immediate take-back over the cap, in one pipelined round trip on the existing bounded (1 s) client, and only on the retry path. The reserve runs only: - after the sticky privacy check and the stop check, - after a second check of the recorded denial, just before the reserve, - with at least 3 s (`RESERVE_MIN_SECONDS`) of the deadline left. - **When the reserve fails** (over the cap, Redis error or timeout), the retry is not sent. The chunk fails as a failed retry does, and the pass yields to batch through the existing path with outcome `retry_cap`. With under 3 s left, the chunk fails with its first error, as before. - **No audio is sent unreserved.** `_Sent` closes when the pass settles. After that, nothing more is sent or reserved, and a retry reserve that lands after the settle gives its seconds back. A settle can therefore only refund, never undercharge. - **Late reservation:** a retry whose reservation returns with under 1 s (`RETRY_SEND_MIN_SECONDS`) of the deadline left is not sent (`_Expired`, which counts as `deadline`). Its reserved seconds are refunded at settle. A retry's reservation can take about 3–4 s in the worst case (AUTH on a new connection, the health-check PING, the pipeline and the give-back). The admission reservation can take about 5 s, so it ends within `STOP_GRACE_SECONDS` past the deadline. The slot bound holds because every wait on these calls is bounded. - **Settle** works as before: it charges what was sent and refunds the rest, including a reserved retry that was never sent. - **Metric**: `omi_conversations_v3_fast_finish_total{outcome="retry_cap"}` is pre-initialised and kept by the existing GMP keep regex (`conversations_v3_fast_finish_total`). At 7,200 s, about three 30-minute passes fit a day, versus two, and two fit at once. The bound is unchanged. Ramp: move `CONVERSATIONS_V3_FAST_FINISH_LONG_PERCENT` 25 → 100 after the first 24 h readback of long-pass latency (first card within 60 s) and long audio seconds. Any cap raise is David's spend decision. Flag notes, the runbook and the change note say the same. This PR does not deploy, set any env or merge anything. ## Product invariants affected - INV-MEM-4: not affected. The preflight matches `backend/deploy/runtime_env.yaml`, which only #26344 changes, because it compares against `main`. This PR changes no deploy, memory or projection path, only `fast_finish.py`, its tests, docs and flag notes. ## How it was verified The worktree is on head `cbc8142a113`, which includes `origin/main` at `cb15ebd4fa5` (#26344 merged as `4e5dfdb1088`). All runs went through `omi-heavy`: - `test_conversations_v3_fast_finish_chunked.py` plus `test_conversations_v3_fast_finish.py`: 243 passed. With `test_real_clock_budget_ratchet.py` added: 254 passed. - `python -m testing.pipeline_lab scenario run --jobs 4 --repeat 2 --json --stt replay`: overall outcome `passed`. 12 of 13 scenarios passed and `finish_after_second_close` was xfail, as it is declared `expected_failure` (#26288). - Mutation checks, each run on both fast-finish files: - `_run` reading `_Sent` instead of `close()` fails the abandoned-chunk test. - Dropping the post-reserve time check fails the late-reservation test. - Replacing the 1 s minimum with a plain deadline check fails the 0.1 s-left case. - Removing `retry_cap` from the pre-init list fails the fresh-process test. - `scripts/check_feature_flag_registry.py`: OK. These are unit and lab results only. Nothing was deployed. ## Tests In `test_conversations_v3_fast_finish_chunked.py`: - Admission reserves `planned + 30`, and that is all the counter holds while the pass runs. - A retry reserves its own seconds before it sends. The counter equals admission plus that chunk's seconds at the retry's send. - With the cap set exactly to the admission amount, the retry is skipped, the outcome is `retry_cap`, nothing is written, and nothing beyond the reservation is sent. - A Redis error at the retry reserve skips the retry. - Two `_FleetBudget` instances (two processes) racing 40 takes on one counter keep at most the cap. A second process taking the last room makes the pass's retry `retry_cap`. - Settle refunds a reserved retry that was not sent (the pass stopped during the reserve). A retry reserve that lands after settle gives its seconds back. - A denial recorded by another check, a denial at the retry check, or a stop during the first request: no reserve. - A retry with under 3 s left reserves nothing. - Two 30-minute passes fit under 7,200 s at once, and three in a day; a fourth gets `long_cap`. - **`_run`-level:** three abandoned long chunks are held just before their send until `run()` has returned and settled. After that they make no provider call and charge nothing. The language probe cannot reach `add` after settle, because the pass waits on its resolution until the deadline and the probe rechecks the deadline before charging. - A retry whose reservation returns past the deadline, or with 0.1 s left, is not sent and is refunded. - Every outcome, `retry_cap` included, is pre-initialised at import. This is checked in a fresh process, so test order cannot create the label. All outcomes are also kept by the GMP regex. UI-Evidence: none -- backend only ## Failure class (fixes) Failure-Class: none 🤖 Generated with [Claude Code](https://claude.com/claude-code)
…s tail (#26419) ## Summary When Finish resolves to a live v3 window and a capture sealed after that window's last speech, Finish now also finishes that newer capture. Before, it cut only the window's tail. The bug was reproduced by pipeline-lab `finish_after_second_close` (#26389): 1. Recording A seals. 2. Recording B seals about two minutes later. B is a pendant or server-batch capture still waiting on its transcript, so no window lists it in `v3_recording_ids`. 3. The user taps Finish. A's window was still live: idle 125 s, inside `live.MAX_IDLE` = 2 h. So `finish_live_window` called `request_finish` on that window, which cut `members[-1]` = A. B got neither the manual-end cut nor a fast finish, and a short B stayed hidden under the Home word floor. The #26288 single-capture fallback and the #26361 named-window path both run only when no window is live. ## DESIGN **Reads and writes.** This changes only the live-window Finish transaction, with `CONVERSATIONS_V3_FINISH_NEWER_CAPTURE` on. - **Reads** (on top of main's window and tail-recording reads): - the existing `_recent_finish_sources` query: at most 8 documents, 1 billed read when empty; - when a newer capture qualifies, the account-deletion marker, then by path: | Path | Extra reads after the marker | | --- | --- | | Live-lane capture moved to | none | | Server-batch capture whose speech landed (`newer_recording_*`) | **B's native ledger, 1 read** (`_finish_capture` → `_native_projection_state`, since `newer_state` is None) | | Marked capture, pending-retry (a later tap on a still-requested batch B: `newer_already_requested` / `newer_consumed`) | **B's native ledger, 1 read** (same call) | | Stored both (`newer_dual_*`) | **2 ledger reads**: B's, plus A's when A is batch. A's is the read the tail cut always made, now ahead of both writes | | Selected, then declined | that path's ledger read; the tail's own batch ledger read is unchanged | Pinned by `test_server_batch_redirect_reads_the_capture_ledger_once`, `test_marked_pending_retry_reads_the_capture_ledger_once`, `test_stored_both_reads_each_ledger_once_before_any_write` (exact ordered read paths). - **Settlement:** none added. The Finish-to-visible sample is read from the derived row `settle_processing` already reads. - **Writes:** - **up to 2 documents** in the stored-both case: A's window-tail cut and B's recording-scoped request; - otherwise exactly 1, as before; - the Finish stamp (`v3_finish_requested`) rides in the write the transaction already makes, and the planner carries it in the derived-row write it already makes: **no added write**. - Off means the transaction is main's, plus the `tail` stamp in its existing write. - **Provider cost:** storing B's request makes B a fast-finish candidate. That adds at most one fast-finish pass per stored-both Finish, even when B turns out silent. - **Chunked (the default since #26344, production `on`):** each unit is split into chunks of at most 5 min with 3 s of overlap, sent concurrently. A B of up to 20 min (`MAX_SECONDS`) is a few prerecorded requests; the lab's 80 s B is one (STT 0 → 1). - **Chunking off:** one request per unit, at most `MAX_UNITS` (8), up to 20 min. - **Bounds:** - `CONVERSATIONS_V3_FAST_FINISH`: `cohort` by default, but production runs `on` for the services that serve Finish and admission, so the cohort does not limit it there. - A B over 20 min runs only for the long canary: `CONVERSATIONS_V3_FAST_FINISH_LONG_PERCENT` (25 in production) and `CONVERSATIONS_V3_FAST_FINISH_LONG_DAILY_SECONDS` (7200 s of such audio per UTC day across the fleet in production). That is the only fast-finish daily cap; a long pass reserves its planned seconds before any spend. - The shared funding gate (`fast_finish.funded` → `sync_admission(lane='batch')`): consent and the owner's funded STT plan allowance. **Production readback:** 1. `omi_conversations_v3_finish_no_pointer_total` by `outcome` for the `newer_*` and `newer_dual_*` labels, against the tail path's `cut` / `requested`. That shows how often Finish finds a newer capture and which branch it takes. 2. **The share of Finishes whose response target becomes visible within 60 s:** `omi_conversations_v3_finish_to_visible_seconds{path}` (`tail` / `newer` / `newer_dual`), `le="60"` bucket over `_count`, compared by path. One sample per Finish, at the response target's first visible manual-end settlement; kept by the sync scrape profile. 3. `omi_conversations_v3_finish_newer_declined_total{reason}`: how often a selected newer capture declined and the tail answered. ## Change - `database/conversations_v3_live.py` - `request_finish(..., newer_capture=False)` gets a new parameter. When it is true, the transaction runs the existing `_recent_finish_sources` scan after its two document reads and before any write. - `_newer_capture()` selects the capture. A capture qualifies when it: - is a sealed Listen capture; - ended strictly after the window's `finished_at`; - is not one of the window's sources; - carries `has_content` (a projection that landed empty clears it); - passes `_capture_ineligible(row, now)`: sealed within `RECENT_FINISH_AGE`, unclaimed, not marked for another window, not private, deleted, discarded, locked, merged, partial or upload-failed. The newest qualifying capture wins, as in `_latest_capture`. The account-deletion check (`_account_deleting`, shared with `_live_window_or_deleting`) runs before any write. - **B's speech has landed** (a live-lane capture with `has_finish_content`, or a batch capture whose projection landed): redirect only. B gets the recording-scoped cut or request through `_finish_capture`, and the response names B. Outcomes are `newer_recording_cut` / `newer_recording_requested`. - **B is a server-batch capture whose projection has not landed** (`_batch_speech_landed`). It may hold only silence: the session's last capture often does, after the quiet timeout seals A and the device stop seals B. The same transaction: - stores A's window-tail cut, exactly what main stores; - stores B's recording-scoped request. Both ledger reads come first. `_finish_window_tail` and `_finish_capture` take a pre-read `state=`, and StrictFirestore enforces the order in tests. The response names **A's window**, because the cut landed there. The outcome is `newer_dual_<tail outcome>`. - Silent B: A is cut at once, as on main, and B's request clears at whole-record completion. - Speech B: A is cut and B's request becomes B's own manual end, so B shows as its own card. - **Why not `has_finish_content` for batch B?** In production it is true for almost every batch capture right after creation. `create_in_progress_conversation` → `mark_new` stamps `v3_speech_landed_at` at creation (`utils/conversations/v3/triggers.py:61-69`), and audio custody sets `has_content` on any committed audio (`database/server_batch_audio.py:60`). So a batch capture's speech has landed only with its projection: `record_projection_revision` together with `has_content`. The lab, which creates captures through the product path, shows the same stamp. A test pins it: `created_stamp=True` fails if the check goes back to `has_finish_content`. - **The window-tail cut alone** runs unchanged when: - no capture qualifies; - two captures tie exactly on `finished_at`; - the scan is full with its oldest row still newer than the window; - `_finish_capture` declines or answers `already_empty`. It writes nothing in those cases. - **Retries never cut A twice.** - If A already carries this window's Finish (the stored-both case), the tail path answers (`already_cut` / `already_requested`) and B is not touched. - A capture an earlier recording-scoped Finish marked answers through `_finish_capture`, even if a window claimed it between taps. - If the marked capture can no longer answer (private, locked, deleted, discarded, merged, partial, upload-failed, or `_finish_capture` declines, e.g. an unavailable ledger), the **window tail is cut**. The app's `settleManualFinish` reads a 404 as "already closed", so a 404 would leave A uncut. `_finish_capture` writes nothing on those declines, so the tail cut's reads still precede every write. - A mark that resolved empty no longer holds the Finish. - Unmarked captures older than an active mark don't qualify. - `utils/conversations/v3/finish.py`: both live-window calls pass the switch. They are the empty body and a named window that is still live. `_acknowledge` counts the full label, then strips `newer_` / `dual_` to answer like the path that stored it. A window answer is what the app already settles on: `settleManualFinish` binds `_finishLiveId` to it (`app/lib/providers/conversations_v3_provider.dart:145-173`). - `config/conversations_v3.py`: `finish_newer_capture_enabled()` adds the kill switch `CONVERSATIONS_V3_FINISH_NEWER_CAPTURE`. It defaults on; off is exactly main. - `utils/conversations/v3/metrics.py`: pre-initialised labels in `omi_conversations_v3_finish_no_pointer_total`, apart from the tail path's outcomes, every one reachable: - `newer_recording_cut`, `newer_recording_requested`, `newer_already_cut`, `newer_already_requested`, `newer_resolved_empty`, `newer_consumed`, `newer_recording_ineligible` (account being deleted); - `newer_dual_cut`, `newer_dual_requested`, `newer_dual_consumed`, `newer_dual_already_cut`, `newer_dual_already_requested`, `newer_dual_already_empty`, `newer_dual_resolved_empty`. - `newer_already_empty`, `newer_batch_unavailable`, `newer_batch_disabled` could never be returned and are removed. A selected-then-declined capture counts in **`omi_conversations_v3_finish_newer_declined_total{reason}`** (`already_empty`, `batch_unavailable`, `batch_disabled`, `recording_ineligible`), once after the commit; the window tail still cuts and answers, counted as the tail's outcome. - **`omi_conversations_v3_finish_to_visible_seconds{path}`**, histogram, `path` ∈ `tail` / `newer` / `newer_dual`, buckets 5 s – 2 h. - **Finish-to-visible sample (no correlation store).** `request_finish` stamps `v3_finish_requested = {at, path}` in the first write it stores on the response target's source: the tail for `tail` / `newer_dual`, B for `newer`. In the stored-both case the tail's write is planned first (`_window_tail_plan`, no read or write), so B's request is stamped only when the answer names B; otherwise B rides along unstamped and B's own card never samples. Consuming cuts and `already_*` answers write no stamp, so a retried Finish keeps the first. The planner carries the stamp to the derived row that shows the cut (first stamp wins). `settle_processing` observes `now - at` once, at the row's first visible manual-end settlement (the `v3_manual_end_home_counted` transition), after the transaction commits; a stamp older than 2 h, a hidden row, or a re-settlement records nothing. `first_speech_to_visible_seconds` is not reused: it fires at row creation, and a live window's row exists before its Finish. `deploy/cloud_run_gmp_sync.yaml` keeps the histogram. - Pipeline lab (`scenario/ops.py`): at seal, the batch lane writes `has_content` with `server_batch_audio_end`, as production's `note_server_batch_audio` does in one transaction. `finish_after_second_close` now expects the answer to name A's window (`finish_response_names_a_window`) and B to be fast-finished (`b_fast_finished`, the check main fails). - Flag registry, contract paragraph in `listen_pusher_pipeline.mdx`, change note, Firestore query driver for `request_finish`. ## Verification All commands ran from `backend/` in the lane worktree, through `omi-heavy`. Base is origin/main `afab9560db2`. - **Scenario on main:** `finish_after_second_close` gave XFAIL. A was cut, B got no fast finish, reads 236. - **Scenario with the change:** PASSED. The answer names A's window; B fast finish `written`; B on Home. Reads 304, writes 74, no-op writes 12, STT 1, LLM 6. The budget is re-measured. - **Scenario with `"env": {"CONVERSATIONS_V3_FINISH_NEWER_CAPTURE": "off"}`:** same as main, at this head. Target A, `b_fast_finished` fails, 236 reads, 62 writes, 0 STT. - **All 13 committed scenarios:** passed. - **Unit tests:** `tests/unit/test_episodes_finalize_paths.py`, 154 passed; with the Firestore guard set, 1079 passed. - **End-to-end race test** (owners' request): `test_one_finish_cuts_a_at_once_and_consumes_b_once_across_resolution_and_retry`, parametrized by B landing with `speech` or `silence`. It runs entirely on StrictFirestore: 1. B is created through the real `triggers.mark_new`, so it carries the creation stamp. 2. Finish runs: one transaction cuts A and stores B's request; the answer names A's window. 3. B's projection lands (`replace_record`), then the real whole-record completion (`store.complete` → `_v3_finish_update`) runs twice. B's request is consumed once: B ends with `v3_manual_end` for speech, or the request is cleared for silence. 4. The same Finish runs again (same body and window id). It answers A's window with `already_cut` and no writes; A is cut once and B is requested once. With the retry guard removed, `[speech]` fails (the retry answers `capture-b`). `[silence]` still passes, because a mark that resolved empty no longer holds the Finish, so the retry reaches A's tail either way. - **Each new test fails without its own fix.** Mutation runs: - R1, no stored-both path: 12 fail; - R7, `has_finish_content` as the batch speech signal: 4 fail (`created_stamp=True`); - R2, ledger reads not hoisted: 4 fail (StrictFirestore read after write); - R3, stored-both retry guard removed: 3 fail; - R4, a blocked mark answers instead of a tail cut: 5 fail; - R5, a retry decline is a 404: 1 fails; - R6, the older-than-mark condition removed: 1 fails. The previous round's mutations (`has_content` gate, `already_empty` decline, newest-wins, deletion marker) still hold. - **Degraded-targeting telemetry counts once per Finish.** A tie or a full scan records `omi_fallback_total` (`conversation_finalization`, `newer_capture` → `window_tail`, `degraded`). `_newer_capture` only marks a per-attempt flag, reset at the top of the transaction body; `request_finish` records it once after the transaction commits. `test_live_window_finish_records_degraded_targeting_once_across_transaction_retries[tie|full_scan]` aborts the first attempt after the scan and before any write. With the recording back inside the body, both cases fail: "Called 2 times". - **Targeted set:** 43 files, 2597 tests passed: the changed tests, the Firestore guard set, every `test_conversations_v3_*`, `test_reliability_experiment_end_*`, `test_reason_label_enums`, `test_pipeline_lab_*`, `test_batch_pipeline_projection` and `test_server_batch_completion`. - `scripts/check_feature_flag_registry.py` OK. ### Review fixes (panel `review-20261127t015349-a22e`, F1–F5) - **F1** Finish-to-visible sample: `test_live_window_finish_stamps_only_its_response_target[tail|newer|newer_dual]`, `test_retried_live_window_finish_keeps_the_first_stamp[...]`, `test_consuming_cut_keeps_the_stamp_of_the_finish_that_stored_the_request[tail|newer]`, `test_finish_stamp_follows_the_cut_to_its_card_once` (planner, dual card), `test_finish_to_visible_is_observed_once_at_the_first_visible_settlement[...]` (re-settlement does not repeat), `test_finish_to_visible_drops_stale_hidden_and_unstamped_rows[stale|hidden|unknown_path|no_time|unstamped]`, `test_finish_to_visible_dual_card_samples_only_the_response_target`, `test_cloud_run_sync_scrapes_finish_to_visible`. - **F3** decline: `test_live_window_finish_counts_a_declined_newer_capture_and_still_cuts_the_tail[already_empty|batch_unavailable|batch_disabled|recording_ineligible]` and, separately, `test_live_window_finish_without_a_newer_candidate_counts_no_decline[none|older_than_window|silent]`; `test_newer_capture_finish_labels_are_reachable_or_absent`. - **F2/F4** read counts: the three exact read-sequence tests above. - **F5** `test_live_window_finish_cuts_the_tail_without_a_newer_finishable_capture` asserts on the retained `b` that neither `v3_manual_end` nor `v3_manual_end_requested` was written (and, for `none`, that B was not recreated). - Mutations: dropping the decline record fails 4; stamping B's request in the stored-both case fails 1. - Focused files (15), all passed at the earlier merged head (origin/main merged after main moved): `test_episodes_finalize_paths` 178, `test_conversations_v3_fast_finish` 115, `test_conversations_v3_contract` 119, `test_firestore_query_shapes` 644, `test_firestore_runtime_witnesses` 25, `test_conversations_v3_live_passes` 53, `test_conversations_v3_live_rederive` 129, `test_conversations_v3_created_delivery` 59, `test_conversations_v3_engine` 97, `test_conversations_v3_finish_late_predecessor` 33, `test_batch_pipeline_projection` 87, `test_pipeline_lab_scenario` 51, `test_monitoring_telemetry_contract` 58, `test_fleet_deployment` 11, `test_attach_cloud_run_gmp_sidecar` 117. - `python -m testing.pipeline_lab affected` → 15 scenarios, all passed, budgets unchanged (`finish_after_second_close` included). The full backend unit suite is left to CI. ## Lab vs production - **The final conversation shows `manual_end = no` in the lab.** The lab's native-completion stand-in (`batch_projection`) skips the projection transaction, so neither A's window-scoped request nor B's recording-scoped request is ever promoted to `v3_manual_end`. Production promotes them: at admission for a window-targeted single unit, at whole-record ledger completion for a recording-scoped request (`database/batch_pipeline_projection.py`, `whole_record_consumed`), as for the existing #26288 fallback. In the lab, A and B end in one conversation because no cut lands. - **#26344 interaction.** #26344 is merged into this branch (merge `4d2e913c`). Under its chunked fast finish and extended lab STT stand-in, `finish_after_second_close` still meets every check (`b_fast_finished: written`, STT 1 via `fast_finish`), now at 299 reads (was 304). ## Rollback Set `CONVERSATIONS_V3_FINISH_NEWER_CAPTURE=off` on the API service that serves `POST /v1/conversations`. That restores exactly main's Finish without a deploy; cuts and requests already stored stay. Or revert the merge commit. Product invariants affected: none Failure-Class: none 🤖 Generated with [Claude Code](https://claude.com/claude-code)
DESIGN
A sealed v3 Listen recording can exist before transcription or reconciliation creates its first derived window. After both active-recording lookups miss, only a request with no body fields may use the recording fallback. A body carrying a window ID, calendar context, client processing data, or any other field continues through the existing live-window lookup. The request and response schemas are unchanged.
After a live-window miss, the transaction reads up to eight masked recent source rows over five minutes. It then rechecks the same indexed two-hour live horizon with a masked query capped at 200 rows. It declines when either query reaches its cap or an eligible live window has appeared. The transaction can also read one account deletion marker and one native ledger and write at most one eligible, unclaimed recording. The source query uses the single-field finished time index, and the window query reuses the existing derived-window composite index. It adds no provider calls. A direct cut schedules at most one reconcile task.
A pending recording-scoped intent is consumed by the native whole-record completion transaction after its ready-sibling and privacy checks. This includes single-unit jobs when Finish arrives either side of the transcript write and ahead of ledger completion. The admission and provisional transcript paths leave recording-scoped cuts to this transaction. A pending batch accepts Finish when its archived audio bounds are valid, even if a silent unit cleared the projected content flag. Terminal silence resolves the intent without cutting unrelated speech. The window and recording paths return the existing
discarded: trueacknowledgement for terminal empty results when no other window member has speech. Shipped clients map that flag to their too-short-or-empty notice. Whole-record silence clears a pending recording-scoped intent and counts the asynchronous empty resolution for production readback. When a recording redirects, the same completion transaction clears the donor's request and counts it as terminal. The redirect proves custody but cannot establish a safe cut point inside the survivor's speech. Roll back API acceptance with CONVERSATIONS_V3_FINISH_NO_POINTER=off.Compare 404 share against 57/127 from the 2026-11-24 22:15Z to 2026-11-25 11:15Z request logs. Separate API acceptance (including
recording_requestedandrecording_cut) from the post-commitwhole_record_consumedandwhole_record_resolved_emptyoutcomes, terminalwhole_record_redirectedresolutions, and the derived window's firstsettledoutcome. Include the API'swindow_lookup_cappedcount separately. Compare on the same revision and time window after the pipeline has drained.What changed and why
Production request metadata shows 57 404s and 70 200s on the exact Finish POST across four backend revisions from Nov 24 22:15Z through Nov 25 11:15Z. Both image lineages contain #26242. Same-window GMP shows 10–11
no_live_windowand onealready_cut; the latter is a success. The remaining roughly 46–47 404s cannot be attributed from the available structured logs. All four revisions used v3 on and beta stage with the Finish kill switch unset. Eligibility exits had no counter and normal finalization can return a separate 404.The bounded source path lets an empty-body Finish succeed before the first derived row exists. The transactional recheck covers windows with delayed speech timestamps, and native completion consumes deferred intent once for both single-unit and multi-unit jobs. For redirected recordings it clears the original donor's marker in the ledger completion transaction and leaves the survivor's speech boundary intact.
Cost
Only a v3 empty-body live-window miss attempts the recording lookup. Only an eligible recent source incurs the full-horizon transactional recheck. The whole-record completion path reuses the source snapshot when a receipt names it. If the receipt already points elsewhere, it may add one masked read of the original recording. It still writes at most one Finish update.
Rollout and rollback
Deploy the API, native batch projection consumer, and v3 builder with the merged change. The existing API switch restores previous lookup-miss behavior. Use the per-outcome counter to separate expected eligibility misses from remaining live-window misses.
Product invariants affected
none
How it was verified
Focused route, batch, capture and settlement tests ran through
omi-heavy(507 passed). They cover body field rejection for the recording path with the existing window behavior preserved, both single-unit transcript/Finish orderings, a pending native batch with a silent first unit, post-commit metrics, first derived settlement, and the exact terminal-empty reply fields for both routes after silence or no recoverable speech. Flutter checksdiscardedbefore it checksrecording, so empty replies skip the processing page. A retry with a silent tail and earlier speech returns completed/done without the discard flag even when the repaired ledger is unavailable. The lifecycle writer guard passed 1,997 cases and the Firestore query shape suite passed 634 cases. Ten loopback Firestore emulator tests passed throughomi-heavy. They cover the source range, order, field mask and cap, a delayed window inserted by a second client, saturation of the window lookup, single- and multi-unit redirect completion with receipts pointing at the donor or survivor, and one-time completion metrics after both terminal silence and no recoverable speech. The workflow proof starts the Firestore emulator without an inherited sync stage. The fixture sets its stage explicitly. The query guard verifies index coverage. After the test import cleanup, the three affected unit files, the Firestore query shape guard, and the Finish emulator suite were rerun.Tests
backend/tests/unit/test_episodes_finalize_paths.pybackend/tests/unit/test_server_batch_completion.pybackend/tests/unit/test_conversation_archive_filter_contract.pybackend/tests/unit/test_batch_pipeline_projection.pybackend/tests/unit/test_batch_pipeline_live.pybackend/tests/unit/test_conversations_v3_fast_finish.pybackend/tests/unit/test_conversations_v3_created_delivery.pybackend/tests/unit/test_conversations_v3_live_capture.pybackend/tests/unit/test_lifecycle_state_table_writers.pybackend/tests/unit/test_firestore_query_shapes.pybackend/tests/integration/test_conversations_v3_finish_emulator.py(Firebase emulator)UI evidence
UI-Evidence: none -- backend-only change and existing response schema
Failure class (fixes)
Failure-Class: none
Line-Count-Exception: backend/database/batch_pipeline_projection.py | 1530 -> 1548 | The established completion transaction resolves recording intents with its existing sibling, redirect, and privacy fences.
Line-Count-Exception: backend/routers/conversations.py | 3199 -> 3203 | The route explicitly limits recording fallback to requests with no body fields.