Repository navigation
fix(notes): a sealed mobile recording gets notes right away, not after a 10-minute quiet wait - #25538
Merged
Merged
Conversation
…r a 10-minute quiet wait A batch-owned live recording reaches the server over the live socket, so the server's own seal proves it ended. Hold admission now treats a completed batch_live_v1 row with a closed record barrier and a projected record transcript, before its first notes, as end-proven (outcome end_proof, proof result sealed). A pendant or phone copy that lands after notes keeps the quiet wait and gets at most the one automatic late run. Pure sync uploads keep the quiet rule. Same SYNC_UPLOAD_WATERMARK_ENABLED kill switch; no reads or writes added.
…as landed Review of the seal proof: record_projection_revision counts projected units (one per hour of audio), so a revision of 1 is not a finished transcript. The proof now also requires the capture's pipeline ledger to show the transcribed stage, which is written only after the record's whole projection completes, at or after the latest record_sealed_at. A reseal keeps the quiet wait because the ledger never moves back. Only rows that pass the row barrier read the ledger (one document). The projection completion path, which runs only after every unit is ready, requires the job to carry the row's current upload revision and records the sealed metric after commit, once per proof. A reopen between admission and the summary run is fenced by the existing first-summary updated_at precondition; a test pins it.
kodjima33
added a commit
that referenced
this pull request
Nov 17, 2026
…lands (#25635) ## What changed and why Goal: a recording's summary within about a minute of it ending, with the existing Processing row shown meanwhile. For a batch-owned mobile live recording (`batch_live_v1`, `server_batch_only`), four things held the first summary back or hid the row. This PR removes all four. It adds no new user-visible concept and no flag; it shares the `SYNC_UPLOAD_WATERMARK_ENABLED` kill switch with #25538. 1. **Deadline wait after a complete transcript.** Production runs with `RECORD_NOTES_EAGER_ENABLED=false` (backend-integration and backend-sync, read back today). So the record's units marked notes on the main settle path (`database/batch_pipeline_projection.py:483`, due +600 s). Dispatch then waited for the 120 s first-summary deadline (`utils/enrichment/outbox.py:475`), even after the record's last unit landed. - Fix: when the record binding completes, `ProjectionStore.complete` moves the row's existing open notes obligation to due now, inside the completion's commit transaction. After that commit it writes the ledger's `transcribed`, and only then wakes the obligation. - This also fixes a latent ordering race: the old code woke notes before writing the `transcribed` stage that the woken callback's seal proof reads. 2. **One held unit blocked the first notes for about an hour.** A unit whose ASR came back empty is quarantined for recovery. That keeps the binding's `complete()` open (`batch_pipeline_projection.py:849`), so the ledger never gets `transcribed`, and #25538's seal proof (`utils/sync/capture_end.py:248-255`) returns `units_pending`. The callback (`utils/enrichment/callback.py:125`) then fell back to the 600 s sync quiet wait (`utils/sync/processing_hold.py:20,201`). That wait restarts whenever a phone copy or a released bridge piece merges in (`utils/sync/assignment.py:980`). - Fix: `hold_for_quarantine` already reads every sibling in one transaction. When every unit is projected or held for recovery and the row passes `seal_barrier`, it: - stamps `sync_processing_hold.units_settled_seal_at = record_sealed_at`, and only on rows that already have a hold state; - moves the obligation to now in the same transaction, and wakes it after commit. - Both wakes (here and in `complete()`) are fail-open, like `_rearmed`. An exception is logged and left to the outbox sweep. It never fails the unit job, and in `complete()` it never skips `_mirror` or `_settle_allowance` after the durable commit. - `seal_proof` returns `units_held` while the stamp equals `record_sealed_at`; the metric outcome is `sealed_held`. A reseal invalidates the stamp. - A unit that is still transcribing (not quarantined) keeps the existing wait, so the first summary never fires halfway through a projection. - **Accepted tradeoff:** a held unit that recovers after the first notes is late content and follows the existing late-run rules (`immaterial`, `late_cap`, at most one material late run). So its text can land in the transcript while staying out of the notes. In `debba5b8` that unit held 4 words. 3. **Summarized rows hidden for up to 2 h.** The processing write merges maps (`database/conversations.py:1378,1745,1747`), so the stand-in's `structured.title_provenance='server_minimum'` outlived the real notes. `is_settling_fragment` (`utils/conversations/fragment_visibility.py:196`) then kept the summarized row off `GET /v1/conversations` until 2 h after its end. This was reproduced on a sync piece reprocessed today. - Fix: when a processing write carries real notes and omits the marker, `summary_delivery.merge_result` (called by both writers) deletes it (`retires_title_marker`). 4. **Home: a row with speech never disappears, and every read agrees.** - **Where prod Home reads today:** the prod `backend` service runs `HOME_FEED_ENABLED=false` and no `OMI_INDEXED_LIST_READS_ENABLED`, and `EPISODES_ENABLED=off`. So prod Home is `GET /v1/conversations` (`routers/conversations.py:1164-1189`), which classifies full rows. That path already saw the row-level `summary_title_provenance`. The compact feed (`database/home_feed.py:338`), the slim list select and the episode member read classify a field mask that never loaded it (`utils/conversations/home_titles.py:26`). - **Change 1:** that field is now loaded, so those paths match the full-row list. For example, a projected batch row that owes notes shows the existing "Processing… · Writing notes…" row. No effect in prod until one of those paths is enabled. - **Change 2, the settled Home rule:** a row whose only stand-in marker is the row-level one, with no debt, no summary and **no `summary_blocked_reason`**, is now classified `ready` (a finished card), not `noise` (which both app paths hide: `home_rows.dart:376`, `home_card_rows.dart:29`). - Only `stamp_projection_debt` marks the row alone, and only when projected transcript text landed (`live_projection.py:150-157`). So these rows always carry speech. - They occur when the projection lands past the repair age gate, or when a later write clears the debt. - Rows that truly owe notes still show Writing notes. A row with real notes is `ready`. - These stay `noise`: - an intake stand-in (`structured.title_provenance`, e.g. "Mm-hmm.") with no debt; - a blocked row: `local_only` (including `terminal_no_derived_effects` and deferred), `blocked_byok`, and `empty_output_exhausted` even with `HOME_EMPTY_OUTPUT_NOISE=false`. - **This reverses the "hide" half of 50d85f5's expectation**, limited to unblocked rows carrying projected speech. The other half, never presenting "Writing notes" forever, is kept. The `stamp_projection_debt` docstring and the renamed age-gate test now say this. - **Measured, read-only:** last 7 days, Nik plus 30 randomly sampled batch owners, 10,540–11,350 non-deleted rows, current prod flags. **0 rows** flip from visible to `noise` with the new field mask, and **0 rows** reach the provisional branch's `noise`. - **Limits of that measurement:** it covers only those sampled owners, not every user. It also cannot cover a flag flip, such as enabling the feed, the indexed list reads, or setting `HOME_EMPTY_OUTPUT_NOISE=false`. The blocked-row tests pin the classification for those cases instead. - **Not changed here:** prod rows that are `noise` today all come from other branches. 1,128 are `empty_output_exhausted` (16 of them with a nonzero word count; Nik's 12 have none) and 24 are below the content floor. Those are a separate "missing from Home" candidate. ## Prod timeline (read-only Firestore, ledger, batch job docs and Cloud Run logs, 2026-11-17 UTC) `debba5b8` (36 min recording, 8 record units, sync live target with one phone piece merged): | Step | Time | Wait | Where | |---|---|---|---| | Cut (end observed) / audio end | 18:06:05 / 18:06:07 | | listen | | Record sealed | 18:06:11 | 6 s | `record_sealed_at` | | Intake claimed → compute admitted | 18:06:15 → 18:06:54 | 43 s | batch jobs `record_intake_claimed_at`, `compute_decision.at` | | STT ready, 7 of 8 units | 18:07:11 | 17 s | job `ready_at` | | Unit `d7ce8acf` (92 s audio, 3.5 s VAD speech) `worker_failed`/`empty_asr`, quarantined | 18:07:11 | | job `quarantine_reason` | | Results committed (ordered merge) | 18:09:03-06 | 114 s | result `committed_at` | | Text persisted on the row | 18:09:57-18:10:25 | 52-80 s | `projection.persisted_at` | | Notes obligation opened (per-unit marks) | 18:10:52 | 27 s | `summary_first_pending_at` | | Released bridge piece / phone copies merged; quiet clock restarted | 18:06:26, 18:12:38 | | `sync_merged_from`, hold `last_content_at` | | First-summary deadline run → deferred `quiet_wait` (seal proof `units_pending`, no ledger `transcribed`) | 18:13:09 | 137 s | outbox `deferred_since`/`deferred_reason` | | Quiet due | 18:22:38 | 569 s | `processing_hold.py:201` | | Enrichment request started → summary written | 18:23:26 → 18:24:54 | 48 s dispatch + **88 s processing** | backend-integration request log | | Held unit's recovery started → projected → binding complete | 19:08:56 → 19:12:15 | ~62 min held | job `recovery.prepared_at` | - Before: cut → summary **18.8 min**. - After (same row, projected): the last unit's mark at 18:10:52 stamps the seal and wakes notes now, so the summary lands at about 18:12:20 (dispatch plus the 88 s processing). That is about **6.3 min** from cut, and about 90 s after the transcript became complete on the row. - A row with no held unit gains the 120 s deadline back. Measured on `6c2a7917`, ledger `noted − transcribed` = 137 s before this change; it becomes processing time only. Other rows: - `604bd874`: summary at 17:25:54, 18 s after its seal at 17:25:36. The cut came at 17:25:34, 2 min after audio end at 17:23:35, from the listen silence cut that a parallel listen PR shortens. Because of that 2-minute lag, the quiet window had already passed by the seal. This summary was built from merged phone content; notes were rewritten at 17:45:32 after the record landed. - `6ccc2ca6` (pure `sync_vad` piece): summary at 17:40:52, which is quiet due (last content 17:29:41 + 600 s) plus 71 s. That is the phone-upload quiet rule, unchanged here. - Sync pieces `5731e148` / `c35a2059`: held by `pending_live_bridge` for as long as live target `c92384c3` is `in_progress`. - The callback re-polls every 30 s (`utils/sync/bridge.py:395-433`), and hourly after 6 h (`utils/enrichment/outbox.py:69`). - On the first poll after the target leaves `in_progress`, `_finish_pending_live_bridge` (`bridge.py:196-244`) merges a piece into the live row when `choose_live_overlap` picks it and the piece has no notes. Otherwise the piece is summarized on its own, under its own hold. - A merge restamps the live row's quiet clock. That restamp is exactly what this PR's seal proof now overrides for the first notes. - So bridge release adds at most about 30 s plus one dispatch. ## Not changed / not verified - **Batch STT pipeline time.** Seal → transcript complete on the row took 4 min 41 s here: 43 s intake and admission, 114 s ordered merge, 52-80 s projection, 27 s finish. "Summary under 1 min after the recording ends" is not reachable until those stages shrink. - **Processing time.** The LLM notes step alone took 88 s (this 36-min recording) and about 100 s (a 21-min reprocess). That bounds what "within a minute of transcript ready" can mean. - **Quarantine recovery.** Recovery of an empty-ASR unit took about 62 min to start. Untouched here; the held unit now only arrives as late content. - **Phone tail upload.** The phone's own upload of the record tail got `503` for over an hour (`sync_record_upload outcome=pending reason=audio_coverage_unproven`). It does not gate the summary; not investigated further. - **Conversations v3** is untouched (#25548 owns its quiet snapshots). - **Listen lifecycle** (`routers/listen`) is untouched. - **Verification level.** Unit tests only. No emulator or prod run, no deploy, no flag change. Existing stale `structured.title_provenance` leaves on already-summarized rows clear on their next processing write; nothing is backfilled. ## Product invariants affected none ## How it was verified - Read-only prod evidence: Firestore conversations, `pipeline_ledger`, `batch_pipeline_prod_jobs`/`_results`, `sync_reprocess_outbox`; Cloud Run request and app logs. - Targeted suites, one pytest process per file: - `test_record_complete_notes` 46 passed - `test_sync_capture_end` 57 - `test_outbox_firestore` 30 - `test_summary_delivery` 65 - `test_home_step` 128 - Every new test fails with its source change reverted. Tests that assert "unchanged" behavior pass both ways. - Read-only prod Home measurement (above), with the real `home_step.classify` under prod's Home env values. - Follow-up commit: all 156 suites the selector and a grep tie to the changed files pass, one process each. - Changed-file selector (`scripts/select_backend_unit_tests.py`): all selected files, each in its own process. That run caught a decorator misplacement in an intermediate revision (3 suites), fixed before this commit. `test_pusher_storage_pcm_saturation` fails its RSS bound on this Mac on the base commit too. - Lints: `scan_async_blockers` 0 findings; `scan_import_time_side_effects` and `check_module_stub_pollution` 0 violations. - `make preflight` and `scripts/pr-preflight --pr-body-file`. ## Tests - `test_record_complete_notes.py`: - eager-off completion makes notes due now, and the ledger write precedes the wake; - notes already written, an unsealed record and the kill switch each leave the obligation alone; - a held unit stamps the seal and wakes notes, while a still-transcribing unit does not; - a held unit after first notes changes nothing. - `test_sync_capture_end.py`: the `units_held` truth table (reseal, barrier); the stamp proves with no ledger read; the kill switch. - `test_outbox_firestore.py`: `expedite_update` never creates, reopens, unparks, re-leases or touches blocked or already-due rows. - `test_summary_delivery.py`: real notes delete the marker through the production leaf mask, and the stored row is no longer a settling fragment. A stand-in, empty output and new rows keep or skip it. - `test_home_step.py`: - a projected batch row read through `CONVERSATION_FIELDS` classifies `writing_notes`; - a past-age-gate stamped row (built with the real `stamp_projection_debt`) classifies `ready` on both the field-masked feed read and the full row; - a no-debt intake stand-in stays `noise`; - parametrized `local_only`, `blocked_byok`, and `empty_output_exhausted` with `HOME_EMPTY_OUTPUT_NOISE=false` stay `noise`. - `test_batch_pipeline_live.py`: the age-gate projection test (renamed `..._stamps_no_debt_and_stays_on_home`) now expects `ready`; it had pinned `noise`. - `test_record_complete_notes.py`: - the held-unit wake carries the rotated token; - a raising wake does not fail `hold_for_quarantine` (the row stays due now); - a raising wake in `complete()` still returns the result and runs `_mirror` and `_settle_allowance`. - Each new test fails with its fix reverted. UI-Evidence: none -- backend projection fields only; the app renders the existing server step unchanged. Failure-Class: FC-batch-fault-domain-head-of-line-poison Change note: `backend/docs/listen_pusher_pipeline/changes/2026-11-17-sealed-record-first-notes-latency.md`. Related classes for parts 3 and 4: `FC-read-projection-omits-visibility-field` (Home field mask) and a merge write keeping an omitted leaf (no existing class). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The CEO wants notes within seconds of a conversation ending. Today a mobile conversation's notes land about 10 minutes after its transcript is ready.
Prod trace from 2026-11-16 of a plain mobile live recording (conversation
a4d5bf49):server_batch_audio_end/finished_atrecord_sealed_at,record_admitted_atepisode_transcript_updated_at)summary_first_pending_atsummary_completed_at/notes_written_atFour real conversations from the same night took 6.7, 14.7, 29.7 and 30.4 min from audio end to notes.
What the prod rows show (read-only Firestore, the same user's
batch_live_v1rows that night):replace_record. That path never touches the processing hold. The pipeline ledger hassealed, thentranscribed1.5 to 5 min later.sync_vad) then merges into the live target. Assignment stampssync_processing_hold.last_content_at, which restarts the 600 s arrival-quiet clock.processing_hold.admissionreturnsquiet_wait. The outbox rows showdeferred_reason = quiet_waitandtask_due_at = last_content_at + 600./v2/sync-capture-end, and their recording-session documents have nocapture_end. So the end-proof path from feat(sync): end-of-recording proof lets notes start without the quiet wait (server) [SCA-2344] #25309 always returnedabsent, and the quiet rule won.a4d5bf49, notes at exactly 600 s after a content arrival at 05:53:09 fit this path. The first-summary deadline claimed the row early, and admission deferred it tolast + 600.Fix
A batch-owned live recording reaches the server over the live socket, so the server's own seal proves it ended. This PR reuses the capture-end proof hook rather than adding new hold semantics:
utils.sync.capture_end.seal_proof(row, ledger)is pure. It returnsprovenwhen all of these hold:batch_live_v1row;record_audio_closed, not partial, no open or failed upload;record_projection_revision);pipeline_ledgerdocument holds atranscribedtransition at or afterrecord_sealed_at. The ledger writestranscribedonly after the record binding's whole projection completes (ProjectionStore._observe_transcription), and units are up to an hour each, so a projected revision alone is not proof. The ledger never moves back, so a reseal keeps the quiet wait;summary_output_present,summary_completed_ator holdfull_snapshot.database.capture_end.sealedreads the ledger document once, and only for rows that pass the row-onlyseal_barrier. A missing or unreadable ledger counts as "not proven".provenasks it first, then the phone marker as before. Both admissions that already passend_provenpick it up: the enrichment callback and the legacy sync pipeline. Outcomeend_proof, metricomi_sync_capture_end_proof_total{result="sealed"}.claim_from_snapshot, anupdated_atprecondition) then fails, and the retry re-admits the fresh row. A test pins this.RECORD_NOTES_EAGER_ENABLED, still off in prod) only runs once every unit is ready. It applies the row barrier when the job carries the row's current upload revision, and recordssealedafter commit, once per committed proof.MAX_LATE_RUNS = 1), and only if the change is material. The unchanged, immaterial and late-cap rules are untouched.batch_sync_v1rows keep the quiet rule.SYNC_UPLOAD_WATERMARK_ENABLEDkill switch. No reads or writes added.Contract:
backend/docs/listen_pusher_pipeline.mdx(End-of-recording proof).Change note:
backend/docs/listen_pusher_pipeline/changes/2026-11-16-sealed-live-record-end-proof.md.Tests
New:
test_sync_capture_end.py:transcribedfrom before a reseal gives no proof;sealedis counted once; the kill switch reads nothing; the ledger collection and stage names are pinned;('end_proof', None)while a sync-only row still getsquiet_waitatlast + 600;ready(exactly one late run,late_runs == 1), thenlate_cap.test_sync_processing_hold.py, using the realenrich_conversationcallback:end_proof);quiet_waituntil 700;claim_from_snapshotprecondition fences the run.test_record_complete_notes.py:None, and the row is not due now;due_at == now, with exactly onesealedcount;The new tests fail with the proof switched off (
SYNC_UPLOAD_WATERMARK_ENABLED=false). Removing the ledger unit gate fails 6 of them.Run, each file in its own pytest process as CI does: 26 files, 1,357 passed, 0 failed. Files:
test_sync_capture_end,test_pipeline_ledger,test_sync_processing_hold,test_record_complete_notes,test_record_notes_delivery_barrier,test_occasion_merge_before_processing,test_sync_reprocess_coalesce,test_outbox_firestore,test_enrichment_*(7),test_episodes_finalizer_hook,test_stt_cap_sync_hold_recovery,test_sync_enrichment_custody,test_reason_label_enums,test_pipeline_ledger_census,test_pipeline_ledger_routes,test_batch_pipeline_projection,test_batch_pipeline_live,test_sync_v2,test_episode_composer,test_live_member_notes_bound.scripts/pr-preflight --pr-body-filepassed (41 checks).Risks / not covered
transcribedis a duplicate. It keeps today's quiet wait.batch_live_v1from its bounded retry); demand tiers.Product invariants affected
none
Failure-Class: FC-sync-enrichment-before-merge-settles
🤖 Generated with Claude Code