Skip to content

SCA-4434: v3 Finish cuts a capture that sealed after the live window's tail - #26419

Merged
Git-on-my-level merged 19 commits into
mainfrom
lane/finish-newer-capture
Nov 27, 2026
Merged

Git-on-my-level merged 19 commits into
mainfrom
lane/finish-newer-capture

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

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 v3: fast finish long and multi-unit recordings in concurrent chunks (SCA-4434) #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

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

…s tail

A live v3 window idle inside live.MAX_IDLE made Finish cut its tail (A)
while a newer pendant or server-batch capture (B), still waiting on its
transcript and so in no window, got neither the manual-end cut nor a fast
finish. A short B then stayed hidden under the Home word floor.

request_finish now runs the existing bounded recent-source scan
(_recent_finish_sources, at most 8 documents) inside its transaction when
CONVERSATIONS_V3_FINISH_NEWER_CAPTURE is on (default). One sealed,
unclaimed, eligible capture newer than the window's finished_at takes the
recording-scoped cut through _finish_capture, and the response names it.
Two such captures decline as recording_ambiguous. A capture an earlier
recording-scoped Finish marked answers the retry, so A is never cut as
well. New outcomes newer_recording_cut and newer_recording_requested.

Removes the expected_failure from pipeline-lab finish_after_second_close
and re-measures its budget.

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

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T08:35:02.186640Z 5383aae New commits
ℹ️ 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.

…ins, retry checks)

- A newer capture takes the Finish only with has_content; one already known
  empty (already_empty) or declined keeps the window-tail cut, so a silent
  capture no longer swallows the cut on A.
- Two newer captures: the newest wins, as in _latest_capture; an exact tie
  cuts the window tail instead of answering recording_ambiguous (a 404 the
  app reads as already closed).
- A retry on a capture an earlier tap marked refuses it once it is private,
  locked, deleted, discarded, merged, a partial archive or a failed upload,
  and writes nothing. A mark that resolved empty no longer holds the Finish,
  so a second tap cuts the tail.
- The redirect reads the account-deletion marker before writing
  (_account_deleting, shared with _live_window_or_deleting).
- Every moved-Finish outcome counts with a newer_ prefix in
  omi_conversations_v3_finish_no_pointer_total, all pre-initialised.
- Pipeline lab: the batch lane writes has_content with server_batch_audio_end
  at seal, as production's audio custody does in one transaction.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4e5cfebb86

ℹ️ 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".

Git-on-my-level and others added 2 commits November 26, 2026 12:22
…pture

The session's last capture is often silence only (the quiet timeout seals A,
the device stop seals B). Audio custody sets has_content on any committed
audio and mark_new stamps v3_speech_landed_at at creation, so a silent batch
B took the whole Finish and A stayed uncut until B's batch completed.

When the newer capture is a server-batch capture whose projection has not
landed (_batch_speech_landed), the same request_finish transaction now stores
A's window-tail cut (exactly main's) and B's recording-scoped request, and
answers with A's window. Both ledger reads precede both writes
(_finish_window_tail / _finish_capture take a pre-read state). Counted as
newer_dual_<tail outcome>. A capture whose speech landed keeps the redirect.

Retries: when A already carries this window's Finish, the tail answers and
B is left alone. A marked capture that can no longer answer (ineligible, or
_finish_capture declines) now falls through to the tail cut instead of an
empty-id 404 the app reads as already closed. Adds the older-than-mark test
and fixes the change note's second-tap wording.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…gnal and cost

Adds test_one_finish_cuts_a_at_once_and_consumes_b_once_across_resolution_and_retry:
B created through the real mark_new (creation stamp), Finish stores A's cut
and B's request, B's projection lands and the real whole-record completion
consumes the request (speech, or silence), then the same Finish again. A is
cut once, B is requested and consumed once, and the retry answers A's window
with already_cut and no writes, all under StrictFirestore. Removing the
retry guard fails the speech case.

Change note: states the one-Finish-two-cards behaviour, why batch captures
use _batch_speech_landed rather than has_finish_content (mark_new stamps
v3_speech_landed_at at creation; a fast-finish provisional transcript never
sets record_projection_revision), and the provider cost: at most one
fast-finish pass per stored-both Finish, bounded by the flag and the funded
STT allowance.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 and others added 3 commits November 26, 2026 15:00
…ture

