Skip to content

fix(v3): split derived windows before transcript_segments exceeds Firestore's 1 MiB field limit (SCA-2918) - #26372

Merged
Git-on-my-level merged 4 commits into
mainfrom
lane/v3-window-size-cap
Nov 26, 2026
Merged

Git-on-my-level merged 4 commits into
mainfrom
lane/v3-window-size-cap

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

What changed and why

SCA-2918. Firestore rejects an oversized inline transcript_segments field and reconcile retries the same projection. Bound new derived windows with a deterministic 900 KiB estimate that accounts for enhanced encryption. Use the existing continuation path for IDs, claims, and audio custody. The default-on CONVERSATIONS_V3_TRANSCRIPT_SIZE_CAP kill switch disables future size cuts when set to off. Split logs carry no owner identifiers.

The prior failed projection leaves its recordings pending. The next reconcile retries from those recordings and commits capped continuations. The planner adds no reads or queries. Continuations add row writes and their normal transaction fences, and a larger projection can take the existing multi-batch path. Previously locked rows keep their boundaries. A single source segment is atomic, and this cap does not repartition locked rows that grow through late speech.

Product invariants affected

none

How it was verified

215 focused backend fixture tests passed through omi-heavy run -- timeout 900, including the engine, claim growth, live passes, fragmentation, sit-down, stretch cohesion, and lock timing suites. The feature flag registry check passed.

After rollout, confirm zero backend-sync is longer than 1048487 bytes errors and corrected reconcile 5xx back at baseline.

Tests

The strict Firestore fixture rejects the oversized derived union of two individually bounded recordings with the switch off. With the default restored, the next reconcile commits the continuations, preserves all segment IDs, and clears pending state. Planner fixtures also verify stable continuation IDs and enhanced-codec headroom in both planner modes.

UI evidence

UI-Evidence: none

Review follow-up

A Firestore per-property rejection (The value of property "transcript_segments" is longer than 1048487 bytes) now classifies as document_too_large. The owner parks with the existing backoff (5 min doubling to 1 h) instead of Cloud Tasks retrying a 500 forever. This also covers residual oversize rows the planner cap cannot split, such as a locked row grown by late speech. The split event is also logged when the size budget blocks a resumed merge, and the v3 runbook documents the switch.

Line-Count-Exception: backend/utils/conversations/v3/service.py | 1614 -> 1615 | redacted_cause recognizes the per-property size rejection with inline string checks (event loop; the async-blocker gate rejects a store call there).
Line-Count-Exception: backend/database/conversations_v3.py | 1771 -> 1772 | One marker constant for the per-property size rejection beside the existing size markers.

Failure class (fixes)

Failure-Class: FC-permanent-write-rejection-retried-forever

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

Failure-Class: FC-permanent-write-rejection-retried-forever

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T05:12:56.280528Z e0a0eb8 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b6def3c478

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +659 to +661
import base64
import random
import zlib

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Move the new test imports to module scope

These function-local imports violate the explicit backend import convention: all imports must be at module top level, with no exception stated for tests. Move these imports and the corresponding local imports in test_reconcile_retries_oversize_transcript_as_continuations to their respective module headers.

AGENTS.md reference: backend/AGENTS.md:L168-L168

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9ce0cee: the new test imports are at module scope in both test files. 146 tests pass in engine, live passes and claim growth.

Git-on-my-level and others added 3 commits November 25, 2026 23:36
Backend import convention (backend/AGENTS.md): imports live at module top
level. Addresses the Codex review on #26372.

Failure-Class: FC-permanent-write-rejection-retried-forever

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Firestore rejects one oversize field as 'The value of property "X" is
longer than 1048487 bytes', which size_error did not recognize, so a
residual oversize row (for example a locked row grown by late speech)
still raised and Cloud Tasks retried it forever. Classify it as
document_too_large so the owner parks with backoff and recovers on a
later pass. Log the split event when the size budget blocks a resumed
merge, and document the switch in the v3 runbook (omi-panel F1, F3, F5, F6).

Failure-Class: FC-permanent-write-rejection-retried-forever

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	backend/tests/unit/test_conversations_v3_live_passes.py
@Git-on-my-level
Git-on-my-level merged commit 30322be into main Nov 26, 2026
67 of 68 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/v3-window-size-cap branch November 26, 2026 06:17
kodjima33 added a commit that referenced this pull request Nov 30, 2026
…eech splits) (#26705)

## 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](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