Repository navigation
fix(notes): first summary as soon as a sealed recording's transcript lands - #25635
Merged
Merged
Conversation
…or the deadline, a held unit, or a hidden title marker - Record completion (eager notes off, as in prod) writes the ledger's transcribed stage first, then moves the row's open notes obligation to due now instead of the 120 s first-summary deadline. - A unit held for recovery (empty ASR, quarantined ~1 h) no longer holds the record's first notes: once every other unit is projected, hold_for_quarantine stamps the seal on the hold state and moves the obligation to now; seal_proof accepts the stamp (units_held, metric sealed_held). - Real notes delete the stand-in's structured.title_provenance. The merge write kept that leaf, so the settling-fragment filter hid summarized rows for 2 h. - Home's feed and list reads load summary_title_provenance, so a projected batch row that owes notes shows the existing Writing notes step. Failure-Class: FC-batch-fault-domain-head-of-line-poison
…it notes wake - home_step: a row marked a stand-in only at row level (the batch projection stamps it only when transcript text landed) with no debt and no summary is a finished card, not noise. Intake stand-ins with no debt stay noise. Measured on 7 days of prod rows (Nik + 30 batch owners): 0 rows change. - hold_for_quarantine: a wake exception after commit is logged and left to the outbox sweep instead of failing the unit job; test pins the rotated token. - Change note: ordering (due-now move in the commit, ledger after commit, then wake) and the accepted late-unit tradeoff. Failure-Class: FC-batch-fault-domain-head-of-line-poison
…s wake - home_step: the finished-card branch for a row-level stand-in now also requires no summary_blocked_reason, so local_only, BYOK and empty-output blocks (also with HOME_EMPTY_OUTPUT_NOISE off) stay noise. - complete(): the post-commit notes wake shares the fail-open helper with hold_for_quarantine, so a raising wake never skips _mirror or _settle_allowance or fails the unit job. - stamp_projection_debt docstring and the age-gate test name match the settled Home behavior. Failure-Class: FC-batch-fault-domain-head-of-line-poison
kodjima33
added a commit
that referenced
this pull request
Nov 18, 2026
…allowlist canary) (#25673) ## What changed and why **Problem.** A pendant recording should show its transcript and summary on Home within 60 s of the seal. In prod it takes minutes. The largest p50 stage after the seal is not the GPU. It is the ordered merge: 80% of recordings wait the full 60 s `BATCH_PIPELINE_MERGE_HEAD_WAIT_SECONDS` behind a starved head. That head is a days-old `retry` job, and the existing bypass then commits the same row 60 s late. **Change.** Owners listed in the new `BATCH_PIPELINE_MERGE_STALE_HEAD_UID_ALLOWLIST` (default empty) skip the head wait when it is waiting only on starved rows. A starved row was admitted at least 1,800 s ago and has waited that long for a lease: `ready`/`retry` with `available_at` at least 1,800 s in the past, or `leased` with `lease_until` at least 1,800 s in the past. Every lease-ending path (`_defer`, admission hold, missing-input repair, held requeue, redrive, quarantine) resets `lease_until` to 0 and stamps `available_at`, so a row that failed seconds ago, or is due again in seconds, is not starved. The skip commits exactly the row the expired wait would commit (the owner's earliest ready pending row) through the same transaction body. Inside that transaction it also requires: - the row is a native record unit whose earlier binding units are settled; - every pending row captured before it is starved. A new bounded `pending_page` read (129 rows, `first_pending`'s filters, order and index, on every store backend) checks this; a longer backlog refuses. A refused skip returns before the catch-up hold and the backlog-release fallback. Without the early return, a provider-route record candidate could set `held['backlog']` and the tx-fresh fallback would run before 60 s; with it, that fallback is unreachable from a skip. A skip logs `event=batch_merge outcome=stale_head_skip` (head state + wait bucket) and does not write `head_wait_bypass`, so the bypass field and log stay real expiries only. Unchanged: - unlisted owners - head wait off - non-record rows - any unready row ahead that is in flight, recently leased, younger than 30 min, or in another state (`record_pending`, `held`) ### Stage budget, seal to Home summary (prod, read-only) Sample: 600 random `batch_live_v1` rows with `record_sealed_at`, sealed 45 min to 8 h before 2026-11-18 07:50Z, out of 6,730 eligible. 432 had every unit committed. Per recording, the critical path is the last unit to commit. Units per recording: p50 1, p75 2, p90 5. | Stage | p50 s | p75 s | p90 s | Note | |---|---:|---:|---:|---| | seal -> intake claimed | 8 | 396 | 732 | bimodal: 56% < 15 s, 36% wait 5-15+ min | | claimed -> staged/admitted | 6 | 9 | 19 | | | admitted -> GPU result (queue + compute) | 9 | 21 | 62 | GPU is not the bottleneck | | **GPU result -> committed (ordered merge)** | **62** | 137 | 372 | 346/432 via head-wait bypass: p50 67 s single-unit, 98 s multi-unit. Without bypass: 0.1 s | | committed -> persisted (projection discovery) | 21 | 33 | 43 | | | persisted -> ledger `transcribed` (follow-up/completion) | 37 | 62 | 99 | 33 s single-unit (eager wake), 46 s multi-unit | | `transcribed` -> `summary_completed_at` (notes) | 38 | 58 | 93 | Luna `conv_structure` | | seal -> `summary_completed_at`, end to end (n=235) | 452 | 708 | 1,496 | | Sum of p50 stages on the fast-claim path: about 181 s. **Root cause of the merge stage.** For 20 of 20 sampled bypassed owners, the earliest pending fresh-class row is a native record job in `retry`, captured 36-215 h ago and due long ago (`available_at` in the past). `fresh_capture` is fixed at admission. The tx-fresh gate and `_fresh_pick` therefore treat these rows as fresh heads, and every new recording waits out the full 60 s. The canary account (`viUv7G...`) has this shape: a 78.6 h-old catch-up `retry` head, with fresh-class `retry` stock from 84 h ago behind it. ### Ranked cuts (expected p50 seconds saved for the seal -> summary path) 1. **Stale-head skip (this PR).** Saves 45-55 s on ~80% of recordings. All 75 of the canary owner's rows ahead are starved under this rule: `retry`, due 10.3-90.3 h, unleased (53 at attempt 1, 22 at attempt 0, so an `attempt == 0` rule would exclude most of them). They fit inside the 129-row page. Sampled owners had 8-134. Low risk: same rows and outcome as today's bypass, 60 s sooner, allowlist-scoped. After a CPU roll the commit lands on the next serving tick (10 s on prod backend-integration). After a GPU worker roll it lands at publication, saving about 60 s. 2. **Persisted -> `transcribed` completion.** Saves 20-35 s. Low-medium risk, small to medium effort. `RECORD_FOLLOWUP_WAKE_ENABLED` covers only single-unit records (`projection.py:1627`), and even single-unit takes 33 s. Extending the eager wake to multipart, and finding the single-unit delay, comes next. 3. **Post-commit projection wake (committed -> persisted).** Saves 15-20 s. Medium effort. The GPU pump commits directly with no `on_committed` hook, so this needs a GPU image roll. 4. **Intake-claim tail.** p50 unchanged, p75 about -380 s. Medium risk and effort. 36% of seals wait 5-15+ min for the `record_pending` claim. Needs diagnosis: record-drain capacity (10 rows per pass) vs ~1,200 seals/h, or barrier refusals. 5. **Starved fresh-class `retry` heads themselves.** Same seconds as cut 1, for every owner. Medium effort. This is a scheduler question: why due FRESH `retry` rows go unleased for days. Fixing it removes the need for cut 1's allowlist. 6. **Notes model time.** At most 5-15 s, with quality risk. Luna one-shot; the fleet notes histogram is ~25 s model time. Needs a quality eval before any model or prompt change. Not recommended now. 7. **Staged cuts, no gain now.** - `RECORD_FRESH_MERGE_ENABLED` (cut 4): its blocker is unresolved. The prod GPU worker image tag is `ef42ee8` (2026-11-14), which predates the sibling guard `a0a8816`. It would also not help here, because the stale heads are already fresh-class. - `RECORD_NOTES_EAGER_ENABLED` (cut 2): superseded by #25635, which already moves the notes obligation to due-now at completion. The lease-off producer revision blocker is still open. 8. **Pre-seal admission of completed units.** Saves at most ~25 s (admission + GPU = 15 + 9 s p50). Very high custody risk: the seal barrier is the admission contract (`require_record_audio_barrier`). Not recommended. **What remains to reach 60 s p50.** After cut 1 (with a GPU roll), the fast path is about 8 + 6 + 9 + ~1 + 21 + 37 + 38 ≈ 120 s. Cuts 2 and 3 bring it to about 65-75 s. The rest has to come from notes (cut 6) or claim/staging. The intake-claim tail (cut 4) dominates p75 and must be fixed for a p75 target. **Related.** #25633 (120 s speech-quiet seal) and #25635 (first summary when the sealed transcript lands) are live. #25601 and #25623 (David) work on stuck projection chains/heads; they touch no file here. The staged cuts and the 60 s head wait are documented in `2026-11-14-record-post-seal-latency.md`. ## How to canary and roll back - **Canary for one account.** Set on prod Cloud Run `backend-integration` (the serving loop host, `BATCH_PIPELINE_SERVING_ENABLED=true`): `BATCH_PIPELINE_MERGE_STALE_HEAD_UID_ALLOWLIST=viUv7GtdoHXbK1UBCDlPuTDuPgJ2`. This PR deliberately adds no runtime-env overlay entry: put it in the `backend-integration` section of `backend/deploy/runtime_env/prod.overlay.yaml` as part of the canary change, so the next deploy keeps it. The backend image must contain this PR. `config/deployment-setting-classification.json` classifies the variable as `config`. The GPU worker needs nothing; adding the same env there after its next image roll moves the commit to publication time. - **Readback.** A skip leaves no durable marker, so readback relies on the `event=batch_merge outcome=stale_head_skip` log line. On the canary account's next recordings, `committed_at - ready_at` of the last unit should drop from ~60-100 s to ≤ ~10 s, with no `late_capture` within a recording. - **Rollback.** Remove the uid or unset the env. No migration; committed rows keep their order. ## Product invariants affected none ## How it was verified - Prod measurement used read-only Firestore (collection-group `conversations` query on `record_lane_owner`/`status`/`finished_at`, joined to `batch_pipeline_prod_jobs` and `_results` and to `pipeline_ledger`) and read-only `kubectl`/`gcloud` describes. No prod writes, env or flag changes. - `pytest tests/unit/test_batch_pipeline_merge_stale_head.py`: 32 passed. Jobstore SQL safety plus protocol parity: 210 passed. - 94 directly affected test files pass locally: merge, jobstore, parity, scheduler, transaction-attempt, pipeline sims, all Firestore query/index guards, `test_flag_budget.py` and `test_record_seal_latency.py`. CI runs the full 1,260-file selection. - Existing merge suites unchanged and passing: - `test_batch_pipeline_merge_head_wait.py` (177) - `test_batch_pipeline_merge_fresh_first.py` (59) - `test_batch_pipeline_merge_tx_fresh_gate.py` (24) - `test_record_seal_latency.py` (58) - `test_batch_provider_merge_membership.py` (46) - `test_batch_terminal_poll_skip.py` (42) - `test_batch_backlog_release.py` (57) - the recovered-release suites and the head-wait sims - All 24 changed-file-selected unit test files pass, including `test_flag_budget.py`, `test_pipeline_sim*`, `test_lifecycle_invariants.py` and `test_cross_service_deploy_contract.py`. - `backend/scripts/typecheck.sh`: 0 errors. `make preflight`: 43 checks passed. `scripts/check_feature_flag_registry.py`: OK. - Not verified: a live canary. That requires the backend roll and env change, which belong to the parent. ## Tests `backend/tests/unit/test_batch_pipeline_merge_stale_head.py` (32 cases) covers: - a listed owner commits at once behind a starved head, with its own log and no `head_wait_bypass`; an expired wait keeps the bypass marker - **realistic heads that are not starved keep the wait:** in flight; the reviewer's lease-expired retry due again in 10 s (`lease_until=0`, `attempt=1`); a retry that failed 10 min ago; a row redriven a minute ago; `record_pending`; `held` - a prod-shaped retry due for 10 h without a lease is starved and skips - a head deferred between the probe and the transaction keeps the wait - **a young, leased recording captured earlier blocks the skip**; both then commit in capture order - **a refused skip of a backlog-held (provider) unit commits nothing, adds no held owner and runs no early fallback transaction** before 60 s - the 129-row page bound: 128 starved rows ahead skip, 129 refuse - unset, empty or other-uid allowlists keep the 60 s wait - head wait off keeps strict order - an unready earlier unit of the same recording waits - non-record rows keep the wait - the prod shape (catch-up head plus fresh-class stock), with the tx fresh gate on and off - exact allowlist parsing Mutation check: restoring the old `lease_until`-only rule fails 4 of these tests, and removing the early return fails the backlog test. `test_jobstore_sql_safety.py` adds `pending_page_in` binding and limit-cap coverage. `test_jobstore_protocol_parity.py` checks that every backend serves `pending_page`, and the Firestore query-shape registry drives the new query. ## UI evidence UI-Evidence: none -- backend merge scheduling only ## Failure class (fixes) Failure-Class: none 🤖 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.
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 theSYNC_UPLOAD_WATERMARK_ENABLEDkill switch with #25538.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.ProjectionStore.completemoves the row's existing open notes obligation to due now, inside the completion's commit transaction. After that commit it writes the ledger'stranscribed, and only then wakes the obligation.transcribedstage that the woken callback's seal proof reads.complete()open (batch_pipeline_projection.py:849), so the ledger never getstranscribed, and fix(notes): a sealed mobile recording gets notes right away, not after a 10-minute quiet wait #25538's seal proof (utils/sync/capture_end.py:248-255) returnsunits_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).hold_for_quarantinealready reads every sibling in one transaction. When every unit is projected or held for recovery and the row passesseal_barrier, it:sync_processing_hold.units_settled_seal_at = record_sealed_at, and only on rows that already have a hold state;complete()) are fail-open, like_rearmed. An exception is logged and left to the outbox sweep. It never fails the unit job, and incomplete()it never skips_mirroror_settle_allowanceafter the durable commit.seal_proofreturnsunits_heldwhile the stamp equalsrecord_sealed_at; the metric outcome issealed_held. A reseal invalidates the stamp.immaterial,late_cap, at most one material late run). So its text can land in the transcript while staying out of the notes. Indebba5b8that unit held 4 words.database/conversations.py:1378,1745,1747), so the stand-in'sstructured.title_provenance='server_minimum'outlived the real notes.is_settling_fragment(utils/conversations/fragment_visibility.py:196) then kept the summarized row offGET /v1/conversationsuntil 2 h after its end. This was reproduced on a sync piece reprocessed today.summary_delivery.merge_result(called by both writers) deletes it (retires_title_marker).backendservice runsHOME_FEED_ENABLED=falseand noOMI_INDEXED_LIST_READS_ENABLED, andEPISODES_ENABLED=off. So prod Home isGET /v1/conversations(routers/conversations.py:1164-1189), which classifies full rows. That path already saw the row-levelsummary_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).summary_blocked_reason, is now classifiedready(a finished card), notnoise(which both app paths hide:home_rows.dart:376,home_card_rows.dart:29).stamp_projection_debtmarks the row alone, and only when projected transcript text landed (live_projection.py:150-157). So these rows always carry speech.ready.noise:structured.title_provenance, e.g. "Mm-hmm.") with no debt;local_only(includingterminal_no_derived_effectsand deferred),blocked_byok, andempty_output_exhaustedeven withHOME_EMPTY_OUTPUT_NOISE=false.stamp_projection_debtdocstring and the renamed age-gate test now say this.noisewith the new field mask, and 0 rows reach the provisional branch'snoise.HOME_EMPTY_OUTPUT_NOISE=false. The blocked-row tests pin the classification for those cases instead.noisetoday all come from other branches. 1,128 areempty_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):record_sealed_atrecord_intake_claimed_at,compute_decision.atready_atd7ce8acf(92 s audio, 3.5 s VAD speech)worker_failed/empty_asr, quarantinedquarantine_reasoncommitted_atprojection.persisted_atsummary_first_pending_atsync_merged_from, holdlast_content_atquiet_wait(seal proofunits_pending, no ledgertranscribed)deferred_since/deferred_reasonprocessing_hold.py:201recovery.prepared_at6c2a7917, ledgernoted − 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(puresync_vadpiece): 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.5731e148/c35a2059: held bypending_live_bridgefor as long as live targetc92384c3isin_progress.utils/sync/bridge.py:395-433), and hourly after 6 h (utils/enrichment/outbox.py:69).in_progress,_finish_pending_live_bridge(bridge.py:196-244) merges a piece into the live row whenchoose_live_overlappicks it and the piece has no notes. Otherwise the piece is summarized on its own, under its own hold.Not changed / not verified
503for over an hour (sync_record_upload outcome=pending reason=audio_coverage_unproven). It does not gate the summary; not investigated further.routers/listen) is untouched.structured.title_provenanceleaves on already-summarized rows clear on their next processing write; nothing is backfilled.Product invariants affected
none
How it was verified
pipeline_ledger,batch_pipeline_prod_jobs/_results,sync_reprocess_outbox; Cloud Run request and app logs.test_record_complete_notes46 passedtest_sync_capture_end57test_outbox_firestore30test_summary_delivery65test_home_step128home_step.classifyunder prod's Home env values.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_saturationfails its RSS bound on this Mac on the base commit too.scan_async_blockers0 findings;scan_import_time_side_effectsandcheck_module_stub_pollution0 violations.make preflightandscripts/pr-preflight --pr-body-file.Tests
test_record_complete_notes.py:test_sync_capture_end.py: theunits_heldtruth table (reseal, barrier); the stamp proves with no ledger read; the kill switch.test_outbox_firestore.py:expedite_updatenever 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:CONVERSATION_FIELDSclassifieswriting_notes;stamp_projection_debt) classifiesreadyon both the field-masked feed read and the full row;noise;local_only,blocked_byok, andempty_output_exhaustedwithHOME_EMPTY_OUTPUT_NOISE=falsestaynoise.test_batch_pipeline_live.py: the age-gate projection test (renamed..._stamps_no_debt_and_stays_on_home) now expectsready; it had pinnednoise.test_record_complete_notes.py:hold_for_quarantine(the row stays due now);complete()still returns the result and runs_mirrorand_settle_allowance.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