# Conflicts:
#	backend/docs/feature-flag-registry.md
#	config/feature-flags.yaml
…nish (#26344)

After merging #26344: fast finish is chunked by default (5-minute chunks
with 3 s overlap, sent concurrently), and a B over 20 minutes runs only for
the long canary (LONG_PERCENT, 25 in production) under the fleet-wide
LONG_DAILY_SECONDS cap (7200 s/UTC day in production). The change note no
longer says there is no fast-finish daily cap. finish_after_second_close
re-measured on the merged base: 299 reads, 74 writes, 12 no-op, STT 1 via
fast_finish, LLM 6; caps unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Copy link
Copy Markdown
Member Author

Verification for c75e13c

  • Focused backend unit file: 152 passed.
  • Bounded pre-push gate: passed; selected static and contract checks, plus 40 selected backend unit files, passed. Full suite coverage remains with CI.
  • Pipeline Lab affected set: 13 scenarios × 2 runs, all passed, using STT replay; no repeat mismatch. Per-scenario checks: audio_single_recording_finish 9/9; finish_after_long_reconnect_gap 8/8; finish_after_reconnect_late_transcript 8/8; finish_after_second_close 10/10; finish_cloud_audio_off 9/9; finish_double_tap 11/11; finish_next_opens_before_close 10/10; finish_no_closed_recording 9/9; finish_on_visible_conversation 10/10; finish_privacy_refused_fast_finish 8/8; finish_single_recording_fast 9/9; finish_transcript_never_lands 7/7; home_paging_past_hidden_runs 8/8.
  • At the CI snapshot, PR checks were queued or in progress.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c75e13c470

ℹ️ 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".

