Skip to content

fix(finalization): admit a user finish inside the first archive window - #26213

Merged
kodjima33 merged 7 commits into
mainfrom
fix/finish-short-server-batch
Nov 24, 2026
Merged

kodjima33 merged 7 commits into
mainfrom
fix/finish-short-server-batch

Conversation

@kodjima33

@kodjima33 kodjima33 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

What changed and why

A Finish pressed in the first minute of a mobile recording did nothing. The app showed Processing, no summary arrived, and the row later disappeared.

Mobile captures are server-batch-only. The listen session marks server_batch_audio_received at the first audio frame and writes has_content only when a 60-second archive window commits. A user finish before that commit reached finalization admission with no transcript and no content marker, was answered no_content, and the request returned the recording unchanged. The recording stayed open until the socket closed or the quiet timer fired. A pendant keeps streaming, so that could take minutes or never happen.

Production readback (2026-11-24, one test account, synthetic speech over /v4/listen, then POST /v1/conversations with the socket held open):

Recording Answer to the finish Finalization job
37 s in_progress (ignored) capture_end, created only when the socket closed 20 s later
77 s processing client_finalize, created with the request

For the 77 s recording the session rolled over at once, committed the tail in 2.8 s, and the record sealed 4.4 s after the request. #26192 does not cover the short case: its manual-end marker needs a client_finalize job, and none was created.

The change:

  • Admission (_create_or_get_finalization_intent_txn): a client_finalize of a batch-owned row with server_batch_audio_received true, no committed audio, an open archive, no reconnect producer and at least 10 seconds of age is admitted. Every other trigger, and every other row, keeps no_content.
  • Worker (finalize_persisted_conversation): for that job it re-reads the row every 0.5 s for at most 30 s until the session has committed the audio, then registers the recording and closes the capture as before. A row that never gains audio keeps the existing ServerBatchArchiveNotClosed retry.

No new write: the session's existing rollover commit supplies the audio bounds. Cost is at most 60 extra row reads per early finish.

Rollout and rollback

It rolls out with the fast first transcript: CONVERSATIONS_V3_FAST_FINISH (default cohort, the v3-fast-finish runtime rollout cohort; on admits every owner; off stops it). With the default, nothing changes for an owner outside the cohort. CONVERSATIONS_V3_BATCH_MANUAL_END=off also stops it. A job admitted before either switch still completes.

Known limits, to settle before on

  • A row with a reconnect producer is not admitted early. note_server_batch_audio and close_server_batch_audio refuse a producer row once its status leaves in_progress, so the session could not commit the audio. The serving listen image predates LISTEN_BATCH_RECONNECT_ENABLED, so today's mobile rows carry no producer. When that image ships, this change stops applying to mobile rows until the fence lets the owning token write while the row is processing. The same fence would then refuse the tail of a finish after the first window; that is independent of this change.
  • The session commits with the next frame after the rollover, at the 60-second window, or at teardown. It does not commit on seeing the row leave in_progress (PUSHER_RECORD_CLOSE_NOTIFY_ENABLED is off). If frames stop while the socket stays open, the audio commits only at teardown and the job spends its retry budget meanwhile.
  • A POST /v1/conversations sent again more than 10 seconds after a finish can cut the successor recording.
  • The worker wait is keyed on the trigger and the row, not on the cohort. A non-member reaches it only if admission saw content that the worker no longer sees; the effect is the existing not-closed retry up to 30 s later.
  • In cohort mode a cold membership lookup (one Redis read and one point read, cached 60 s) runs inside the admission transaction, for a row that already passed the row checks, the age floor and the kill switch.
  • A wait that times out is a counted attempt. Before on, give it a non-counting retry reason.

Product invariants affected

  • INV-DATA-1
  • INV-CAP-1

How it was verified

  • New test_user_finish_first_archive_window.py: 20 passed. The admission cases run the real admission transaction and lifecycle reducer on StrictFirestore (which now models the transaction-bound photos.limit(1) probe as a read) and assert the queued job and the row's move to processing; a refused finish is asserted to write nothing. It covers the early admission, the rows that stay empty (no audio yet, closed empty archive, not batch-owned, legacy, reconnect producer, seconds-old successor, no creation time), non-user triggers, both switches, the cohort gate, the worker wait, the timeout, a natural end that does not wait, and a deleted row.
  • Neighbouring suites through backend/test.sh: test_conversation_finalization_jobs, test_server_batch_completion, test_listen_finalization_cloud_tasks, test_record_finalizer_discard_registration, test_record_finalizer_photo_registration, test_conversation_quiet_finalization, test_client_processing_finalize, test_conversation_smart_merge_finalizer and test_conversations_v3_fast_finish: all passed.
  • An independent review of the first revision returned FIX-FIRST. The producer guard, the age floor and the cohort gate answer its findings; the remaining ones are the known limits above. A second review of this revision returned SHIP with the gate at cohort.
  • The 37 s and 77 s production readbacks above were taken before this change. The 37 s case has not been exercised against real services with this change; that readback follows the deploy, on the owner account in the cohort.

Tests

backend/tests/unit/test_user_finish_first_archive_window.py.

Failure-Class: none

Line-Count-Exception: backend/database/conversation_finalization_jobs.py | 3750 -> 3754 | The early admission is decided inside the existing admission transaction, on the snapshot that transaction already holds; four lines on the existing no-content branch.

A live audio-only capture writes has_content only when a 60 s archive window
commits, so a Finish in the first minute was answered no_content and ignored:
the recording stayed open until the socket closed or the quiet timer fired.

Admit a client finalize when the live session already holds audio, and let the
finalization worker wait for that session to commit it before the batch handoff.
…kip producer rows and seconds-old successors

Review findings: a reconnect producer fences archive writes once the row leaves
in_progress, a repeated finish could cut the successor, and the change should
ramp from the owner account like the fast first transcript.
The fixture gains the transaction-bound photos.limit(1) existence probe as a
read, so admission's read-before-write ordering is enforced by these tests.
@kodjima33
kodjima33 merged commit 69ba4fa into main Nov 24, 2026
70 checks passed
@kodjima33
kodjima33 deleted the fix/finish-short-server-batch branch November 24, 2026 08:46
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