Skip to content

fix(notes): a sealed mobile recording gets notes right away, not after a 10-minute quiet wait - #25538

Merged
kodjima33 merged 2 commits into
mainfrom
t3/sealed-recording-immediate-notes
Nov 16, 2026
Merged

kodjima33 merged 2 commits into
mainfrom
t3/sealed-recording-immediate-notes

Conversation

@kodjima33

@kodjima33 kodjima33 commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

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):

Event Time (UTC)
server_batch_audio_end / finished_at 05:51:49
record_sealed_at, record_admitted_at 05:51:58
Transcript ready (episode_transcript_updated_at) 05:53:30
summary_first_pending_at 05:53:34
summary_completed_at / notes_written_at 06:03:09 (9.5 min idle)

Four 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_v1 rows that night):

  • The record's own transcript is projected through replace_record. That path never touches the processing hold. The pipeline ledger has sealed, then transcribed 1.5 to 5 min later.
  • A phone or pendant copy (sync_vad) then merges into the live target. Assignment stamps sync_processing_hold.last_content_at, which restarts the 600 s arrival-quiet clock.
  • When the outbox claims the row, the enrichment callback's processing_hold.admission returns quiet_wait. The outbox rows show deferred_reason = quiet_wait and task_due_at = last_content_at + 600.
  • Live recordings never send /v2/sync-capture-end, and their recording-session documents have no capture_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 returned absent, and the quiet rule won.
  • For 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 to last + 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 returns proven when all of these hold:
    • the row is a completed batch_live_v1 row;
    • its record barrier is closed: record_audio_closed, not partial, no open or failed upload;
    • record text is projected (record_projection_revision);
    • every unit has landed: the capture's pipeline_ledger document holds a transcribed transition at or after record_sealed_at. The ledger writes transcribed only 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;
    • it has no notes yet: no summary_output_present, summary_completed_at or hold full_snapshot.
  • database.capture_end.sealed reads the ledger document once, and only for rows that pass the row-only seal_barrier. A missing or unreadable ledger counts as "not proven". proven asks it first, then the phone marker as before. Both admissions that already pass end_proven pick it up: the enrichment callback and the legacy sync pipeline. Outcome end_proof, metric omi_sync_capture_end_proof_total{result="sealed"}.
  • A reopen between admission and the summary run changes the row. The existing first-summary claim (claim_from_snapshot, an updated_at precondition) then fails, and the retry re-admits the fresh row. A test pins this.
  • Complete-record notes scheduling in projection (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 records sealed after commit, once per committed proof.
  • The seal proves only the first notes. A pendant or phone copy that lands after notes starts a normal hold epoch: it waits the quiet window, then gets at most the existing one automatic late run (MAX_LATE_RUNS = 1), and only if the change is material. The unchanged, immaterial and late-cap rules are untouched.
  • Pure sync uploads and batch_sync_v1 rows keep the quiet rule.
  • No new flag: it shares the SYNC_UPLOAD_WATERMARK_ENABLED kill 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:
    • the seal-proof truth table: lane, open barrier, partial, failed upload, transcript pending, notes written, no seal time;
    • revision 1 projected with a sibling unit pending gives no proof; all units projected gives proof; a transcribed from before a reseal gives no proof;
    • only the ledger is read, and only past the barrier; an unreadable ledger gives no proof; sealed is counted once; the kill switch reads nothing; the ledger collection and stage names are pinned;
    • a sealed live row gets ('end_proof', None) while a sync-only row still gets quiet_wait at last + 600;
    • a pendant copy after sealed notes waits quiet, then ready (exactly one late run, late_runs == 1), then late_cap.
  • test_sync_processing_hold.py, using the real enrich_conversation callback:
    • all units landed: the row passes admission at claim (end_proof);
    • a unit still transcribing: it keeps quiet_wait until 700;
    • a reopen after admission: the real claim_from_snapshot precondition fences the run.
  • test_record_complete_notes.py:
    • unit 1 projected with its sibling pending: completion returns None, and the row is not due now;
    • both units ready: due_at == now, with exactly one sealed count;
    • notes already written: the row stays on its deadline.

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-file passed (41 checks).

Risks / not covered

  • Not exercised against an emulator or prod. Unit tests only.
  • The proof depends on the lifecycle ledger. If the ledger write fails (it is fail-open) or the ledger is off, the row keeps today's quiet wait.
  • A resealed record never gets the seal proof, because the ledger's second transcribed is a duplicate. It keeps today's quiet wait.
  • A pendant copy that would have been inside the old 10-minute window now lands after first notes. It regenerates notes once only if material (at least 30 s of speech or 80 words).
  • A sync mark that lands after the record's own notes mark still schedules its wake at +quiet. The proof applies at the next claim, the same as the phone marker.
  • Not changed, and still visible on some rows that night: transcription about 20 min after the seal on some rows; notes 18 to 30 min after the quiet deadline on others (live-episode member-notes deferral excludes batch_live_v1 from its bounded retry); demand tiers.

Product invariants affected

none

Failure-Class: FC-sync-enrichment-before-merge-settles

🤖 Generated with Claude Code

…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
kodjima33 merged commit 59e0276 into main Nov 16, 2026
71 of 73 checks passed
@kodjima33
kodjima33 deleted the t3/sealed-recording-immediate-notes branch November 16, 2026 22:40
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)
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