Skip to content

fix(conversations-v3): compare large stored transcripts in write equality as bounded streams - #26787

Merged
kodjima33 merged 3 commits into
mainfrom
fix/v3-large-card-bounded-reads
Nov 30, 2026
Merged

kodjima33 merged 3 commits into
mainfrom
fix/v3-large-card-bounded-reads

Conversation

@kodjima33

@kodjima33 kodjima33 commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

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

…hat the writer stores

#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
kodjima33 added a commit that referenced this pull request Nov 30, 2026
…readable

The review's round-3 late-growth case, now readable through #26787's writer-sized readers:
the 680-line card resolves in shared chat, compares equal to itself, and unchanged re-arms
write nothing.
…reams; leave shared chat on main's reader

Write equality now keeps main's comparison and, when main's bounded decode refuses a
transcript, compares the two stored transcripts as 64 KiB decompressed-byte streams: each
field must pass the writer's own field check (estimate_firestore_value_bytes against
HARD_FIELD_LIMIT) before decryption, decoding stops at 32 MiB, and a grouping sidecar
falls back to a write as before. Peak memory on a 62,000-segment, 16 MB card is 1.95 MiB.
Shared chat is reverted to main's bounded reader.

Failure-Class: new
@kodjima33 kodjima33 changed the title fix(conversations-v3): size shared chat and write equality reads to what the writer stores fix(conversations-v3): compare large stored transcripts in write equality as bounded streams Nov 30, 2026
kodjima33 added a commit that referenced this pull request Nov 30, 2026
…readable

The review's round-3 late-growth case, now readable through #26787's writer-sized readers:
the 680-line card resolves in shared chat, compares equal to itself, and unchanged re-arms
write nothing.
…or their size

A transcript main's inline decode refuses for its shape (an over-long anchor) keeps main's
write; only a refusal for size (stored past 256 KiB or decoded past 512 KiB) takes the
bounded streamed comparison. Fixes the emulator proof
test_projection_writes_when_inline_anchor_is_rejected.

Failure-Class: new
kodjima33 added a commit that referenced this pull request Nov 30, 2026
…readable

The review's round-3 late-growth case, now readable through #26787's writer-sized readers:
the 680-line card resolves in shared chat, compares equal to itself, and unchanged re-arms
write nothing.
@kodjima33
kodjima33 marked this pull request as ready for review November 30, 2026 16:47
@kodjima33
kodjima33 merged commit 4bf6559 into main Nov 30, 2026
75 checks passed
@kodjima33
kodjima33 deleted the fix/v3-large-card-bounded-reads branch November 30, 2026 16:47
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