Skip to content

v3: Finish cuts the just-sealed capture a non-live named window points to (SCA-4385) - #26361

Merged
Git-on-my-level merged 3 commits into
mainfrom
lane/finish-named-sealed
Nov 26, 2026
Merged

Git-on-my-level merged 3 commits into
mainfrom
lane/finish-named-sealed

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

SCA-4385 / SCA-4084: a deliberate pendant Finish leaves no row and no card.

DESIGN

On iOS with a pendant, the app shows a processing row after Finish. The row then disappears, with no card. Production backend has answered about 1 in 8 Finishes with 404 Conversation in progress not found since 2026-11-25T18:00Z. Over 6 h, omi_conversations_v3_finish_no_pointer_total read owner_not_enabled 27, no_live_window 6, cut 1 and recording_requested 1. owner_not_enabled covers non-v3 owners and is left alone. The affected owner's pendant recordings are 4–90 s long and seal at speech pauses. None of their rows since 18:34Z carries v3_manual_end or v3_manual_end_requested.

Cause, confirmed in code (origin/main, serving build 6e3204f has the same path):

  1. The Flutter Finish (processInProgressConversationOutcome) sends {"live_conversation_id": <id>}. The id is ConversationsV3Provider.live.id, the derived v3 window from GET /v1/conversations/live. It is never a raw recording id.
  2. The capture seals at a pause, so the Redis pointer is gone. The window it fed can stop being live before the tap lands. It may finish (processing/writing), settle (done), or be hidden while open, and live.active rejects all three. live_window_by_id and request_finish therefore find nothing finishable, and no other window is live.
  3. finish_live_window returns no_live_window whenever window_id is set, so the request 404s. The recording fallback was unreachable for this body. It would also have refused anyway, because it requires an unclaimed recording and the tail is claimed by the named window.
  4. A finished window under the Home word floor is home_hidden unless it has manual_end (visibility.project). Short pendant windows therefore never reach Home.