One Finish may end two cards: A's window is cut at once; if B lands with speech, B's request becomes its own
manual end. The response names A's window, and a retry answers the same target without writing.
"""
from utils.conversations.v3 import triggers

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Move the new end-to-end test's import to module scope

The previously reported helper and account-deletion imports have been moved, but the newly added end-to-end test introduces another function-local import here. backend/AGENTS.md explicitly requires “All imports at module top level — never inside functions,” including in backend tests. Move this triggers import into the module-level import block to complete the earlier correction.

AGENTS.md reference: backend/AGENTS.md:L168-L168

Useful? React with 👍 / 👎.

Git-on-my-level and others added 2 commits November 26, 2026 16:54
…tion

_newer_capture ran record_fallback inside the @firestore.transactional body,
which re-runs on contention, so one Finish could count its tie or full-scan
fallback once per attempt. The body now marks a per-attempt flag, reset at
the top of commit, and request_finish records the fallback once after the
transaction returns.

The new retry test aborts the first attempt after the scan and before any
write; with the in-body recording it sees two calls. The race test's
function-local triggers import moves to module scope.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve backend/utils/conversations/v3/finish.py against #26440 (SCA-2918
per-owner holdout): keep this branch's three-tuple request_finish with
newer_capture and the `capture or window` acknowledgement, and keep main's
named_only strict fallback for a named Finish beside a legacy row.

Main's holdout contract tests stubbed request_finish with the old two-tuple;
they now return (outcome, recording id, None), matching this branch's
request_finish contract.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8f41ed5fe9

ℹ️ 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".

if window is not None:
outcome, recording_id = conversations_v3_live.request_finish(uid, window['id'], now=now)
outcome, recording_id, capture = conversations_v3_live.request_finish(
uid, window['id'], now=now, newer_capture=newer_capture

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Disable newer-capture retargeting for strict named Finish

When a held-out owner has a legacy conversation in progress alongside a live v3 window, process_in_progress_conversation calls this helper with named_only=True specifically to finish only the named window. This call now enables newer-capture retargeting even in that strict mode: if an unclaimed capture sealed after the named window, request_finish can cut that unrelated capture and return before reaching the strict=True path below. This can leave the requested window unfinished or finish both targets for a pending batch capture. Disable newer-capture retargeting when named_only is true.

Useful? React with 👍 / 👎.

# Past a full scan, keep the tail cut rather than guess which capture is the newest.
if not capped
and not row.get(FINISH_RECORDING_FIELD)
and row.get('has_content') is True

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep partially transcribed batch captures eligible for Finish

When B is a multi-unit batch capture whose first projected unit is silent while another unit remains pending, replace_record sets has_content=False even though B still has retained audio and its native ledger is processing. The existing test_finish_accepts_retained_audio_after_first_native_unit_is_silent covers this state for the recording-only Finish path, but this new filter excludes B outright when A's window is live. Finish consequently cuts only A and never stores B's request, so speech arriving from B's remaining units does not receive the requested manual end. Allow pending batch captures with retained audio to qualify, and distinguish a partial empty projection from whole-record silence before excluding them.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deferring this as a non-regression follow-up. On main, Finish never redirects to B, so this PR introduces no case where B's request is lost. The recording-only Finish path (test_finish_accepts_retained_audio_after_first_native_unit_is_silent) still covers the partial-silent multi-unit capture. Telling a partial empty projection apart from whole-record silence in the live-window redirect filter will be its own change. Leaving this thread open.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up filed as SCA-5067 (Pipeline backlog), taken after this PR merges. It covers the regression test (silent first unit with another unit still pending, Finish stores B's request), keeping whole-record silence excluded, and a post-release check of the already_empty decline rate against a comparable baseline.

finish_live_window(named_only=True) promises to finish only the window
window_id names. With CONVERSATIONS_V3_FINISH_NEWER_CAPTURE on, the live
named-window branch passed newer_capture=True to request_finish, so a
holdout Finish could move the cut and its answer to a newer capture.
Pass newer_capture=False on the named_only path; other paths are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c6a2a0b479

ℹ️ 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".

Comment on lines +511 to +514
if row.get('data_protection_level') == 'private' or any(row.get(key) for key in _FINISH_BLOCKERS):
# It can no longer take a Finish. A 404 would read as "already closed" to the app; cut the tail.
logger.info('v3 Finish found its earlier capture no longer finishable; cutting the window tail')
return None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Instrument the retry fallback when a capture becomes ineligible

When a previously finished capture becomes private, locked, deleted, or otherwise blocked between taps, this branch redirects Finish to the older window tail but emits only an informational log. Unlike the corrected tie and capped-scan branches, it never appends to degraded, so request_finish skips shared fallback telemetry and counts the result as an ordinary tail cut. Mark this decision as degraded so the existing post-commit emitter records it once, including across transaction retries.

AGENTS.md reference: backend/AGENTS.md:L327-L327

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 319860b. The branch where an earlier finished capture is now private, locked, deleted or blocked appends to degraded, the same way the tie and capped-scan branches do. request_finish's post-commit _record_newer_capture_fallback() then records it once (conversation_finalization, newer_capture → window_tail, reason other, outcome degraded). The list resets on every transaction attempt. Tests: test_live_window_finish_retry_cuts_the_tail_when_the_finished_capture_cannot_answer asserts exactly one emission for each blocked state and none on the first tap's redirect. test_live_window_finish_records_degraded_targeting_once_across_transaction_retries[finished_capture_locked] asserts one emission across a simulated Aborted retry. Behaviour is unchanged.

Git-on-my-level and others added 6 commits November 26, 2026 21:58
Review panel review-20261127t015349-a22e, F1-F5 (SCA-4799 ruling).

F1: each live-window Finish stamps v3_finish_requested {at, path} in the
first write it stores on its response target's source (tail, newer, or
the tail alone in the stored-both case; B's request rides unstamped). The
planner carries the stamp to the derived row, and that row's first
visible manual-end settlement observes
omi_conversations_v3_finish_to_visible_seconds{path} once. Stamps older
than 2 h are dropped. Kept by the sync scrape profile.

F3: a selected newer capture that declines the cut counts in
omi_conversations_v3_finish_newer_declined_total{reason}; the tail cut
and its answer are unchanged. The unreachable newer_already_empty,
newer_batch_unavailable and newer_batch_disabled labels are removed.

F2/F4: document and pin the ledger read on the server-batch redirect and
marked pending-retry paths. F5: assert on the retained B row directly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	backend/database/conversations_v3_processing.py
…d Tasks graph

metrics imported FINISH_STAMP_PATHS from v3.live, whose config.conversations_v3
import reaches utils.cloud_tasks, so diarizer.batch_pipeline_runtime gained a
Cloud Tasks edge (test_gpu_batch_retry_cap_does_not_reach_cloud_tasks). Move
FINISH_STAMP_FIELD/PATHS/MAX_AGE to a dependency-free v3.finish_stamp module;
live re-exports them, so callers and behaviour are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6e0bc3ac71

ℹ️ 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".


def test_newer_capture_finish_labels_are_reachable_or_absent():
"""Every pre-initialised newer_* outcome is one request_finish can return; declines are counted apart."""
from utils.conversations.v3 import metrics

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Move the new test imports to module scope

The new metrics-label test imports metrics inside its function, and test_finish_stamp_follows_the_cut_to_its_card_once in backend/tests/unit/test_conversations_v3_engine.py:815 likewise introduces a function-local import. Although the previously reported imports have been moved, these newly added imports still violate backend/AGENTS.md's explicit requirement that all imports be at module scope. Move both dependencies into their respective module-level import blocks.

AGENTS.md reference: backend/AGENTS.md:L168-L168

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 319860b. test_newer_capture_finish_labels_are_reachable_or_absent now uses a module-level metrics as v3_metrics import (test_episodes_finalize_paths.py:38). test_finish_stamp_follows_the_cut_to_its_card_once now uses a module-level from utils.conversations.v3.live import ... (test_conversations_v3_engine.py:13). Neither adds an import edge: planner already imports live at module scope, and v3_finish already pulls in metrics. test_runtime_image_contracts.py passes.

# The newer capture was selected but declines the cut (already empty, batch unavailable or disabled,
# or ineligible): _finish_capture wrote nothing, so the tail is cut and answers. The decline is
# counted apart (FINISH_NEWER_DECLINED) once the transaction commits.
declined.append(outcome)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Emit shared fallback telemetry for declined capture cuts

When a selected newer capture's ledger is unavailable or batch manual-end is disabled, _finish_capture declines the request and this branch cuts the older window tail instead. It appends only to declined, so the post-commit code increments FINISH_NEWER_DECLINED without calling the shared fallback emitter. These degraded targeting decisions therefore remain absent from omi_fallback_total, contrary to the backend's new-fallback requirement. Also mark these declines as degraded and use the existing post-commit emitter so transaction retries do not duplicate telemetry.

AGENTS.md reference: backend/AGENTS.md:L327-L327

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 319860b. A selected newer capture that declines the cut now also records the shared fallback after commit, through the same _record_newer_capture_fallback helper: same component and newer_capture → window_tail modes, outcome degraded, with a reason label for each decline: batch_unavailable → unavailable, batch_disabled → dispatch_disabled, recording_ineligible → policy. already_empty emits nothing. That capture held only silence, so the window tail really is the last speech; this matches the resolved-empty retry, which also emits nothing. FINISH_NEWER_DECLINED{reason} is unchanged and still counts all four. degraded and declined can't both be set in one committed attempt, and the emitter is if/elif, so one Finish records at most one fallback. Retries reset both lists. Tests: the decline test asserts one emission per reason and none for already_empty. The retry test's [declined] case asserts one emission and one decline count across a simulated Aborted retry. The no-candidate test asserts none. Behaviour is unchanged.

Git-on-my-level and others added 3 commits November 27, 2026 01:01
…capture

# Conflicts:
#	backend/docs/feature-flag-registry.md
…lined cuts

A retried Finish whose earlier capture became private, locked, deleted or
blocked now appends to `degraded`, so the existing post-commit emitter
records it once (reason other), as the tie and capped-scan branches do.

A selected newer capture that declines the cut (batch_unavailable,
batch_disabled, recording_ineligible) now also records the shared
newer_capture -> window_tail fallback after commit, with reason
unavailable, dispatch_disabled or policy. already_empty stays a
FINISH_NEWER_DECLINED count only: a silent capture is not the last
speech, so the tail is the right answer. degraded and declined are
exclusive per committed attempt, so one Finish records at most one
fallback, and retries reset both lists.

Tests: the fallback is asserted once per Finish across a simulated
transaction retry for both new paths, and absent on the ordinary paths.
Function-local test imports move to module scope.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit 92e192d into main Nov 27, 2026
76 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/finish-newer-capture branch November 27, 2026 13:32
Git-on-my-level added a commit that referenced this pull request Nov 27, 2026
…apture)

Combine the deliberate-Finish SLI (SCA-4489) with Finish newer capture
(SCA-4434, #26419):

- finish.py: every live-window path passes observe_recording into
  _acknowledge alongside #26419's capture-or-window answer. The SLI binds
  before the newer_/dual_ prefix strip (deliberate_finish already strips
  it), so it binds the recording the answer names: the newer capture on
  newer_*, the window tail on newer_dual_*, tail and declined Finishes.
  That is the same response target that carries v3_finish_requested.
- conversations_v3_processing.py: settle keeps both the eligibility list
  and the Finish-to-visible sample, each reset per transaction attempt and
  emitted after commit.
- routers/conversations.py: main's wall-budgeted Home read moved v3_home
  into read_page; record it there and run the beta Home summary
  validation on the final projected (possibly truncated) page.
- Flag registry/yaml: keep both CONVERSATIONS_V3_FINISH_HOME_SLI and
  CONVERSATIONS_V3_FINISH_NEWER_CAPTURE rows.
- Test: the SLI binds the stamped response target on tail, newer,
  newer_dual and declined paths.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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