Skip to content

fix(v3): size cap measures the real stored transcript size (no mid-speech splits) - #26705

Merged
kodjima33 merged 39 commits into
mainfrom
fix/v3-transcript-real-size-cap
Nov 30, 2026
Merged

kodjima33 merged 39 commits into
mainfrom
fix/v3-transcript-real-size-cap

Conversation

@kodjima33

@kodjima33 kodjima33 commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

What changed and why

#26372 (SCA-2918) cuts long conversations in the middle of continuous speech. planner._transcript_bytes estimates each line as 3 * (len(json.dumps(segment)) + 64) with no compression, and _capped cuts once the running sum passes 900 KiB. Segment metadata dominates that estimate, so ordinary speech reaches the budget long before the stored field nears Firestore's limit.

Production, last 24 h (metadata only): 215 mid-speech size splits for 143 users. 0 had a finished stretch when the first part was created: all 215 were cut while still live, the first part created 25-74 minutes before the speech ended. Round 6's final-only merge would have merged none of them. One 65-minute recording (Nov 28): 702 lines, cut mid-sentence while its whole stored enhanced field was 284,756 B (27% of the 1,048,487-byte limit).

Design (round 13): cut later, with main's machinery

The size merge is gone: size_merge, merged-row and provenance comparison, kept_live, the merge STRETCH_FIELD paths and their service hooks.

  1. Where the size cut lands (planner._capped). Main's deterministic, append-only cuts, the two-hour CAP, "every part but the last locks", ownership and locked runs are unchanged. A size cut happens when either:

    • (a) the per-line estimate sum passes TRANSCRIPT_BUDGET = 2 x 900 KiB (MAIN_TRANSCRIPT_BUDGET = 900 KiB remains for fallback); or
    • (b) the part's speaker evidence would pass 95% (EVIDENCE_SHARE) of each hard cap of speaker_grouping_storage's timing fallback. The evidence is counted exactly as the storage serializes it:
      • each unit's envelope json.dumps({'id': first_sid, 'timing_unit': {'scope', 'timing_store', 'segments': {sid: {'id', 'provider'}}}}), which grows by exactly one , "sid": {...} entry per member;
      • the decoded total exactly as _protect_timing_markers sums it, from the _timing_record compact-record bytes;
      • the encrypted length exactly, 4 * ceil((n + 28) / 3).
        test_evidence_accounting_is_exact checks that against the real sidecars protect_segments writes.

    The budgets are:

    Cap 95% budget
    MAX_BYTES per unit envelope (65,536 B) 62,259 B
    MAX_ENCODED_BYTES per unit, encrypted (98,304 B) 93,388 B
    MAX_TIMING_TOTAL_BYTES, compact records and envelopes decoded (262,144 B) 249,036 B
    MAX_TIMING_TOTAL_ENCODED_BYTES (393,216 B) 373,555 B
    MAX_TIMING_UNITS (1,024) 972

    (b) also cuts before a segment id the part already holds, because the fallback binds labels by id, and before a unit's second timing store, which the fallback drops. Both sums only grow as lines are appended, so cuts stay append-only. Logged as event=v3_transcript_size_cap_split / event=v3_transcript_evidence_cap_split.

  2. Final-row validation (v3/size_check.py). prepare encodes every final row exactly as the commit stages it, quietly, on the DB executor: the commit codec plus the configured settle stamp. Each field value and the document are measured by Firestore's storage-size rules, using the same staged_sizes as the commit guard. It then reads back from those bytes every line's reader-visible speaker placement, (provider, unit, label, timing store) in order, through the serving decode and reveal_segments. This covers retained, appended and new lines on both protection levels.

    • Any codec fault (an encode exception, or an encryption, authentication or readback failure, reported by speaker_grouping_storage.quiet() separately from intentional capacity drops) means no cache and one retry. A fault that persists leaves the row to the normal writer: no carry, no replan, no routing.
    • Probes are silent. The fallback outcomes a carried payload's quiet encode suppressed travel with its checked encoding, and commit_projection reports them once, after that row's successful write (report_written). A plan discarded by adoption or a replan reports nothing.
    • A planned row (not a locked one, which keeps main's append) that exceeds 768 KiB field or 900 KiB document, loses a placement, or fails to encode gets its stretch planned again with MAIN_TRANSCRIPT_BUDGET (event=v3_transcript_size_check outcome=fallback|replan). Fallback never shrinks a published row: a stored, undeleted, unlocked row owning lines on both sides of a fallback or evidence cut joins Ownership.locked_ids, so it is planned as locked at its stored extent.
    • A hard overflow takes main's own path. If a stored open (unlocked) card's rebuild exceeds a hard limit (1,048,487 B field value, 1 MiB document), it is released (Ownership.released): it loses both its stored-extent pin and its Rule B outline protection, its stretch gets main's 900 KiB budget in the same retry, and it is cut by that budget and its topics, as main would cut it (outcome=recut). The first part keeps the card's id through main's matching, and claims follow main's normal writes. A locked row past a hard limit is not carried: the exact staged guard refuses it before anything is sent, with Firestore's own message naming the document, and the pass parks as on main.
    • Only bytes that are storable and keep every placement are carried, and commit_projection writes exactly those bytes on every attempt and retry.
    • As a backstop, commit_projection refuses any staged derived row (after stamps, privacy filtering and rederive lineage) and any source claim update past the hard limits before sending it (guard_staged). It uses Firestore's own rejection and message, so main's existing park path applies unchanged.
    • Planning passes are bounded at five.
  3. Late appends into locked rows (v3/locked_append.py), strictly a fallback. A locked row appends late speech exactly as on main whenever the grown row stores intact, including past the soft limits. "Intact" means within the hard limits with every speaker placement kept, decided on the commit's own bytes by size_check.prepare; the final representation is re-verified and carried by size_check.

    • Only past a hard limit, or losing evidence to the storage's caps, does the row stop appending everything. It keeps what it published plus every new turn whose audio lies inside its own claims (only the card can play those turns), as long as that is within the hard limits. When only evidence overflows, a continuation that Home would hide as its own row (for example below_word_minimum) is not created: its speech stays on the visible row. Each turn keeps its own placement where the storage's capacity rules keep it at no cost to a placement already kept (locked_append.choose, no encode). The committed bytes are checked once with the real codec, with at most one retry. A continuation the hard limits require shows on Home as its owner does in this pass, from its first write and whatever its classification (v3_home_owner). It never takes the owner's End. Past full-evidence capacity the codec's compact fallback keeps what it can, as on main. The rest of the speech main's own append dedupe calls new (planner.present_in: ids, revised ids, overlapping equivalent text) goes to continuations. These are cut by main's 900 KiB budget and the evidence budget, untitled. If even the retained append is past a hard limit, the row grows as on main and the pass parks.
    • Rollback. With CONVERSATIONS_V3_TRANSCRIPT_SIZE_CAP=off, planning, late appends and the writer are main's: no size check, no replan, no routing. Only the commit's staged hard-limit guard stays.
    • A probe whose codec keeps failing takes main's append.
  4. A published live card keeps its extent across re-outline (planner._keep_published). Cohesion on and off, only with the size cap on.

    • The planner marks a card with the persisted flag v3_size_extended once its lines exceed main's 900 KiB estimate under the size cap; only the larger budget creates such cards.
    • The mark survives live rewrites, because a build carries the prior's fields.
    • Rule B: protection covers the card's claimed audio interval. A topic that starts anywhere inside it becomes a section of the topic before it, whoever owns the neighbouring lines.
    • On a finished stretch, preserve_finished_windows holds the card's own lines apart through its existing provisional custody. An unowned turn inside the interval therefore gets its own row, as on main. The card keeps its id, lines and claims and keeps growing; topics that start after its lines still cut. Live cards under main's budget keep main's topic cuts exactly, so the existing test_delayed_short_topics_across_recordings is unchanged. Production runs with cohesion on: CONVERSATIONS_V3_STRETCH_COHESION is unset on backend-sync, backend and backend-sync-backfill, and the code default is on.

Owner's real recording on round 8 (reported): the dinner is one row (282,372 B, 702/702 placements); three dinners are 800 + 801 + 505 with 2,106/2,106 placements. Round 9 keeps both: the dinner and three-hour tests are unchanged and pass.

Review items (round 22)

  1. Companion recovery survives the owner's deletion. The on-open outline recovery recognized a companion by its live v3_home_owner link, which clears once the owner is deleted. It now also recognizes the persisted End receipt (v3_home_owner_cut present). Such a row, unless it owns a distinct End (manual_end), clears the stale outline failure with no processing scheduled. A companion that owns a distinct End keeps ordinary outline recovery.
    • Regression: test_a_continuation_resolves_its_owner_on_a_narrow_load[deleted_then_open|unlinked_then_open], through the real failure_patch and the production loader. The owner's claims are released and it is removed; the companion is then opened at once, or after a separate pass already cleared its link. Through two re-arms it stays completed with nothing pending, the failure cleared, no End, and the receipt equal to the deleted owner's cut. Both went to processing before the change.

Non-test code this round: +6 / -3 (net +3).

Review items (round 21)

Each counterexample was written as a test first and failed before the code changed.

  1. The reduced locked row is always validated. In the evidence-only path, every reduced row accepted without its own probe (the card plus its claim-bound turns, with or without chosen evidence) is marked. Before, only rows with short turns were. If its committed bytes fail the hard check, the next attempt probes it. If it stores, its late turns go to visible continuations; otherwise the measured full append (main's) commits, before any continuation is staged and without a park. Degradation is reported for the payload that commits (report_written of its own encode).
    • Regression: test_a_reduced_locked_row_past_the_hard_limits_appends_as_main, at a twentieth: the near-limit card with unstamped placements, conversation kind, one 40-word turn inside its claim and ten unclaimed 16-word turns with unstamped placements, visible on their own so nothing is chosen. The plain append is 44,960 / 46,667 B; the reduced row would be 52,876 B document. It commits every line once, visible, with nothing pending and every write within the hard limits, stable on re-arm. It returns blocked before the change.
  2. A recovered outline failure on a settled companion adds no processing. On open with first-open gating, a continuation (v3_home_owner) whose outline failure recovers has the failure cleared (and its tile back to done). It keeps its settled status, and no processing obligation is added for the End its owner holds.
    • Regression: test_a_continuation_resolves_its_owner_on_a_narrow_load[on_open]: the continuation is written with a failed outline (the real failure_patch), then opened through the production loader with a working outline and re-armed twice. One End, no cut on the continuation, completed, nothing pending and the failure cleared. Without the change it goes to processing.
  3. The consumed End receipt survives owner removal. A continuation persists its owner's cut as v3_home_owner_cut (or None). Clearing the visibility link keeps it, and _takes_end lets a row that is or was a continuation take an End only after that cut.
    • Regression: [owner_deleted] through two re-arms: the link is gone, the receipt equals the owner's cut, and there is no End, no cut and no processing. Without the receipt rule the survivor takes the owner's End.
  4. Line-count exceptions regenerated against the final diff. service.py 2113 -> 2256. database/conversations_v3.py is 2500 against main's 2511, since the owner read moved to database/conversations_v3_home_owners.py, so it needs none. Validated with the actual body by make preflight.

Non-test code since round 19's head (rounds 20 and 21, pushed together): +97 / -18 (net +79); round 21 alone +25 / -12 (net +13); the runbook +3 / -2.

Review items (round 20)

Both counterexamples were written as tests first and failed on round 19's head before the code changed.

  1. Evidence selection never turns a storable append into a park. Two holes, both closed:
    • The choice now models where the reader reveals sidecars. reveal_segments rejects a sidecar on any line at a position of MAX_SEGMENTS or later, so locked_append.choose no longer gives a placement back there.
    • Bytes past a hard limit always count as hard. size_check.check now counts a row whose committed bytes pass a hard limit as hard even when their readback also faults; the guard refuses those bytes either way.
    • Recovery instead of a park. If a row whose evidence was chosen fails the hard check, the next attempt routes its late turns outside the claims to visible continuations (owner visibility, outcome=choice_over_limit). If the kept row still cannot store, the measured plain append (main's) is used, so the pass never parks on its own choice.
    • Regression: test_a_selection_past_the_hard_limits_never_leaves_late_speech_pending[unrevealable|over_limit], at a twentieth. unrevealable is the review's geometry: 12 placed card lines and 13 sidecars, the 450->777 media replay, ten unstamped late turns. over_limit has every card line placed and nine sidecars to spare, so the choice is valid by the model but its bytes pass the limit. Both commit with every line stored once and visible, nothing pending and every write within the hard limits, stable on re-arm. Both return blocked on round 19.
  2. A continuation resolves its owner on a narrow load and never doubles the End.
    • The owner is read by id. store.load reads a continuation's owner that the pass did not load by id (database/conversations_v3_home_owners.attach, a new 26-line module, so conversations_v3.py stays under main's line count): one get_all of just its cut, Home fields and deletion flags (planner.HOME_OWNER_META). A missing owner reads as deleted.
    • No new End without proof. _takes_end gives a continuation a new End only on a resolved owner and a distinct, later cut; an unresolved owner gives none.
    • Dead links clear. shown_as_owner clears v3_home_owner once the owner is deleted or discarded.
    • Regression: test_a_continuation_resolves_its_owner_on_a_narrow_load[on_open|owner_deleted], through the production loader with a real owner End cut (end_open_conversation). on_open: opening the settled ten-turn continuation reads only it and its source, yet there is one End, no cut on the continuation and no processing re-queued. owner_deleted: the owner's claims are released, the owner removed and the source re-armed, and the continuation keeps no link. Both fail on round 19.

Non-test code this round: +81 / -15 (net +66); the runbook +3 / -2.

Review items (round 19)

  1. One End owner through re-arm. In retained-window planning (preserve_finished_windows), a row that owns a window's last line takes the window's End only through planner._takes_end. A continuation (v3_home_owner) takes it only for a distinct End, a cut after its owner's v3_manual_cut_at. v3_home_owner never carries End ownership.

    • Regression: test_a_required_continuation_shows_as_its_visible_owner[conversation|media|background|media-toggle] now records the owner's End on its source, as the End writes it. The ten turns land after every card line and before that End, and the continuation's processing has settled before re-arm. Through re-arm there is exactly one End (the owner's), no cut stamp on the continuation, and the continuation stays completed with no processing re-queued. Without _takes_end there are two Ends.
  2. Visibility from the owner as planned in this pass. locked_append.shown_as_owner reads the owner from this pass's planned rows, falling back to the loaded owner when the pass leaves it untouched. It runs before sizing, and the effective fields are persisted on the continuation's committed row.

    • Regression: [media-toggle]: manual-End Home visibility is off for the 35- and 54-line passes (the 450/777 ones) and on when the ten turns land. Owner and continuation are both visible on that first write. Reading the stored owner hides the continuation.
  3. Bounded codec work. The kept row is built once with the short turns stripped. locked_append.choose picks the turns whose own evidence can return, by the storage's own capacity rules and with no encode:

    • while every per-segment sidecar fits, a turn joins only if the count, plaintext and encrypted totals still fit (protect_segments's checks);
    • past that, only the timing fallback is kept, and a turn joins only if its timing evidence fits beside what is kept (planner._Evidence at the hard caps; it now takes a share).

    The choice rides on the row (size_check.CHOICE). size_check.check's own encode of the final row is the one real-codec check. If those bytes lose a placement the choice expected, the chosen evidence comes off and the row is encoded once more, and those are the bytes committed. In the evidence-only case the kept row is part of the already probed grown row, so its separate storable probe is gone.

    • CPU, the review's case (a 455-line locked media card, a 200-turn unstamped late append, 247 unrelated lines; full scale, real codec; warm median of three late passes): before 7,303 ms with 204 encodes of the card; after 165 ms with 2 encodes; cap off (main's behaviour) 155 ms, so about 1.06x.
    • Regression: the evidence fixtures count encodes per row per pass: the card is encoded at most twice (its overflow probe and its committed bytes), on the first write and on re-arm. mixed and alternating keep their exact placement sets.

Non-test code this round: +155 / -52 (net +103), mostly the capacity model in locked_append.choose; the runbook +3 / -2.

feature-flag-registry still fails identically on main (date rollover, other teams' flags). scripts/check_feature_flag_registry.py --as-of 2026-11-29 passes here.

Review items (round 18): the general rules

  1. A required continuation shows on Home as its owner does, for every classification. Round 17 lifted only the conversation word gate. Now a continuation the hard limits require records its owner (v3_home_owner, persisted). On every build while that owner stands, it takes the owner's effective Home fields (home_hidden, home_hidden_reason; locked_append.shown_as_owner). It keeps its own kind and End ownership. The round-17 _stretch_words floor is gone.
    • Regression: test_a_required_continuation_shows_as_its_visible_owner[conversation|media|background]: the 450->777-line replay at a twentieth with the outline classified as each kind (background is wearer-recognized). The continuation is visible on its first committed write, keeps its own kind, plays 10/10, and stays visible on re-arm. All three fail without the change: hidden on the first write, or on re-arm before the owner link was persisted.
  2. Evidence chosen turn by turn. The Home-hidden late turns kept on the visible row are walked in order. A turn keeps its own placement when a probe with it included keeps every placement already retained and stays within the hard limits (locked_append.placed); otherwise only that turn's placement is stripped. The final selection's bytes are the ones committed: size_check.check now carries a locked row's storable probed bytes even where the codec drops evidence (main's append path), so the write is exactly what was probed.
    • Regression: test_evidence_only_overflow_keeps_claim_bound_turns_on_the_locked_card[mixed|alternating], at a tenth with the sidecar capacity scaled with the lines. mixed (250 + 5 + 2 with 256 sidecars at full scale): every original and in-claim placement plus the stamped late turn's. alternating (stamped, unstamped, stamped, unstamped): the first two late turns, the ones that fit. The committed bytes are checked on the first write and on re-arm. Both fail with round 17's all-or-nothing choice.

Non-test code this round: +51 / -33 (net +18); the runbook +3 / -2.

feature-flag-registry (Hygiene and make preflight) fails identically on main since 2026-11-30 00:00 UTC: flags of other teams passed their 7-day grace. It is not changed here. scripts/check_feature_flag_registry.py --as-of 2026-11-29 passes on this branch.

Review items (round 17)

  1. Main's budget on the hard-release retry. The release now also installs main's 900 KiB budget for the stretch before retrying (fallback), so the released outline and size cuts apply together.
    • Regression: test_an_open_card_revised_past_the_hard_limits_is_cut_as_main[outline-on|outline-off] now asserts main's exact partitions from the same wide card. Main's budget is scaled to nine of a topic's twelve lines, so topic 1's tail after the size cut is a topic of its own, as the 19-line tail is at full scale. Cohesion off: each topic cut by main's budget (260+19+260+19 at full scale). Cohesion on: the stretch cut by main's budget, then at the topic boundary (260+19+241+38). Both hold after End and after re-arm. Without the change both cases fail.
  2. A short turn keeps its placement when it fits. For speech kept on the visible row, the retained payload is probed with that speech's evidence intact and again without it (locked_append.keeps_as_many, via size_check.placed, the per-line readback). The evidence is stripped only if keeping it would cost a placement the stripped payload keeps, or pass a hard limit.
    • Regression: test_evidence_only_overflow_keeps_claim_bound_turns_on_the_locked_card[stamped]: stamped originals, the five-word late turn stamped in its own batch unit, ten unstamped in-claim turns still overflowing the sidecars. The committed bytes keep every original placement and the late turn's own, on re-arm too. Fails with round 16's always-strip.
  3. A required continuation shows as its visible owner. A continuation the hard limits force (overflows says 'hard') under a visible owner carries the word gate the owner already passed (continuations(..., visible=True) sets _stretch_words to at least MIN_HOME_WORDS). Its Home visibility on the first write therefore matches main's append to the visible card.
    • Regression: test_a_required_continuation_shows_as_its_visible_owner: at a twentieth, a visible End card grows from 35 to 54 lines (49,872 B field / 51,023 B document; the review's 450->777 lines at 1,043,824 / 1,045,746 B). Ten more turns of 140 words from another late source need a continuation, and it is home_hidden: False on its first committed write. Without the change it is hidden.

Non-test code this round: +78 / -27 (net +51); the runbook +4 / -3.

Review items (round 16)

  1. A released open card loses outline protection too. Before, the release cleared ownership.locked_ids, but _keep_published put the same card back in the outline hold, so a 558-line card with a revised second topic was rebuilt whole, refused by the guard and left in_progress. Now any stored open row that fails the hard check joins Ownership.released, which both the pin and _keep_published skip, and the retry applies the actual topic and size cuts.
    • Regression: test_an_open_card_revised_past_the_hard_limits_is_cut_as_main[outline-on|outline-off], through the production store.load and commit_projection at a twentieth: two 279-line sources (12 here) at 36 words published as one open card with the size marker, then both completed at 53 words with a second topic at line 280 (13 here). It commits with no quarantine, every part within main's budget and the hard limits, the card's id on the first part, and every line once. A healthy recording 6 h later commits, and End settles every card with its processing queued. Both cases return blocked without the change.
    • Per the round-16 scope note, the [words] case (round 15's 2x250-line 28->61 replay) no longer asserts main's exact partition. It asserts main-budget compliance and the safety properties.
  2. Short late speech stays visible. During evidence-only overflow (locked_append.overflows now says 'evidence' or 'hard'), a continuation Home would hide as its own row is not created. Its lines stay on the visible original with their own placement stripped (locked_append.unplaced), so the card's stored placements are not put at risk.
    • Regression: test_evidence_only_overflow_keeps_claim_bound_turns_on_the_locked_card adds a five-word late turn from a later recording to the unstamped fixture. One visible card with all eleven new turns, 11/11 covered by its recording_pieces, on re-arm too. Without the change there are two rows.

Non-test code this round: +50 / -24 (net +26); the runbook +4 / -2.

Review items (round 15): the park path is replaced, not patched

  1. Re-cut instead of park for the open card. In the size-check loop, a published row pinned at its stored extent whose rebuild then passes a hard limit (size_check.check now also returns those row ids) is unpinned and the stretch is planned again with main's budget, so the end state is cut as main cuts it. Locked rows keep main's park. The round-13/14 park attribution is gone: _size_quarantine, _quarantine_park, size_error_document and store.load are back to main's code, and guard_staged no longer tags its error.
    • Regression: test_an_open_card_revised_past_the_hard_limits_is_cut_as_main replays the 2x250-line 28->61-word revision at a twentieth (2x13 lines) through the real store.load (the lease's real open_id) and commit_projection, with healthy recordings 30 s and 6 h later. It commits parts within main's budget (round 16: exact partition not required) with the card's id on the first part, no quarantine and no park, and every line published once. End then settles every card with v3_process_pending and clears every source. It returns blocked without the change.
  2. Evidence-only overflow on a locked append. The retained card keeps every new turn inside its own claims whenever that is within the hard limits (locked_append.storable), even if evidence exceeds full-evidence capacity. Only speech outside its claims is routed, so routed turns always have unclaimed, playable audio.
    • Regression: test_evidence_only_overflow_keeps_claim_bound_turns_on_the_locked_card: a locked card with no timing stamps at MAX_SEGMENTS, then a same-length revision with ten distinct 0.7 s turns inside its claim and ten older turns omitted. One row, all ten on the card, 10/10 covered by its recording_pieces, on re-arm too. Round 14 made a continuation.
  3. Rollback switch. size_cap = transcript_size_cap_enabled() gates the size-check loop and the late routing; off returns main's plan and build directly. The runbook says so.
    • Regression: test_late_speech_of_the_same_unit_keeps_every_placement[off], the 580+1+220 replay at a tenth: one card with every line (101), as main, on re-arm too. [on] keeps the card plus the in-claim turn and routes the 30 late lines, with every placement kept.

Non-test code this round: +73 / -60 (net +13); the runbook +7 / -4.

Review items (round 14, superseded by round 15 item 1 for the park)

  1. The park drains independent stretches when the rejected card is the open window. Before, a guard rejection of the card the lease's open_id points at was treated as unattributable (the open window is loaded on every pass), so the owner backed off and the next healthy recording never ran. Now the commit guard's rejection names its row (error.conversation_id), and _size_quarantine charges it to the seeds whose claims feed that card. store.load skips the open window while every one of its sources is quarantined, so its closure stays out of unrelated passes until the hold lapses.
    • Regression: test_a_rejected_open_card_quarantines_its_own_seeds_and_the_next_recording_commits, through the real store.load with open_id set to the rejected card: exactly its seeds (a, b) are quarantined, the stored card and claims are unchanged, the independent recording c commits on the next pass, and nothing loops (two passes). It fails without either half (no quarantine; or blocked on the second pass).
  2. A distinct turn stays playable when a locked append splits. A continuation cannot claim audio the retained card already claims, so a new turn inside the card's claims had no playable audio once routed. Now new turns inside the card's claims stay on the card when the grown card still fits, and only the remaining late speech moves (locked_append.claimed). If even that does not fit, main's split applies.
    • Regression: test_late_turn_inside_a_locked_cards_audio_stays_playable: an overflowing late append plus a distinct 0.7 s turn inside the card's audio. The card keeps its published lines plus that turn, only the other recording's speech moves, and every row's recording_pieces cover every transcript turn it serves. It fails without the fix.

Non-test code this round: +53 / -19.

Review items (round 13): the frozen-card path is removed

All three round-12 must-fixes were inside the frozen path, and rounds 9 to 12 each found new edge cases there:

  • distinct speech overlapping the frozen claim by 50 ms was hidden;
  • an interleaved second-device turn sent the card to processing while live, with revised duplicates;
  • frozen playback stacked [0, 749.0] and [0, 749.1].

Why it can go. A published row only exceeds Firestore's hard limits if the same audio's stored transcript more than about doubles. Real speech rows publish at about 330-400 KB, the pre-commit check bounds every new row at 768 KiB, and re-transcribing the same audio cannot double it.

Round 13 parked that case with the one-seed quarantine; round 15 cuts an open card by main's budget instead (above). Removed: Ownership.freeze and frozen_ids, planner.claimed_overlap, the frozen build window and its playback/piece handling, the frozen service hooks, size_check's hard set, and their tests. Non-test code is -50 net lines this round (+32 / -82).

  • Regression (replaced in round 15 by test_an_open_card_revised_past_the_hard_limits_is_cut_as_main): test_a_revision_past_the_hard_limits_parks_with_one_seed_quarantine used the round-8 two-source revision to many more high-entropy words, at a twentieth. The card is published under main's budget (no extended marker, revision 1). The staged guard refuses the oversized rebuild before sending, and the pass returns blocked with document_too_large, quarantining the seed's closure (r, r2). The stored card and both sources' claims are untouched, nothing is written, and the independent recording commits on the next pass.
  • Kept: Rule B, the sticky marker, revisions on real changes only, codec-fault handling, telemetry after the write, exact sizing, the evidence tally, and all the listed must-keep regressions. The 130-minute cut has a test again (test_a_130_minute_dinner_cuts_once_at_the_two_hour_cap).

Review items (round 11)

Round 12 replaces case-by-case handling with the two rules above and deletes what they supersede (locked_append.keep_published, locked_append.as_locked, size_check.report, the stored-estimate classifier). Non-test code shrank by 3 net lines this round (+102 / -105).

  1. Revised boundary turn. Superseded by the round-13 removal of the frozen path.
  2. Unowned turn inside a protected card. Rule B. test_a_new_turn_inside_a_protected_card_gets_its_own_row[off|on x inserted|next]: a 52-line published card (your 520 at a tenth) gets one distinct turn from a new recording between old lines 26 and 27, then End brings a new topic at that turn or the next. The card keeps every published turn and its id, and the inserted turn gets its own row.
  3. Marker and revision from the stored version. With no frozen rebuild, the marker and revision always come from the written transcript. The parked card in the round-12 regression keeps no marker and revision 1.
  4. Telemetry from the write that lands. test_codec_faults_and_telemetry_follow_the_written_payload[timing_write]: planning twice, the first plan discarded as adoption does, reports nothing. The written row reports main's single event after its write.

Review items (round 10)

  1. Frozen cards with replaced source lines. Superseded by the round-13 removal of the frozen path.
  2. Eligibility across intermediate live writes. Design 4. test_reoutline_protection_follows_what_the_card_published[shorter_live_write]: a large card is published, a shorter revision is committed while it is still live, then End brings a new mid-card topic. The card keeps its extent. With size_cap_off, main's topic cut applies whatever the mark says.
  3. Codec faults and telemetry through to the chosen write. Design 2.
    • test_codec_faults_and_telemetry_follow_the_written_payload[sidecar_fault]: a probe-only primary-sidecar encryption fault. The faulted bytes are never cached; the retry's bytes keep 10/10 shadow predictions, and no event fires.
    • [timing_write]: a healthy row on the timing fallback reports the one event main reports.
    • test_a_probe_only_codec_failure_keeps_main_append[encrypt|decrypt]: a probe-only encryption or readback authentication fault leaves the storable late speech in the original card (80 lines, main's 712 at full scale).
  4. Line-count exception. Updated to the final diff, now service.py 2,113 to 2,182. make preflight runs with this body.

Review items (round 9)

  1. Settle a frozen live card. Superseded by the round-13 removal: the overflow parks instead.
  2. Exact field measurement and attribution. test_staged_sizes_measure_field_values_exactly_and_name_the_rejected_row: a 1,048,257 B value in a 1,048,452 B document stores. A value past 1,048,487 B is refused before sending, with Firestore's size message and the row's id (size_error_document).
  3. Re-outline from the published card. test_reoutline_protection_follows_what_the_card_published covers both threshold crossings and the size cap off.
  4. Speculative codec failures. Probes are quiet (test_evidence_only_sidecars_keep_falls_back_to_main_cuts asserts no speaker-grouping events), and a probe-only codec fault keeps main's append.

Review items (round 8)

  1. Hard admission separate from soft replanning. Design 2. Since round 15 an open card in that state is cut by main's budget (round-15 item 1).
  2. Reader-visible evidence on final rows; evidence-bounded locked appends. Designs 2 and 3, both at a tenth.
    • test_late_speech_of_the_same_unit_keeps_every_placement: 70 published lines, then 30 new lines of the same batch unit before the owner End. Appending would pass the storage's per-unit cap, so the new lines go to a continuation. The card is kept exactly as published and all 100/100 lines keep their placement, matching main's 800/800.
    • test_evidence_only_sidecars_keep_falls_back_to_main_cuts: two 24-line sources with per-line evidence and no timing stamps. Their longer row would lose it, so validation falls back to main's cuts and 48/48 placements are kept, matching main's 470/470.
  3. Sidecar preparation errors are failures. test_sidecar_failure_during_the_check_is_never_cached:
    • [1]: the crypto failure hits only the first check encode. The retry's bytes are cached with 8/8 placements.
    • [99]: every check encode fails. No bytes are ever cached, and the commit's own encode keeps 8/8, matching main's 80/80 at full scale.
  4. Published live card across re-outline. Design 4. test_reoutline_at_end_keeps_a_published_live_card (cohesion off and on): a 70-line live card is re-outlined at End with a new topic at line 36. It keeps all 70 lines and its id, as in your 702-line case at line 351.

Review items (round 6)

  1. Keep the original custody when a locked append fits Firestore. Fixed (design 3). test_late_speech_into_a_locked_card[storable] uses the real commit codec at a tenth. The grown card lands past the soft limit and below both hard limits, and it appends exactly as on main with no continuation. A probe exception takes main's path. The checked final encoding is what is written.
  2. Split only new speech and bound each row. Fixed (design 3). The same test runs with the real codec at a tenth:
    • [all_ids_revised]: every card source id is replaced with the same words and timing. No park, no duplicate, the card unchanged, and continuations hold only the late recording's lines.
    • [last_id_revised]: only the last id is replaced. No reissued turn, so the line count matches main's.
    • [two_sources]: two individually storable late recordings, together over the hard limit, are partitioned into continuations that each store.
    • [overflow]: the card's transcript and claims are unchanged. The late recording's claims name only the continuations. With routing disabled the pass parks, as on main.
      Continuations carry no parent title or sections.
  3. Merge-path provenance. That path no longer exists: nothing merges.

Review items (round 5)

  1. Bound writes after a locked row grows. Design 3, tested by test_late_speech_into_a_locked_card (round 6 item above). An End-locked card plus high-entropy late speech that would pass the hard limits commits with every row stored; small and storable appends land in the card as on main.
  2. Preserve published live speech. Nothing merges and nothing is inferred. Live cards keep main's append-only growth, and the larger budget only moves the cut later. test_round5_live_counterexamples_never_reshuffle runs two live passes per case:
    • one appended line: the card grows 70 to 71 under its id, where main had a 48-line locked card and a 22-line card growing to 23;
    • revised text under the same ids: the card keeps its id and 45 lines, where main re-cuts to 41 + 4;
    • re-outline naming a new topic mid-card: the open stretch keeps its cached outline, and the card grows under its id.
      test_dinner_density_speech_stays_one_card_through_live_passes_and_end checks one card from the first live pass through End, cohesion on and off, with the same id, a growing extent and all claims naming it. Fallback is the only place a cut could land inside a published row, and there the row is locked at its extent (test_fallback_never_shrinks_a_published_row). Where a genuine new outline topic does apply, a live card splits at it exactly as main splits any live card under its own budget. Main kept 485 lines in the round-5 replay only because its mid-speech size cut had locked them.
  3. Exact serving provenance. There are no merges, so no plan is compared against another. Instead the evidence budget guarantees a longer row never drops evidence main's smaller rows keep. test_three_hour_dense_stretch_keeps_every_placement_main_keeps covers three hours of dense speech, with per-job units and with one large unit where the evidence budget binds. After the commit codec round trip, every line's (provider, unit, label, timing store) is identical to main's, with reveal_segments accepting every sidecar. test_recordings_that_reuse_segment_ids_never_share_a_row checks that two recordings reusing ids land in separate rows with all 64 bindings correct. Earlier merge-only cases now run through the size check: the sibling that inherits a large prior is planned with main's budget and gives main's rows; the matched prior with a large retained overview stores under the limits.

Evidence the timing fallback cannot represent (shadow predictions, live-store stamps) is kept only by per-segment sidecars of at most 256 segments per row. Main's own parts already exceed that at dinner density (main's 483-line part), so this design does not add that loss to main.

Line-count exceptions

Line-Count-Exception: backend/utils/conversations/v3/service.py | 2113 -> 2259 | the planning block and build loop become plan()/build() (re-indented, unchanged) for the size-check replan with deferred effects and the hard-overflow re-cut, plus the locked-row late-append split (Home-hidden speech kept on the visible row with capacity-chosen evidence and its over-limit recovery, owner visibility and End for required continuations) and the rollback gate; the size logic lives in planner.py, v3/size_check.py and v3/locked_append.py

Product invariants affected

none

How it was verified

  • With CI's timing env (test.sh, warn 0.10 s, fail 1.0 s): 45 files pass, 5,102 tests, no timing-guard failure. They cover v3, speaker grouping, offload, write equality, self-heal and recovery, the lifecycle-writer inventory and query shapes. Every new test is at or under 0.05 s CPU.
  • Merged with current origin/main (merge commit, no rebase or force-push).
  • python -m testing.pipeline_lab affected: discard, 16 scenarios; scenario run of all 16: 16/16 passed.
  • Full-scale one-off (above) through the real _plan_projection with production constants.

Tests

backend/tests/unit/test_conversations_v3_engine.py, through the real _plan_projection, encode_row, protect_segments and reveal_segments. main_capped is a literal copy of main's cut, and scaled() divides every size bound (budgets, limits, storage capacities) by 10. Covers:

  • budgets and append-only cuts;
  • exact evidence accounting against the real stored sidecars;
  • the real-shaped dinner staying one row with main's placements;
  • the dinner density staying one row at both protection levels;
  • three hours with identical placements;
  • the two-hour cap;
  • incompressible fallback, cohesion on and off;
  • fallback never shrinking a published row;
  • the matched prior and the sibling prior;
  • reused segment ids;
  • one encode per row off the event loop;
  • evidence without timing stamps;
  • sidecar failures never cached.

backend/tests/unit/test_conversations_v3_live_passes.py, through the real reconcile and commit_projection on StrictFirestore. The new tests write through the real commit codec and read back through decode_row. Covers:

  • checked bytes on every attempt;
  • one card through live passes and End;
  • the round-5 live counterexamples;
  • incompressible speech with the real codec;
  • late appends: small, storable past the soft limit, overflow, all ids revised, last id revised, two sources;
  • same-unit late speech with the switch on and off, an in-claim late turn staying playable, evidence-only overflow keeping claim-bound turns, re-outline at End, and an open card past the hard limits cut as main.

test_conversations_v3_backfill.py parity now ignores the carried encoding, which is the per-encode copy of the row.

UI evidence

UI-Evidence: none -- backend planner change, no UI.

Failure class (fixes)

Failure-Class: new

Failure-class transition narrative (only when needed)

Adds FC-size-cap-measures-proxy-not-stored-encoding (family cross-boundary-contract): a size cap that protects a storage limit must not cut content on a proxy several times the stored size, and correcting that must not trade away the guard's safety. The planner's estimate and the writer's codec disagreed by about 5.6x, so the guard split ordinary conversations at a quarter of the field limit. No existing class states this: FC-permanent-write-rejection-retried-forever covers retrying a rejected write, not the guard's measure.

Canonical guard:

  • keep the monotone proxy as the cutting mechanism, sized so ordinary content stays whole, plus a second monotone budget for each storage capacity a larger unit could exceed;
  • size every row with the writer's codec and write exactly those bytes, falling back to the original budget without shrinking a published row;
  • size-check later appends into locked rows.

Artifacts: backend/tests/unit/test_conversations_v3_engine.py, backend/tests/unit/test_conversations_v3_live_passes.py. Evidence: the production numbers above (this PR).

🤖 Generated with Claude Code

…eech splits)

The SCA-2918 cap estimated each line at 3 * (json + 64) bytes with no
compression, about 5.6x the stored transcript_segments field, so ordinary
long conversations were cut mid-speech near line 400. Measure the field the
derived-row writer stores instead (speaker sidecars, zlib JSON, enhanced
hex + AES-GCM base64), encode the whole part once and binary-search a cut
only when it reaches the 900 KiB budget. The two-hour cap, locked-row cuts
and the CONVERSATIONS_V3_TRANSCRIPT_SIZE_CAP switch are unchanged.

Failure-Class: new
…eplacing it

Round-1 packed rows to 900 KiB of real stored bytes, which leaves no headroom
for subset re-encoding at sidecar capacity, late speech or other fields, and its
prefix search was non-monotone around capacity transitions.

Restore main's additive estimate and _capped cut byte-for-byte. When the
estimate would size-cut a window (offset to the two-hour cut) or block a
resumed merge, measure that window once with the writer's codec (real
protect_segments on a deep copy, seeded sidecar filler, zlib, enhanced
length). At most 512 KiB keeps it whole; otherwise, or on any probe failure
(including evidence encryption), main's cut applies unchanged. No measurement
runs unless the estimate exceeds the budget.

Failure-Class: new
…strict, stable, bounded probe

The pre-routing probe can be fooled when ownership routing restores evidence a
conflict or capacity drop removed. The reconcile pass now builds each
gate-widened fresh or unlocked row after routing and sizes it with the commit's
own codec (conversations_v3.encode_row, transcript inline). Over 768 KiB field
or 900 KiB document, that stretch is planned again with exactly the estimate's
cuts. The gate is opt-in (reconcile only); backfill keeps main's cuts.

The probe budget is 384 KiB; probes are strict in the timing fallback too
(ProbeFailure, distinct from EvidenceCapacity), use a fixed shadow expiry, run
at most twice per stretch per pass, skip windows over 2,000 lines, and the
resumed-merge probe runs only for an otherwise allowed merge. Planning runs off
the event loop.

Failure-Class: new
…heir own modules

conversations_v3_row_codec owns encode_row and stored_size (one codec for the
commit and the size check); v3/size_gate owns the post-routing check. Re-review
the commit_projection query-coverage digest: no new Firestore query.

Failure-Class: new
…al row stores

Planner is main's cut for cut; it only marks boundaries the size estimate alone made.
v3/size_merge re-plans without them, builds the rows as committed, and keeps a merged row
only if every boundary is main's and the commit codec's encoding is <= 768 KiB field and
<= 900 KiB document. commit_projection writes that checked encoding on every attempt.
Removes the pre-routing gate, probes and size_gate.

Failure-Class: new
…og each judged merge

_capped with keep ends a window that would pass the two-hour cap at its last kept size cut
(one of main's) instead of at a new time cut, so stretches over two hours merge between
main's cuts. keep empty is main's behaviour. Each merged row the final-row check judges logs
event=v3_transcript_size_merge outcome=merged|kept_oversize|kept_error|kept_locked parts
field_bytes doc_bytes (no uid, no text). Lifecycle inventory names the moved build() sites.

Failure-Class: new
…rged rows, keep speaker evidence

- size_merge.check encodes every row of the merged plan with the commit codec and carries each
  encoding; any row over the limits or failing to encode means main's rows (kept_sibling).
- FIELD_LIMIT 400 KiB, DOCUMENT_LIMIT 480 KiB: a later late append as large as the row fits Firestore.
- A stored row owning lines on both sides of a main size cut is planned as locked at its extent
  (Ownership.locked_ids), so no plan moves published speech out of it.
- A merge keeping fewer speaker placements than main's rows (commit codec round trip) is rejected
  before build, and its checked bytes are re-read: kept_evidence.

Failure-Class: new
@kodjima33
kodjima33 marked this pull request as draft November 29, 2026 12:19
@kodjima33

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level handing this PR to you (Nik's call). It is now a draft, and nothing here is deployed. Current head is ef35a5cfd1, with CI green.

Root cause. planner._transcript_bytes estimates 3 × (JSON + 64) per line. On real speech that is about 5.6× the stored size, so TRANSCRIPT_BUDGET cuts ordinary conversations mid-speech at about 35 minutes. This came in with #26372.

What this PR does. Main's planner is kept cut for cut. v3/size_merge.py then drops a pure size cut only when the final built rows still fit, checked with the commit codec:

  • every row in the plan stays at or under 400 KiB field and 480 KiB document;
  • all of main's speaker placements are kept;
  • no boundary is added or moved.

The commit writes exactly the checked bytes.

Result on a real 65-minute, two-speaker recording (702 segments). Main cuts it 400 + 302. This PR keeps one row:

  • 282,769 B transcript field and 310,874 B document;
  • all 702 speaker placements kept;
  • recordings of about 2 and 3 hours, and an inflated 4× stretch, keep main's cuts exactly.

Why it can't merge. Round-5 review, three regressions versus main:

  1. Late speech after a merged row locks. In a synthetic high-entropy replay, a 702-line merged card locked at End and then took a separate late recording.
    • Head attempts 1,112,272 B field / 1,115,107 B document and parks. Main commits 855,408 B.
    • The 400/480 KiB headroom cannot bound later speech.
    • Needed: size-checked late appends that route overflow to a durable continuation and keep existing claims (planner.py late-append ownership, service.py:1061–1076). Without that, keep main's cut whenever a merged row can still receive late speech.
  2. Inferred pinning reshuffles published cards. Seen in replays:
    • a re-outline rewrote a 702-line card to 350;
    • one appended line closed a live merged card and opened a one-line card;
    • a never-merged card whose text was revised got pinned at 350, where main cuts 313 + 37.
    • Needed: no size merges for provisional rows (v3_unlocked) and no inferred pin, or explicit persisted merge provenance with normal active-card growth.
  3. The speaker check compares counts.
    • Equal counts hid 320 wrong bindings: two recordings reused segment ids with different batch units, so the timing reveal bound 320 lines to the wrong scope and label.
    • A transient sidecar failure on an unchecked sibling carried 0 of 80 placements.
    • Needed: compare the exact per-line tuple (provider, unit, label, timing store) against main's built rows for every checked row, and reject on reveal or authentication failure.

Rounds 1–5 of the review notes and the real-recording replay harness are with Nik. The harness runs planner._capped, size_merge.evidence_lost and size_merge.check with the real codec on a stored recording; ask him for the recording ids. Your call whether to finish this design, or fix the estimate in the planner itself (a monotone, codec-aware estimate would avoid merging entirely).

@kodjima33

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level assigned to you. Two questions only you can answer:

  1. Custody piece. Will you take the late-speech continuation for locked rows, merges only for non-provisional rows, and the exact provenance check? Or would you rather fix the estimate in the planner itself, so nothing merges? Either way, nothing here ships until your change passes review. When you push, I'll re-run the real-recording replay and an independent review on your head.
  2. backend-sync release. backend-sync still serves afab956 from Nov 26. The next deploy also carries every backend merge since then, plus the runtime-env cutover (flag source posthog, shadow lanes off, retired names removed). Is backend-sync held on purpose? Once your fix is verified, do you want to promote it yourself, or should I run the named gcp_backend.yml deploy with an hour of monitoring and a rollback ready?

@kodjima33

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level update: per Nik we're taking this back and finishing the custody piece here (round 6: size-checked late appends with a continuation row, merges only for final rows, exact provenance). No need to pick it up; review is welcome.

…nal rows; exact speaker provenance

- v3/locked_append: a locked row gaining late lines is encoded with the commit codec first; over
  768 KiB field or 900 KiB document it keeps exactly its published lines and claims and the late
  lines go to a new continuation row. Applies to every locked row, main's included.
- size_merge: remove the inferred pin; a merged row must commit final in this pass
  (not planner.is_unlocked), so live and provisional cards grow exactly as on main (kept_live).
- size_merge: every line occurrence of the candidate plan must decode and reveal to exactly the
  provenance (provider, unit, label, timing store) of main's built rows; any reveal rejection,
  decode failure or changed binding means main's rows (kept_provenance).

Failure-Class: new
…-evidence budget, every row size-checked

Production: all 215 mid-speech size splits in 24 h were made while the stretch was live, so the
final-only merge could not apply. The size merge, provenance comparison and their hooks are gone.

- planner._capped keeps main's append-only cuts, two-hour cap, locking and ownership. A size cut
  lands at TRANSCRIPT_BUDGET = 2 x 900 KiB, or before the part's speaker evidence passes 70% of the
  timing-fallback caps (per line from the compact record the storage writes), or before a segment
  id it already holds.
- v3/size_check encodes every row with the commit codec; a stretch with a row over 768/900 KiB is
  planned with main's 900 KiB budget, a published row it would cut locked at its stored extent.
  Rows are written as exactly the checked bytes.
- v3/locked_append (round 6) unchanged: late lines past the limits go to a continuation row.

Failure-Class: new
…ontinuation only past Firestore's hard limits, for new speech only

- planner._Evidence counts each unit's envelope exactly as speaker_grouping_storage serializes it,
  the compact-record total and their exact encrypted lengths, against 95% of each hard cap, and ends
  a part before a unit's second timing store. The owner's 702-line dinner (units of 679 and 23
  lines) is one row; the 70% margin had split it 609 + 93.
- locked_append routes late speech only when the grown row, with the commit's settle stamp, would
  pass Firestore's hard limits; a failed probe takes main's path. Held vs new speech uses the row's
  own append dedupe (planner.present_in, extracted unchanged from build). Continuations are cut by
  main's budget and carry no parent title or sections; with nothing held the locked row is left
  unwritten.
- size_check carries every row within the hard limits as its final encoding, and replans only
  planned (not locked) rows past the soft limits.

Failure-Class: new
…tally's fields for the type checker

Failure-Class: new
…d rows past hard limits; keep a published live card across re-outline

- size_check.prepare encodes as the commit writes (codec and settle stamp) and reads back every
  line's speaker placement from those bytes; a degraded encode is retried once and never cached.
  Evidence loss on a planned row plans its stretch with main's budget; only storable, intact bytes
  are carried.
- A row with a stored prior still past a hard limit freezes that prior: kept exactly as stored with
  its claims, its new lines in bounded successors.
- locked_append routes late speech to continuations when the grown row would lose speaker evidence,
  not only past the hard limits; continuations are cut by bytes and evidence.
- commit_projection refuses any staged row or source claim update past Firestore's hard limits
  before it is sent, with Firestore's own rejection, so the existing park path applies.
- planner keeps a published live card longer than main's budget whole across a re-outline: a topic
  starting inside it becomes a section.

Failure-Class: new
…ished-extent re-outline, quiet probes

- A frozen prior is built as a locked row over the lines it holds: stored transcript and claims kept,
  End and processing still run on it; only new speech moves.
- staged_sizes measures each field value and the document by Firestore's storage-size rules, shared by
  the size check and the commit guard, after the configured settle stamp; a guard rejection names
  its conversation id for the one-seed size quarantine.
- Re-outline protection is decided by what the card published (its stored lines), only with the size
  cap on; ownership just locates it.
- Candidate and probe encodes are quiet; speaker_grouping_storage.quiet() reports codec failures apart
  from capacity drops. Exceptions and degraded results retry once; a codec that keeps failing leaves the
  row to the normal writer instead of routing or replanning.

Failure-Class: new
…ty; codec faults and telemetry follow the written payload

- locked_append.split holds every line inside a span the row already claims (re-issued ids or text),
  as well as the append dedupe; frozen and overflowing locked rows write exactly their stored
  transcript, and only unclaimed speech goes to continuations.
- planner.build marks v3_size_extended once a card's lines exceed main's budget under the size cap;
  the mark survives live rewrites and re-outline protection reads it only with the size cap on.
- size_check.prepare treats any codec fault (encode, encryption, authentication, readback) as no
  cache plus one retry; a persistent fault leaves the row to the normal writer. Quiet encodes keep the
  outcomes they suppressed, and the final plan reports them once for each payload written as checked.
- lifecycle inventory declares locked_append.as_locked, a read-only builder view.

Failure-Class: new
…rs the card's claimed span; telemetry after the write lands

- Rule A: Ownership.freeze makes a frozen row own, as a locked run, every line whose audio overlaps
  its claims by any amount (planner.claimed_overlap, also used by locked_append.split). planner.build
  builds a frozen window over the stored transcript alone, so extent, claims, v3_size_extended and
  sync_content_revision are the stored version's own. Removes locked_append.keep_published/as_locked.
- Rule B: an outline cut inside a protected card's claimed audio interval becomes a section,
  whoever owns the neighbouring lines; on a finished stretch preserve_finished_windows holds the
  card's own lines apart, so an unowned turn inside gets its own row.
- The suppressed speaker-storage outcomes travel with the checked encoding and are reported once,
  after that row's successful write (report_written); a discarded plan reports nothing.

Failure-Class: new
…seed quarantine

A published row exceeds Firestore's hard limits only if the same audio's stored transcript more than
about doubles (rows publish near 330-400 KB and the pre-commit check bounds new rows at 768 KiB).
That case now takes main's own overflow path: the exact staged guard refuses the write before it is
sent, naming the document in Firestore's message, and the pass parks with the one-seed quarantine.

- Removes Ownership.freeze and frozen_ids, planner.claimed_overlap, the frozen build window and its
  service hooks, and size_check's hard set.
- Locked late appends classify held vs new speech with main's own append dedupe again.

Failure-Class: new
…aim late turns stay on the locked card

Round 14 review of #26705:
- A commit-guard rejection of the lease's open window is charged to the seeds whose claims feed it, and load skips that window while all its sources are quarantined, so independent recordings keep committing.
- An overflowing locked append keeps new turns inside the card's own claimed audio on the card when it still fits; only the rest goes to continuations, so every routed turn stays playable.

Failure-Class: new
…m-bound late turns stay; honor the size-cap switch

Round 15 review of #26705:
- A published open card that fallback would keep at its stored extent but whose rebuild passes a hard limit is released and cut by main's budget, so the pass commits main's partition. The round-13/14 park attribution and the open-window load skip are reverted to main; locked rows keep main's park.
- A locked append that overflows keeps every new turn inside the card's own claims whenever that is within the hard limits, even past full-evidence capacity (the codec's fallback, as main); only speech outside its claims is routed.
- CONVERSATIONS_V3_TRANSCRIPT_SIZE_CAP=off runs main's plan, append and writer, keeping only the staged hard-limit guard.

Failure-Class: new
…en late speech stays on the visible card

Round 16 review of #26705:
- An open row whose rebuild fails the hard check joins Ownership.released, which both the stored-extent pin and _keep_published skip, so the retry applies the actual topic and size cuts instead of rebuilding the whole card into the guard.
- During evidence-only overflow of a locked append, a continuation Home would hide as its own row is not created; its speech stays on the visible card without its own placement.
- The words replay asserts main-budget compliance and the safety properties, not an exact partition.

Failure-Class: new
…placement that fits; required continuations show as their owner

Round 17 review of #26705:
- The hard release installs main's 900 KiB budget for the stretch before retrying, so the released outline and size cuts apply together (main's partitions from the same wide card).
- Speech kept on the visible row during evidence-only overflow keeps its own placement unless that would cost one the row keeps without it (probed both ways on the commit's bytes).
- A continuation the hard limits require under a visible owner carries the owner's passed word gate, so it is visible on its first write.

Failure-Class: new
…ate-turn evidence chosen turn by turn

Round 18 review of #26705:
- A continuation the hard limits require records its owner (v3_home_owner) and, on every build while the owner stands, takes the owner's effective Home fields, whatever its own classification; its kind and End ownership are untouched.
- Home-hidden late turns kept on the visible row are walked in order: each keeps its own placement only if a probe with it keeps every placement already retained within the hard limits. A locked row's probed storable bytes are the ones committed.

Failure-Class: new
…he planned owner; capacity-chosen late evidence

Round 19 review of #26705:
- A continuation (v3_home_owner) takes a window's End only for a distinct End after its owner's cut, so re-arm keeps one End and leaves a settled continuation settled.
- A continuation's Home visibility comes from its owner as planned in this pass, else as loaded, and is persisted on its row.
- Short late turns' evidence is chosen by the storage's capacity rules (sidecar totals, then the timing fallback tally at the hard caps), with no probes; the commit's own encode is the one real-codec check, with at most one retry. The review's 200-turn case: 7.3 s -> 165 ms per pass (main 155 ms), 204 -> 2 encodes of the card.

Failure-Class: new
… continuations resolve their owner on narrow loads

Round 20 review of #26705:
- The evidence choice skips lines whose sidecar the reader cannot reveal (position MAX_SEGMENTS or later). Bytes past a hard limit count as hard even with a readback fault. A row whose chosen evidence fails the hard check routes its late turns outside the claims to visible continuations on the next attempt, or appends as main if the kept row still cannot store, so the pass never parks on its own choice.
- store.load reads a continuation's absent owner by id (cut, Home fields, deletion flags); a continuation takes a new End only on a resolved owner's distinct later cut, and its v3_home_owner link clears once the owner is deleted or discarded.

Failure-Class: new
…ing for the owner's End; keep the End receipt

Round 21 review of #26705:
- Every reduced locked row accepted without a probe in the evidence-only path is checked by the commit's own encode; past a hard limit the next attempt routes its late turns only if the probed reduced row stores, else appends as main (the measured full append), never parking.
- A continuation whose outline failure recovers on open clears the failure without a processing obligation for the End its owner holds.
- A continuation keeps its owner's cut as v3_home_owner_cut when the link clears; a row that is or was a continuation takes an End only after that cut.

Failure-Class: new
kodjima33 added a commit that referenced this pull request Nov 30, 2026
…connect (#26749)

## What changed and why

A socket reconnect mid-speech seals the current batch recording and
opens the next one on the same device at
once. The next recording has no transcript until it seals, so the v3
builder read it as silence: the first card
locked at the five-minute rule, and the rest of the conversation became
a second card when it landed.
`CONVERSATIONS_V3_CAPTURE_CONTINUITY` (on by default) did not cover
this. `load()` kept a stretch open only for a
following recording that was already `v3_pending`.
`_mark_successor_pending` held one only behind a
rotation-stamped seal, which is off in prod, and only when that source
spoke last.

Synthetic shape of the incident: recording A runs 0:00 to 2:56, the
socket drops, and A seals at 3:00 as B opens
on the same phone. B captures ten more minutes of the same talk and
lands 11 minutes after A ended. On `main`,
A's card locks and gets notes about five minutes after A landed, and B
becomes card 2.

The fix, under `CONVERSATIONS_V3_CAPTURE_CONTINUITY`:

- **Which sources.** Any loaded recording whose latest server seal came
within 90 s of its last line
(`policy.LIVE_SEAL_GAP`, either way within 10 s, `policy.CAPTURE_SKEW`).
- The seal clock is `record_sealed_at`, else
`home_transcription_pending_at`. It is never `finished_at`, which is
    the last archived audio frame.
- A quiet seal comes at least 120 s after the last speech, so it never
qualifies and reads nothing.
  - A source the user ended with Finish does not qualify.
- **Which successor** (`database/conversations_v3.py`
`_mark_successor_pending`): the next `batch_live_v1` capture
  from the same `client_device_id` that opens within 90 s of that line.
- Each such seal gets its own `started_at` window query anchored at its
last line, most recent seal first, read
    in pages of 16 (`SUCCESSOR_PAGE`).
- All the lookups of one pass read at most 64 documents
(`SUCCESSOR_READS`; an empty query counts as one).
- The first successor the user ended (a requested or applied Finish)
fences off every later capture, even
once it is discarded with its Finish kept. Any other discarded successor
never holds.
- **Rotation is `main`'s, under either setting.** Its lookup and hold
are `main`'s code: a successor still capturing
within the cap, or processing within 15 min of `finished_at`, marks a
page continuation
(`policy.awaiting_transcript`, unchanged). The clocks and proof below
apply only to the reconnect lookup, after
  the continuity flag and the device and lane match.
- **Which stretch.** A held source carries `outline.SUCCESSOR_HOLD`. The
last stretch holding it stays open
  whichever device spoke last. Earlier stretches settle.
- **How long** (`policy.successor_hold_until`, absolute deadlines on
server stamps that do not move):
  - While capturing: up to 15 min after `created_at`.
- After a first close inside that window: up to 15 min after it, never
past both windows. The first close is the
earliest of `record_admitted_at`, `home_transcription_pending_at` and
`record_sealed_at`.
- A close after the window starts no wait. An expired hold stays expired
through a late close, a reseal or a
    retry.
- A Finish bounds every wait to 5 min (`FINISH_WAIT`) after its trusted
request time, `v3_finish_requested.at`.
    Without that stamp, the bound runs from the first close.
- Failure receipts are checked before status. Stamps more than 10 s in
the future never hold.
- **When it has landed** (`_capture_landed`):
- Proven silence: `empty_transcription.terminal`, whose empty spans
cover the closed audio.
- The durable proof that every unit of the latest seal landed:
`capture_end.units_landed`. Batch projection now
writes `record_units_landed_seal_at` (the seal the job covered) in the
transaction that commits the
authoritative sibling completion
(`database/batch_pipeline_projection.py`), last in that transaction and
only
    while the row still carries that seal.
- For seals completed before that proof existed: the capture ledger's
best-effort `transcribed` transition after
the latest seal (`capture_end.seal_proof`). It is one read with a 3 s
timeout and no retry, memoized per
    successor per pass.
- A first projected unit proves nothing, silent or not, nor does a unit
held for recovery (`units_held`).

## Round 5: the two review items on `17a21f9e3d`

1. **Rotation is exactly `main`'s.** The rotation scan no longer calls
`policy.successor_hold_until`; its loop is
`main`'s, line for line, except that it stops at the silence gap with
`break` so the reconnect lookup still runs.
- The review's case now settles: A rotated at 300 s, B opened then on
another device and closed at 400 s into the
server-batch handoff (`completed`, `home_transcription_pending_at`, no
speech yet). At 621 s A's card locks
with its notes queued, with capture continuity on or off, as on `main`.
- The round-3 rotation case still holds: B queued with `finished_at` 610
s and no close stamp keeps A open at
     620 s, and B joins it at 650 s.
2. **Line-count exception matches the file.**
`backend/database/conversations_v3.py` is 2,678 lines (2,511 on
`main`), and the exception below says so. Validated with this body by
`make preflight`.

## Round 4: the two review items on `d5c20e5eb9`

1. **`main`'s rotation wait is back.** Rotation successors no longer go
through the reconnect policy first.
- `policy.awaiting_transcript` (main's rule) decides and marks
`_v3_page_continues`, as on `main`. Where it let
     go, the reconnect wait still ran; Round 5 removes that.
- The review's case now holds: A rotated at 300 s, B still in
finalization with `finished_at` 610 s and no close
stamp, capture continuity off. At 620 s A stays open, and B joins it at
650 s.
- The rotation tests in `test_conversations_v3_review.py` are `main`'s
again, unchanged.
2. **A discarded successor's stored Finish still fences.** After the
device and lane match, a discarded successor
   carrying its Finish ends the scan without holding A.
- The review's case now settles: B's Finish at 228 s, C opened at 229 s,
then B discarded with the Finish kept.
     A is not held at 529 s or 598 s.
   - An ordinary discard only releases B.

## Round 3: the three review items on `5a03416141`

1. **Finish is bounded by its original request.**
   - `v3_finish_requested.at` is projected and drives the 5 min bound.
- The ordinary wait runs from a stable first close, so a moved seal
cannot extend it.
   - The latest seal generation is used only for the landed proof.
   - The immediate successor's Finish fences off later captures.
- The review's cases: a Finish at 300 s with the close at 460 s releases
by 601 s; a seal moved to 597 s still
releases by 670 s; with B finished at 228 s and C opened at 229 s, A is
not held at 529 s.
2. **Unrelated rows cannot exhaust the lookup.**
- Each live seal has its own window query, most recent first. The
rotation query is unchanged from `main`.
- Pages continue past cards and other devices' rows, and total reads
stay at most 64 per pass.
- The query-shape driver observes both shapes. Both are single-field
`started_at` ranges, so no index is needed.
3. **Durable whole-capture completion, bounded lookups.**
   - Projection persists the seal it proves with the sibling completion.
- With no proof, an absent ledger no longer counts as complete, and
`units_held` no longer releases.
- A stale ledger after all speech landed releases promptly on the proof.
- The ledger fallback is memoized per successor per pass with a 3 s
timeout: twelve matching sources read it
     once.

## Expected latency cost

- **Quiet seals** (how a conversation normally ends): no change, and no
extra read.
- **Reconnect mid-speech, then the talk goes on:** one card. It locks on
the normal lock delay after the rest of
  the capture lands.
- **Reconnect mid-speech, then silence:** the card can arrive up to
about 10 min later than today. A batch row the
socket created that has heard no speech stays open while the socket
streams
(`utils/stt/speech_clock.quiet_since`,
`FC-transport-liveness-read-as-speech-activity`).
- **Worst case, about 30 min after the reconnect:** the capture runs
almost 15 min, closes, and its transcript
  never lands.
- **A capture running past 15 min after a reconnect:** still splits, up
to 10 min later than today. Listen
  resuming the same recording on reconnect would remove that case.
- **The user ends B:** the hold lasts at most 5 min after the Finish
request, however late the close.
- **A successor with no proof** (its projection completed before this
deploy, and no ledger `transcribed`): it waits
  out its bound, 15 min after its first close.
- **Reads while held:** the existing follow-up wake runs a pass about
once a minute. Each pass reads the successor
windows, at most 64 metadata documents (usually one or two), plus,
without the durable proof, one ledger
  document per partly projected successor.
- **Rollout order:** the proof writer runs wherever batch projection
completes; the hold runs on `backend-sync`.
Until the writer is live, holds release on the ledger's `transcribed` or
wait out their bound.

## Product invariants affected

none

## How it was verified

- **Replays fail on the old code.** The multi-pass replays use the real
loader on a query-capable copy of the strict
Firestore rows, with the real `service.reconcile` and
`commit_projection`.
- On round 4's loader (`17a21f9e3d`), the round-5 regression fails with
capture continuity on and off, as the
review found. On `main`'s loader it passes with both. The round-3
rotation cases pass on all three.
- On round 3's product files (`d5c20e5eb9`), the round-4 regressions
fail as the review found: the rotation
successor still in finalization past the cap (loader case and
continuity-off replay), and the discarded B whose
    Finish must fence C. The ordinary-discard control passes on both.
- On round 2's files (`5a03416141`), the round-3 replays fail: a silent
first unit with no ledger, a stale ledger
with all speech landed, and a Finish with the close 160 s after the
request.
  - On this head everything passes.
- **Mutation checks.** Without its device match, the reconnect lookup
fails the round-5 regression with continuity
on. Each round-4 rule was removed in turn, and each removal failed its
own test:
  - a discard dropping its Finish fence;
  - a discard able to hold;
  - no `main` rotation rule;
  - the rotation flag made group-wide.
- **Round 3 rule checks, still caught:**
  - no Finish fence;
  - a single page;
  - no landed memo;
  - ignoring the durable proof;
  - round 2's ledger rule;
  - the writer stamping no proof;
  - the writer ignoring the seal generation;
  - the latest seal as the wait anchor;
  - Finish timed from the close;
  - accepting a future Finish;
  - oldest cut first.
- **Pipeline lab.** All 17 committed scenarios, `--jobs 4 --repeat 2
--stt replay`: every check passed in both runs
  (552.8 s on a loaded host).
- Three scenarios were flagged nondeterministic only by one
`account_deletions` read between repeats, the
account-deletion check's wall-clock cache. Rerun alone, all three passed
deterministically with the same counts.
- Round 3's traced run refreshed `reach.json`, which lists
`utils/sync/capture_end.py` for the four reconnect
scenarios. Rounds 4 and 5 add no file to any scenario's reach, so it
stands.
- `reconnect_successor_lands_late` passes 9/9 within budget, at 367
reads.
  - Other scenarios' counts are unchanged.
- The lab's transcript stand-in now stamps the completion proof, as
production's sibling completion does.
- **Unit suites.** 158 suites ran under the CI per-test budget
(`BACKEND_UNIT_TEST_FILE_LIST=... bash test.sh`): all
`test_conversations_v3*`, `test_pipeline_lab*`,
`test_batch_pipeline_projection*`, capture-end, record-seal and
server-batch-completion files. All 158 files passed: 5,042 tests, none
failed.
- **Firestore index guard set** (7 files, 928 passed, including 644
query-shape tests): the
`_mark_successor_pending` driver runs a rotation source and a live-cut
source, and records both shapes:
`started_at >` with limit 8, and the `started_at` window with limit 16.
Both are single-field ranges, so no
  composite index is needed.
- **Type check:** `scripts/typecheck.sh` reports 0 errors.
- **Preflight:** `make preflight` with this body passed 40 of 41 checks,
including the line-count exceptions,
the failure class, the index guard and the lifecycle write guard. The
one failure is `feature-flag-registry`
at today's date: 82 flag reviews due 2026-11-22 are past their grace,
repo-wide, and this PR changes no flag.
  `scripts/check_feature_flag_registry.py --as-of 2026-11-29` passes.
- **Not yet seen in production.** This is not deployed, and no real
reconnect on a deployed backend has run through
it. The hold runs on `backend-sync`; the proof writer runs wherever
batch projection completes.

## Tests

`backend/tests/unit/test_conversations_v3_successor_hold.py` (71 cases):

- **Round 5:** rotation lets a closed capture from another device go as
`main` does: a multi-pass replay of the
  review's case, with capture continuity on and off.
- **Round 4:**
- Rotation keeps `main`'s wait for a same-device batch successor still
in finalization past the cap, as a loader
    case and a continuity-off multi-pass replay.
- A discarded successor keeps the fence of its stored Finish; an
ordinary discard only releases it.

- **Loader matrix:**
  - Capture window, and first-close waits and bounds.
  - A reseal after the first close.
- The Finish request bound: request at 300 s with the close at 460 s, a
seal moved to 597 s, a Finish while
    capturing, and a future Finish.
- Proof present with a stale ledger, proof of an older seal, and units
held for recovery.
- One unit projected; no proof and no ledger; transcribed; transcribed
before a reseal.
  - Complete silence, and silence on the first unit only.
  - Failure receipts, and future stamps.
  - Device, lane, sync, deleted and discarded.
  - Window bounds.
- **A finished successor fences off a later capture** (B finished at 228
s, C opened at 229 s, A free at 529 s).
- **Crowding:** 24 other-device captures plus 16 cards are paged through
in three pages; past 64 documents the lookup
  stops.
- **Lookup order:** the newest cut is looked up before an older crowded
one, and rotation keeps its own lookup
  beside a crowded earlier cut.
- **Twelve sources matching one successor:** one ledger read, with the 3
s timeout; zero reads with the durable proof.
- **The real projection completion** stamps the seal it proves after the
last sibling, and writes nothing for a job
  admitted before a reseal.
- **Round 2 cases kept:**
  - A late seal stays expired.
  - Quiet rollover and skew read nothing; continuity off reads nothing.
  - Interleaved device, and an earlier independent stretch.
  - 18 cards in the window.
  - Two reconnects in a row.
  - Finish and owner End still end the stretch.
- **Multi-pass replays:**
  - The incident, with continuity on and off.
  - A silent first unit with the ledger absent, transcribed, or stale.
  - Another device speaking last.
  - A requested Finish, closed at once or 160 s late.

Each test runs at or under the 1.0 s CPU budget.

Elsewhere:

- `test_conversations_v3_review.py`: back to `main`'s rotation tests.
`MemoryQuery` accepts read options (timeout,
  retry) and `<`.
- `test_batch_pipeline_projection.py`: the completion helper takes an
optional `job`.

## UI evidence

UI-Evidence: none -- backend-only change

## Failure class (fixes)

Failure-Class: FC-live-settlement-uses-capture-clock

Line-Count-Exception: backend/database/conversations_v3.py | 2511 ->
2678 | the successor hold extends the loader's existing check in place
beside #26705's edits to the same file; splitting the store is out of
scope for an incident fix
Line-Count-Exception: backend/database/batch_pipeline_projection.py |
1567 -> 1582 | the completion proof must commit in the
sibling-completion transaction that already lives here

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Round 22 review of #26705: the on-open outline recovery recognized a companion only by its live v3_home_owner link, which clears once the owner is deleted. It now also recognizes the persisted End receipt (v3_home_owner_cut), so a companion without a distinct End of its own clears the stale failure with no processing; one that owns a distinct End keeps ordinary recovery.

Failure-Class: new
@kodjima33
kodjima33 marked this pull request as ready for review November 30, 2026 03:55
@kodjima33
kodjima33 merged commit 743bd94 into main Nov 30, 2026
60 of 61 checks passed
@kodjima33
kodjima33 deleted the fix/v3-transcript-real-size-cap branch November 30, 2026 03:56
@kodjima33

Copy link
Copy Markdown
Collaborator Author

Prod deploy status (04:37 UTC Nov 30): backend-sync and backend-integration serve 743bd94 (this PR + #26749) at 100%.

How it got there:

  • Release Eligibility on main is red only from the date-based feature-flag-registry check, so the omi-deployer build-only train is paused.
  • The all-services break-glass run 46350705740 built and validated no-traffic revisions for the four services. It then stopped at the live runtime-env check on backend-projection-pump, which is not in the deploy scope and has drifted from the manifest since its Nov 24 revision. That check blocks every cloud_run_service=all deploy until the pump is redeployed.
  • The workflow-built revisions differ from the serving ones only in OMI_BACKEND_RELEASE_SHA (same env names/values, scaling and resources). I promoted them by hand after a 10 min 10% canary: integration 5xx 0% vs 0%, sync 5xx 47.3% vs 46.9% (designed backpressure), error logs per request at parity, no new exception types.
  • backend and backend-sync-backfill are unchanged. Rollback: backend-sync-p1da636a-98832 / backend-integration-p1da636a-98850 at 100%.

Post-deploy: 60 min watch running, plus a prod reconnect repro (baseline produced 2 cards for one call).

kodjima33 added a commit that referenced this pull request Nov 30, 2026
… lost within the soft limits

After #26705 the size check still replanned a stretch at main's 900 KiB estimate budget
when the commit codec dropped speaker placements past the per-segment sidecar capacity,
even though the stored bytes were far under the store caps. The re-cut never restored the
evidence and only split the conversation mid-speech. A row within the soft limits now
carries its probed bytes (main's writer bytes, placements degraded to the timing markers);
rows past the soft limits replan exactly as before.

Failure-Class: FC-size-cap-measures-proxy-not-stored-encoding
kodjima33 added a commit that referenced this pull request Nov 30, 2026
… lost within the soft limits

After #26705 the size check still replanned a stretch at main's 900 KiB estimate budget
when the commit codec dropped speaker placements past the per-segment sidecar capacity,
even though the stored bytes were far under the store caps. The re-cut never restored the
evidence and only split the conversation mid-speech. A row within the soft limits now
carries its probed bytes (main's writer bytes, placements degraded to the timing markers);
rows past the soft limits replan exactly as before.

Failure-Class: FC-size-cap-measures-proxy-not-stored-encoding
kodjima33 added a commit that referenced this pull request Nov 30, 2026
… lost within the soft limits

After #26705 the size check still replanned a stretch at main's 900 KiB estimate budget
when the commit codec dropped speaker placements past the per-segment sidecar capacity,
even though the stored bytes were far under the store caps. The re-cut never restored the
evidence and only split the conversation mid-speech. A row within the soft limits now
carries its probed bytes (main's writer bytes, placements degraded to the timing markers);
rows past the soft limits replan exactly as before.

Failure-Class: FC-size-cap-measures-proxy-not-stored-encoding
kodjima33 added a commit that referenced this pull request Nov 30, 2026
…lity as bounded streams (#26787)

## What changed and why

#26705 (live on prod `backend-sync`) keeps v3 cards whole up to twice
the old estimate budget, about 600 KB of decoded transcript. v3 write
equality (`_same_transcript`) decoded stored transcripts through public
chat's inline bound (256 KiB stored, 512 KiB decoded). It could not
compare such a card even with itself, fell back to a write, and every
unchanged re-arm rewrote the card.

**Change (write equality only;
`backend/database/conversations_v3_write_equality.py`).**
- Main's comparison runs first, unchanged.
- When main's bounded decode refuses a transcript **for its size**
(stored past 256 KiB or decoded past 512 KiB on either side), the two
stored transcripts are compared as streams. A transcript refused for its
shape (for example a 257-character anchor) still writes, as on main.
- Each field must pass the writer's own field check
(`estimate_firestore_value_bytes` ≤ `HARD_FIELD_LIMIT`, as
`guard_staged` measures) on the stored representation, before
decryption.
- Enhanced fields are authenticated and decrypted. Both are decompressed
in 64 KiB chunks and compared byte for byte, without parsing.
- Supported envelope: the writer's field limit, at most 32 MiB decoded,
and no grouping sidecar. Sidecar ciphertext differs on every encode and
needs serving validation. Anything outside the envelope writes, as on
main (`EQUALITY_UNAVAILABLE`).
- **Shared chat is unchanged** and keeps main's bounded reader. It is
publicly reachable and saw 0 requests in 24 h.

## Production measurement (metadata only, 24 h to Nov 30 15:11 UTC)

- `omi_conversations_v3_equality_unavailable_total` in namespace
`backend-sync`: **12,969** equality fallbacks.
- Rows over the same window (`omi_conversations_v3_projection_rows`,
`backend-sync`): **680,192** written and **4,140,516** skipped as
unchanged. So about 1.9% of written rows fell back.
- The counter has no reason label, so the share caused by this bound is
**not measured**. The once-per-process `omi_fallback_event
from=elide_write` log line matched nothing in 24 h.

## Verification

- **Live passes:**
`test_a_large_stored_card_compares_equal_and_unchanged_rearms_write_nothing`.
Production loader, real codec, strict commit fixture.
- Input: 600 evidence-free lines plan as two cards; the large one
decodes past 512 KiB.
- New code: two unchanged re-arms stage **0** writes, and a real change
(a late turn) still writes exactly one row.
  - Main: rewrites the large card on the first re-arm.
- **Bounded memory:**
`test_a_large_transcript_compares_in_bounded_memory[standard|enhanced]`,
measured with `tracemalloc`.
- Standard: 62,000 segments, 544,725 B stored, 16,086,670 B decoded.
Equal in **1.95 MiB** peak and 0.024 s.
- Enhanced: 30,000 segments, 704,120 B stored, 7.8 MB decoded. **2.27
MiB** peak.
  - A one-segment change compares unequal.
- The test asserts peak < 3 × stored + 4 MiB. It fails on 2efdc2f,
which materialized the card; the review measured +453 MiB RSS there.
- **Writer limit:**
`test_a_transcript_field_past_the_writer_limit_is_never_equal`. The
enhanced case has compressed bytes within the limit but an encrypted
string past it, the review's 1,203,529 B shape; a standard field is past
the limit too. Neither is ever equal. It fails on 2efdc2f.
- **Sidecars:**
`test_a_large_transcript_with_a_grouping_sidecar_still_writes`.
- **Shape refusals:**
`test_a_small_transcript_refused_for_its_shape_still_writes`, which
fails on e6975ad. The emulator proof
`test_projection_writes_when_inline_anchor_is_rejected` passes locally
on the Firestore emulator, 19/19 in that file.
- **Suites:**
  - All `tests/unit/test_*v3*.py`.
- Every test file touching the bounded decoder, write equality or shared
chat, one process per file.
  - All affected lab scenarios.

## Product invariants affected

none

## Failure class (fixes)

Failure-Class: new

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Git-on-my-level pushed a commit to Git-on-my-level/omi that referenced this pull request Nov 30, 2026
…hat the writer stores

BasedHardware#26705 keeps v3 cards up to ~600 KB of decoded transcript, but shared chat and v3 write
equality decoded through public chat's inline 512 KiB bound. Shared chat rejected those
cards and write equality could not compare them, rewriting each on every unchanged
re-arm. Both readers now decode within writer-sized limits (Firestore's field limit,
a 16 MiB decode ceiling, 65,536 segments).

Failure-Class: new
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.

2 participants