Change. When the named window is not live and no other window is, request_named_finish runs one transaction:

  • It reads the named id with a field mask. For a derived window it reads that window's tail source; otherwise it treats the named id as the capture.
  • The named window must not be deleted, discarded, locked, merged (sync_merged_into) or private.
  • Newer sealed capture wins (review P2; delta P1). In the same transaction it scans _recent_finish_sources (at most 8, newest first). If a sealed capture (status == 'completed', recording is True) sealed after the named one, that newer capture is what the person just finished, and it is cut instead. An in-progress successor never supersedes. A speech-pause rotation writes the next capture in_progress, with a later finished_at, before it seals A (routers/listen/conversations.py), and at 8a489b4 that successor turned the main case back into a 404. The unnamed fallback's capture count uses the same sealed-only rule, so an in-progress successor no longer makes an empty-body Finish recording_ambiguous. Example: A seals and WA ends, then B seals 2 min later into WB, which stays hidden under the word floor and never goes live, so the app still names WA. If B is claimed, its one claiming window must list B as its tail. The transaction declines without writing when the newest capture is ineligible, claimed by several windows, not its window's tail (named_superseded), tied (recording_ambiguous), or past a full scan that does not contain the named capture (recording_lookup_capped).
  • The capture that is cut must be an omi/phone Listen capture, completed, sealed within RECENT_FINISH_AGE (5 min), and not private, deleted, discarded, locked, merged, a partial archive or a failed upload. A window tail must carry a claim by its window and no other. A bare capture must be unclaimed and unmarked, as today.
  • Completed visible window untouched (review P2). If the target window is completed and not home_hidden, the transaction answers already_visible with the existing card (completed/done) and writes nothing. Notes and title are not regenerated, and there is no processing row next to the card. The app upserts that answer over the visible card, so the window read also masks in structured, user_title and starred, and the answer goes through prepare_conversation_for_read after the transaction (the live tile's projection). The returned row therefore carries the card's title, overview, emoji and starring.
  • The transaction rechecks the two-hour live horizon (READ_CAP 200) and the account-deletion marker before any write. A live window that appears first still wins.
  • A window tail gets the existing window-scoped cut (_finish_window_tail, extracted unchanged from request_finish). It sets v3_manual_end, v3_pending and v3_finish_no_pointer_window_id=<window>, or the deferred batch request. The planner then re-derives the locked window with manual_end, so it is Home-visible and re-noted. A bare capture gets the existing recording-scoped cut (_finish_capture, extracted unchanged from request_recording_finish). Naming a capture resolves two recent captures that the unnamed fallback reports as recording_ambiguous.
  • {"live_conversation_id": null} is treated exactly like {}.
  • If the name resolves to nothing, a body that carries only live_conversation_id (ProcessConversationRequest.finish_only_body) may use the existing single recent-capture fallback. That body is the Flutter Finish. A body with any other field (calendar_meeting_context, client_processing, unknown keys) keeps the previous rule. Empty-body behaviour is unchanged.

Reads and writes per Finish (R19). Only a v3 Finish whose named window is not live takes this path, and it runs at most two transactions.

  • Named transaction: 1 named doc, plus at most 2 by-reference reads (the tail, or the later capture's window); at most 8 recent sources; at most 200 windows on the live horizon; 1 deletion marker; and 1 ledger doc for a batch capture. An already_visible answer adds the live tile's read projection of that one window, as GET /v1/conversations/live does.
  • Fallback transaction (Flutter body only, after a refused name): at most 8 recent sources, 200 windows, 1 deletion marker and 1 ledger doc.
  • Writes: each transaction writes at most one recording and enqueues at most one reconcile. A completed visible window writes nothing.
  • No provider calls.

Production number. omi_conversations_v3_finish_no_pointer_total{outcome="named_recording_cut"|"named_recording_requested"} counts recoveries. already_visible counts Finishes answered with an existing card. named_not_finishable and named_superseded count the remaining attributable 404s. Expect Finish 404 share for v3 owners (excluding owner_not_enabled) to fall from ~1/8, with no_live_window replaced by these labels.

Rollout and rollback

Ship on. CONVERSATIONS_V3_FINISH_NO_POINTER=off on the API service still restores the lookup-miss 404 for the whole no-pointer path. Rollback is a revert. The code path only widens a 404 branch and adds no schema, index or response-shape change. The new labels are pre-initialised. The metric name is already in the GMP keep regex (backend/deploy/cloud_run_gmp_sync.yaml), so no regex change is needed.

Done check

The affected person's next pendant Finish leaves v3_manual_end=True (or v3_manual_end_requested=True for a batch-pending capture) on the sealed recording, a Home-visible window with manual_end, and a named_recording_cut/named_recording_requested increment on the serving revision.

Product invariants affected

none

How it was verified

All runs used omi-heavy on lane/finish-named-sealed:

  • tests/unit/test_episodes_finalize_paths.py: 104 passed. Without the first commit's finish.py change, its 13 new cases fail. On 6dd3c34, the 7 review cases fail: A-then-B, unproven later capture, and completed-visible. On 8a489b4, 4 delta cases fail: the in-progress successor, empty and with speech, on the named and empty-body paths, and the visible card's title, overview and starring.
  • Firestore emulator suite tests/integration/test_conversations_v3_finish_emulator.py (firebase-tools, emulators:exec --only firestore): 15 passed. New cases:
    • A then B: WA named, B in hidden WB cut, A untouched.
    • In-progress successor, empty and with speech: A is cut.
    • Two sealed captures tied after A: recording_ambiguous, no write.
    • Completed-visible: no write, and the response carries the card's structured title, overview, emoji and starred.
  • Related set through test.sh with BACKEND_UNIT_TEST_FILE_LIST: 20 files and 3,705 tests, all passing. It covers batch pipeline live/projection, server batch completion, v3 contract/fast-finish/created-delivery/live-capture/late-predecessor, reliability end_* experiments, client processing, calendar, lifecycle writers (2,012) and Firestore query shapes (636, with the request_named_finish driver over a named window and a named capture).
  • Not run: the full unit suite (CI's job).

New cases:

  • A named window that is writing, done or hidden-live, with a just-sealed tail, gives named_recording_cut. The tail gets v3_manual_end, v3_pending and the window marker, triggers.enqueue_pending(manual_end_id=tail) runs, and a retry answers already_cut with no write.
  • A named raw capture gives named_recording_cut with the recording-scoped marker.
  • Two recent captures: an empty body still 404s (ambiguous), and naming one cuts exactly that one.
  • A then B, naming WA: B is cut (window-scoped when B is in WB, recording-scoped when B is unclaimed), and A is untouched. Declines with no write when B is private, claimed by two windows, not WB's tail, or tied with another capture.
  • A completed window with home_hidden=False gives already_visible (completed/done) with the card's title, overview, emoji and starred, and no write and no enqueue.
  • An in-progress successor written at A+2s, empty or with speech, still cuts A (named path). An empty-body Finish also cuts the single sealed capture beside an in-progress successor.
  • Retrying on the newer-capture path cuts once. Claimed B answers already_cut. Unclaimed B answers already_cut from the recording-scoped marker, and so does an unclaimed B that a hidden window claims between the taps (the v3_manual_end early return). There is no second write or enqueue.
  • {"live_conversation_id": null} cuts like {}.
  • Still 404 with no writes: a stale (>5 min) source, private, deleted, a deleted, private or merged window, a tail with no claim, a tail also claimed by another window, a live window appearing in the transactional recheck (no_live_window), and account deletion pending.
  • A name-only body whose window is missing falls back to the single capture. A name plus another field keeps the 404 (named_not_finishable).
  • The existing tests for empty-body fallback, live-window Finish, explicit owned window, and foreign or stale hints still pass. Two assertions changed. The foreign-owner case now asserts no writes instead of no transactions, because the name is read in a transaction. The hinted refusal case now carries a second body field.

Tests

  • backend/tests/unit/test_episodes_finalize_paths.py
  • backend/tests/unit/test_firestore_query_shapes.py
  • backend/tests/unit/test_lifecycle_state_table_writers.py
  • backend/tests/unit/test_batch_pipeline_projection.py
  • backend/tests/unit/test_server_batch_completion.py
  • backend/tests/unit/test_reliability_experiment_end_open_conversation.py
  • backend/tests/integration/test_conversations_v3_finish_emulator.py (Firebase emulator)

UI evidence

UI-Evidence: none -- backend-only change, existing response schema

Failure class (fixes)

Failure-Class: none

🤖 Generated with Claude Code

…oints to

A pendant capture seals at a speech pause and its window stops being live
before the Finish tap lands. The app names that window, so the request
skipped the recording fallback and returned 404, and the short window stayed
hidden. Finish now reads the named window's tail (or the named capture),
applies the recording-Finish checks within RECENT_FINISH_AGE, rechecks the
live horizon and deletion marker, and stores the cut. A body naming only the
live window may also use the single recent-capture fallback.

SCA-4385, SCA-4084.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-26T03:34:35.512657Z
We couldn’t complete this review. Comment @codex review to try again.
6dd3c34 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

Git-on-my-level and others added 2 commits November 25, 2026 22:57
…e windows

Review of #26361. A capture that sealed after the named window's tail is the
speech the person just finished (its window can stay hidden and never go live),
so the named Finish now scans the bounded recent sources in the same
transaction and cuts the newest capture, declining when it cannot be told
apart. A completed window already on Home answers already_visible and writes
nothing instead of regenerating its notes. The named window must not be
private or merged, a window tail must carry that window's claim, and a null
live_conversation_id behaves like an empty body.

SCA-4385, SCA-4084.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… keeps the card

Delta review of #26361. A speech-pause rotation writes the next capture in
progress, with a later clock, before it seals the one the person finished, so
counting it made the named Finish decline (named_superseded) and the unnamed
fallback ambiguous: the 404 this change set out to remove. Only completed
recordings now supersede or compete. The already_visible answer reads the
card fields and goes through the live tile's read projection, so the row the
app upserts over the visible card keeps its title, overview and starring.

SCA-4385, SCA-4084.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit 292af04 into main Nov 26, 2026
75 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/finish-named-sealed branch November 26, 2026 04:48
Git-on-my-level added a commit that referenced this pull request Nov 26, 2026
Resolve conflicts with the named-window Finish (#26361), the
end_open_conversation End cut and the moved v3 live Finish code:

- finish.py: keep main's named Finish, _recovered and outcome sets; the
  deliberate-Finish observer now also fires on the named path. Outcomes
  are matched after stripping named_/newer_/dual_ prefixes, so named_*
  counts now and newer_*/newer_dual_* (#26419) will once that lands.
- outline.py: keep main's owner-level cuts and ends(); cut sources are
  looked up per cut instant, and an owner End cut carries the recording
  marks it answered.
- service.py: _reconcile_groups is async and loads main's owner cuts.
- routers/conversations.py: keep main's ended_at/Response params, End
  answer and finish_only_body; bind the Finish alongside them.
- app: send X-Omi-Ended-At and X-Omi-Finish-Cut together; regenerate
  the perf production shell hash.
- Replace a stale delivery test that patched a removed import with a
  direct test of the Home-projection summary observer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Git-on-my-level added a commit that referenced this pull request Nov 27, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant