Skip to content

fix(conversations-v3): show a pendant safety copy's repeat of live speech once - #26699

Merged
Git-on-my-level merged 16 commits into
mainfrom
lane/transcript-dedupe
Nov 30, 2026
Merged

Git-on-my-level merged 16 commits into
mainfrom
lane/transcript-dedupe

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Problem

When a live session drops mid-conversation, the pendant's safety copy of the same audio syncs in later and is transcribed again with different line breaks. The v3 conversation then shows the live lines and the reworded copy lines interleaved: the same speech twice.

Intake keeps nearly all of the copy for owners outside the sync lineage allowlist:

  • whole-batch targeting binds the copy to the live row, or not;
  • the energy trim cuts only on strong proof, with a 1 s margin;
  • merge text dedupe needs an identical tokenisation of eight or more tokens;
  • lineage dedupe needs capture proof.

The projection's own rule in outline.stretches drops another recording's line only when it is 0.92 similar as a whole, and never a line of the same recording. A copy bound into the live row therefore always showed. Widening the lineage cohort is not the fix: its doubled-speech gate has failed since October, and with perfect capture proof it still kept 3 of the incident's 4 duplicate lines (test_capture_proof_removes_only_a_cleanly_contained_repeat).

Fix

backend/utils/conversations/v3/sync_repeats.py, called from outline.stretches. It runs on every v3 builder, backfill and re-derive pass. For each sync:-scoped line:

  • Its three-word phrases are matched against other lines' phrases at most 10 s away in recorded time. Other sync copies and legacy-conversation: lines never cover. A contraction counts as one word.
  • A repeat is a run of 6+ words that continues word by word through the live lines, possibly running from the end of one line into the start of the next. Phrases from two unrelated sentences never join into one.
  • Consecutive lines of one sync recording (pauses of at most 3 s) are read as one stream, even with another recording's lines in between, so a copy that splits a sentence into short lines still repeats it.
  • New words are kept when they make a run of 3+ words in that stream, across line breaks too. A cut-off word or two goes with the repeat.
  • Each phrase lookup reads only its own 10 s, from an index by phrase and instant. A two-hour copy beside two hours of live takes 0.03 s CPU in hide.
  • Each phrase occurrence of a covering line hides one repeat only, nearest first, in time order. Sync lines the projection already hides (exact duplicate, deleted span) spend every phrase they match, however short. So a sentence said again after the live stream dropped stays.
  • A live line that the existing rule dropped as the copy's own duplicate never covers it, so speech is never hidden twice.

Only what the conversation shows changes. A hidden line stays in the projection, marked sync_repeats.HIDDEN. A trimmed line keeps its segment id and recorded span, with shorter text. So the following see exactly the lines they saw before:

  • grouping;
  • ownership (Ownership, preserve_finished_windows);
  • audio claims, playback pieces and v3_recording_ids.

A conversation whose only stored audio is the pendant copy (cloud audio off) keeps its playback. Hiding lines outside those structures:

  • planner.build leaves hidden lines out of the transcript; a new window made only of hidden lines keeps them;
  • planner.word_count does not count them;
  • refinement compares only shown lines.

A finished conversation only gains lines. For a sync: id it already holds, planner.build keeps the stored variant, whole or trimmed. Stored recording segments are never changed.

On the 2026-11-28 local capture that prompted this, three copy lines drop. The fourth trims to "On the shores of the Bari Ganga", the words live never heard. This holds both bound into the live row and as its own sync row. That data was checked only in a scratch script; the committed tests use synthetic text with the same line breaks.

Kill switch

CONVERSATIONS_V3_SYNC_REPEAT_DEDUPE: ops_kill, default on, fail: open, registered in config/feature-flags.yaml.

  • off / false / 0 shows every hidden line again on the next projection of a stretch, in the same conversation, because the lines are still inside its claims.
  • A finished conversation keeps whichever variant of a sync line it stored. Flipping the switch never doubles a line and never opens a second card. This is tested both ways through preserve_finished_windows.

Reproduction (pipeline lab)

New scenario sync_safety_copy_repeats_live:

  • cloud audio off, so recording A is the live lane;
  • a minute of talk, then three live lines over 60-90 s, then the stream ends;
  • sync fragment F is the copy of 60-93.5 s with the incident's line breaks.

The lab now stamps sync fragment lines with the production sync: scope, and conversation_of rows take lines / max_words.

scenario compare over four arms, judged by this branch's harness:

arm result lines words
origin/main fails safety_copy_not_repeated 21 258
repro commit (first commit; expected_failure there, so xfail) fails 21 258
this PR passes 18 202
this PR, kill switch off fails 21 258

All 17 committed scenarios pass on this branch. scenario/reach.json is re-measured (--trace-calls).

Lab limit: the lab's sync stand-in always writes the fragment as its own recording, which is the unbound shape. The bound shape, where the safety WAL is appended into the live row, is covered by tests/unit/test_sync_live_repeat_lines.py through the real assign_in_transaction, which then runs stretches.

Tests

  • tests/unit/test_sync_live_repeat_lines.py: the research characterization, rewritten with synthetic text. In the first commit it records today's doubling (stored and projected); in the second its cases flip to fixed. Intake behaviour is unchanged: the stored transcript still holds both copies.
  • tests/unit/test_conversations_v3_sync_repeats.py (35 tests), covering:
    • full, partial and no cover; new words between two repeats; the cut-off-fragment rule;
    • genuine repeats: after the stream dropped, inside one copy line, two people starting with the same words, and phrases from unrelated sentences;
    • a repeat running on from one live line into the next; short copies hidden as duplicates still spending their words; a copy split into short lines repeating the whole sentence; new words across a sync line break kept; a two-hour stream bounded in time;
    • a fully hidden copy keeping its recording and audio claim in the conversation;
    • an exact copy hidden by the old rule still spending its phrases, and a live line dropped as the copy's twin never covering it;
    • the window boundary (9.8 s hidden, 10.2 s kept, both directions);
    • kill switch values; the bound copy; scopes that never cover; a deleted live line keeping its copy hidden; stored segments untouched;
    • a finished conversation routed through preserve_finished_windows and rebuilt across a kill-switch flip;
    • the pinned known limit.

Risk

  • Hidden genuine speech. A repeat said within 10 s while only the copy heard it can lose the 6+ words live already holds, if the copy did not also hold the original (it started mid-sentence). Another person repeating a 6-word run in those seconds is the same case; live and sync are diarized separately, so speaker labels cannot separate them. This is pinned by test_known_limit_a_repeat_inside_the_window_loses_the_words_the_copy_missed. When the copy holds both utterances, each live phrase hides only one.
  • Clock offset. More than about 10 s between the two captures leaves the copy shown, as today.
  • Unspaced scripts (Chinese, Japanese, Thai): no word breaks, so nothing matches and nothing is hidden.
  • Existing conversations. Finished conversations that already show a copy keep it. Open ones change on their next pass.
  • Refinement. It compares only shown lines. A window whose published rows predate this change (they still show the copy) no longer matches exactly, so refinement skips it. This is the guard's documented fallback to ordinary projection.

Review

One round, two independent reviewers on the same brief:

  • Luna (codex, gpt-6-luna): no blocking findings. One non-blocking point: two people saying the same phrase can hide sync speech. Documented as the known limit. I raised the run to 6 words and made contractions one token, so "I don't know what" no longer counts as 5 words; there is a test for it.

  • DeepSeek (opencode, morph/morph-dsv41flash-1017): 4 blocking findings, all verified and fixed.

    1. A finished conversation appended the trimmed copy beside its stored variant, and turning the kill switch off did the same in reverse. Fixed in planner.build, with a test that fails without the fix.
    2. The scenario text was not the lab's placeholder vocabulary; rewritten.
    3. reach.json lacked the new scenario; re-measured.
    4. The flag scanner could not see the read; the constant is now SYNC_REPEAT_DEDUPE_ENV.

    Non-blocking findings:

    • the 5-word false positive: threshold raised, as above;
    • refinement skip: it now compares only shown lines; rows published before this change fall back as documented;
    • window test row 0.0 passed through the old rule: test fixed;
    • Cover built while the switch is off: now skipped;
    • CJK inert: documented.
  • Codex bot (requested with @codex review; it did not start on its own), three P2 findings, all fixed:

    1. A trimmed line restored by turning the switch off fell outside the finished conversation's claim, so it went to a fresh card. The fix went further. Shrinking or dropping copy lines had also been shrinking the conversation's audio claims and playback pieces. The redesign above keeps hidden lines in the projection and keeps each trimmed line's span. Tested through preserve_finished_windows, and with a fully hidden copy keeping its claim.
    2. Two unrelated phrases could add up to a 6-word "repeat". A repeat must now continue word by word through the live lines.
    3. Short copy lines hidden as exact duplicates didn't spend their phrases. They now spend every phrase they match.
  • Codex bot, second pass (on 184c3b1c9c), one P2 finding, fixed: a copy that splits a live sentence into lines shorter than 6 words left them visible and spent nothing, so a later sync-only repeat could be hidden. Consecutive lines of one sync recording are now matched as one stream.

  • Codex bot, third pass (on a7ce707f40), two findings, both fixed:

    • P1: with streams, one long sync recording made every phrase scan the stream's whole neighbourhood; Codex measured about 7.5 s for two hours, run inline. Lookups now go through a time-sorted index per phrase and read only their own window: 0.03 s CPU on that shape, with a test. outline.stretches already ran inline in service.reconcile before this PR, with its existing whole-line duplicate rule; moving it off the event loop is a separate change.
    • P2: the 3-word keep rule was applied per line, so a new phrase split across two copy lines was lost. Kept runs are now decided over the stream.
  • Codex bot, fourth pass (on eeceb01e32), one P2, fixed: another recording's line between two lines of a copy broke the copy's stream. Streams now group per recording.

Verification

Worktree lane/transcript-dedupe; all commands run from backend/:

  • bash test.sh (CI's changed-file selection);
  • make preflight;
  • the scenario commands above.

Failure-Class: FC-same-speech-captured-twice-surfaces-twice

🤖 Generated with Claude Code

Git-on-my-level and others added 4 commits November 29, 2026 00:54
…ive lines

Scenario sync_safety_copy_repeats_live: a live-lane recording whose stream
ends at 90 s, and a device-sync fragment of the same 60-93.5 s transcribed
with different line breaks (the shape of a 2026-11-28 local capture, in the
lab's placeholder words). On today's v3 projection all four copy lines show
beside the live lines (21 lines, 258 words); the scenario expects 18 lines
and 202 words and is marked expected_failure.

Lab: sync fragment lines carry the sync: speaker scope the sync pipeline
stamps, and conversation_of rows take lines and max_words.

tests/unit/test_sync_live_repeat_lines.py (from the dupe-research lane,
synthetic text): the safety WAL bound into the live row by
assign_in_transaction, and the unbound copy row, both stored and projected
twice.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eech once

outline.stretches now hides, in each sync:-scoped line, the runs of six or
more words that another capture's line already holds within 10 s of
recorded time (three-word phrases, a contraction counted as one word, each
live phrase matched once, nearest first). What the copy alone heard is kept
when it is three or more words; a cut-off word or two at a line break goes
with the repeat. Sync lines the projection already hides spend their
phrases too, and a live line dropped as the copy's own duplicate never
covers it, so speech is never hidden twice and a sentence said again after
the stream dropped stays.

A finished conversation only gains lines; planner.build now keeps the
variant of a sync line it already stored (whole or trimmed), so neither
this change nor a kill-switch flip shows the line twice.

Stored recording segments are untouched. CONVERSATIONS_V3_SYNC_REPEAT_DEDUPE
(ops kill switch, default on) off shows every hidden line on the next
projection.

sync_safety_copy_repeats_live now passes (18 lines, 202 words; origin/main
21 lines, 258 words), and scenario/reach.json is re-measured. On the
2026-11-28 local capture, three copy lines drop and the fourth trims to
the words live never heard.

Failure-Class: FC-same-speech-captured-twice-surfaces-twice

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Failure-Class: FC-same-speech-captured-twice-surfaces-twice

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 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-30T18:53:29.327163Z e375c19 Manual request
ℹ️ 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: 937d3486ad

ℹ️ 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".

Git-on-my-level and others added 2 commits November 29, 2026 02:42
…n repeated words

Codex review of #26699. Hidden sync lines now stay in the projection,
marked sync_repeats.HIDDEN, and a trimmed line keeps its segment id and
recorded span. Grouping, ownership, audio claims, playback pieces and
v3_recording_ids see the same lines as before: a conversation whose only
audio is the pendant copy keeps its playback, and a kill-switch flip
leaves every line with the finished conversation that owns it.
planner.build leaves hidden lines out of the transcript, word_count skips
them and refinement compares shown lines only.

A repeat must continue word by word through the covering lines (also from
one line into the next), so phrases of unrelated sentences never join, and
sync lines already hidden as duplicates spend every phrase they match.

Failure-Class: FC-same-speech-captured-twice-surfaces-twice

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

@codex review

@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: 184c3b1c9c

ℹ️ 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".

Git-on-my-level and others added 2 commits November 29, 2026 02:59
Codex review of #26699: a copy that splits a live sentence into lines
shorter than six words left them visible and spending nothing, so a later
sync-only repeat of the sentence could be hidden. Lines of one sync
recording at most 3 s apart are now matched as one stream, then mapped
back to their lines.

Failure-Class: FC-same-speech-captured-twice-surfaces-twice

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

@codex review

@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: a7ce707f40

ℹ️ 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".

… words across line breaks

Codex review of #26699. Each phrase lookup now reads only its own 10 s
through a per-phrase index sorted by instant, instead of every covering line
near the stream (a two-hour copy beside two hours of live: 7.5 s -> 0.03 s
CPU). New words are kept when they make a run of three in the sync stream,
so a new phrase split over two copy lines is no longer lost.

Failure-Class: FC-same-speech-captured-twice-surfaces-twice

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

@codex review

@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: eeceb01e32

ℹ️ 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".

…ing's lines

Codex review of #26699: a line of an overlapping sync recording broke the
first recording's stream, so its short copy lines no longer spent the
sentence they repeat. Streams now group per recording regardless of lines
in between, still processed in the order they start.

Failure-Class: FC-same-speech-captured-twice-surfaces-twice

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Git-on-my-level and others added 3 commits November 29, 2026 03:42
# Conflicts:
#	backend/testing/pipeline_lab/scenario/reach.json
Resolve planner.py: main extracted the retained-row append dedupe into
present_in (shared with locked_append); the stored-sync-id check now lives
there. Regenerate scenario/reach.json with --trace-calls on the merged tree.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	backend/testing/pipeline_lab/scenario/reach.json
#	backend/utils/conversations/v3/outline.py
@Git-on-my-level

Copy link
Copy Markdown
Member Author

@codex review

@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: 697e501653

ℹ️ 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".

Failure-Class: FC-same-speech-captured-twice-surfaces-twice
@Git-on-my-level

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: e375c19882

ℹ️ 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".

Failure-Class: FC-same-speech-captured-twice-surfaces-twice
@Git-on-my-level
Git-on-my-level merged commit e079c10 into main Nov 30, 2026
70 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/transcript-dedupe branch November 30, 2026 19:53
kodjima33 added a commit that referenced this pull request Dec 1, 2026
…s on landing too (#26771)

## What changed and why

Device sync uploads an older talk file by file, often after newer speech
has landed. Only the newest stretch may stay
open, so `outline.stretches` finished every older stretch at once,
however recently its speech landed. The first
file's card was published on arrival. The next file of the same talk,
landing a minute later, could not move that
published boundary (`planner.preserve_finished_windows`), so it became a
second card. Settling on landing exists so
that "an offline batch whose speech is already old must not lock the
moment it arrives", but it protected only the
newest stretch.

Production audit, metadata only, 24 h to 2026-11-30 04:22 UTC: 110
adjacent v3 card pairs with no gap, disjoint
recordings, no manual cut and 50+ words each side. 53 of them involve a
recording that arrived through device sync.
In 21 of those, the first card was built already finished while newer
speech from the same device existed, and its
neighbour landed within 5 minutes; 19 of the 21 had no recording placed
before. That is the case this PR fixes. The
other pairs are batch-lane reconnects (#26749), concurrent double
captures, or uploads more than 5 minutes apart (see
"Not changed here").

**Containment: dark by default.** Everything this PR adds runs only for
owners listed in
`CONVERSATIONS_V3_SETTLE_OLDER_OWNERS` (owner tags `sha256(uid)[:12]`,
or `*`; read per pass), and only with
`CONVERSATIONS_V3_SETTLE_ON_LANDING` on. The default is empty, and then
every pass is main's: no hold, no off-page
sibling lookup, no settlement wake, and `has_pending` and the projection
commit run main's code (the commit's
past-deadline rotation now also applies only to sources the outline held
for settlement). The existing
`CONVERSATIONS_V3_SETTLE_ON_LANDING` stays as it is: it defaults on and
gates main's own landing settlement of the
newest stretch, so turning it off would change main. The new flag is
registered as a rollout
(`config/feature-flags.yaml`): merge dark, then a test allowlist,
internal owners, and `*`. Proof: `scenario compare`
with the allowlist emptied on both arms shows every committed scenario
identical to main (below), and unit tests
pin the flag-off loader, `has_pending`, commit and plan to main's.

**The mechanism.** Live builder passes (`service.reconcile`, never
derive or on-open) pass `settle_older` to
`outline.stretches`. Under `CONVERSATIONS_V3_SETTLE_ON_LANDING` (default
on), `_settle_older` leaves out an older
stretch when all of these hold:

- every recording in it is a device-sync landing
(`outline.device_sync_landing`: sync intake stamped its
`sync_content_revision`, a positive integer; no other sync stamp, such
as `sync_recorded_end_at`, counts; and it is
not a live capture that sync extended, `sync_live_target`), all from one
known `client_device_id`;
- a newer stretch holds speech from that same device, or the stretch
already stores a deadline;
- its speech is older than the lock delay, but it landed less than the
lock delay ago;
- no transcribed audio covers the silence gap after its last line
(`_audio_covers`: completed and transcribed
recordings only, on capture-time ends, never an arrival-stamped
`finished_at`);
- no conversation has placed any of its recordings (no claims), and none
of them has lines in another stretch;
- it is not bounded by a manual end or the window cap.

Its recordings stay pending until the lock delay after the stretch's
last landing (`outline.SETTLE_UNTIL`, kept
pending by `preview_wakes`). A file that lands in that window joins the
stretch. Once the wait ends, the stretch is
planned as one finished card. No second open card is ever committed.
Every other capture keeps main's publication
schedule: live, batch and rotation captures whose transcript lands late,
separate-origin Finish predecessors, and
synced speech behind only another device's speech.

**The stored deadline.** The projection commit writes the deadline to
each held recording as `v3_settle_until` and
clears it once the stretch is planned. Without it, the wait would end as
soon as the newer conversation locks and
leaves the loaded page. The older stretch would then be published as an
open card, finished by the next newer
speech, and the next file would split again.
`sync_files_after_newer_speech` covers that sequence.

**The new wake.** `_after_projection` enqueues a Cloud Task at every
distinct deadline it holds
(`triggers.enqueue(settlement=True)`) with payload `trigger:
"settlement_deadline"` and its own per-second task name,
so a same-minute arrival wake cannot swallow it, and each held row keeps
its wake whichever page later loads it.
`routers/conversations_v3_tasks.py` answers 503 for this trigger while
the builder lease is busy, so the
queue retries it; untriggered and `native_manual_ready` requests behave
as on main. A deadline already past (a sibling
still missing) re-checks once a minute through the same settlement task,
never an ordinary minute wake. Each wake is
retried briefly (three attempts); one that still cannot be created makes
the pass report more work.

**The pass chain.** `service.has_pending` keeps main's read first. Only
when every other pending source it finds is
held until a future settlement deadline does it read in
`v3_pending_since` order for owed work ahead of them. Held
sources on other pages therefore no longer keep the chain reconciling
and waking the owner every minute; their
settlement task plans them. When it finds only such holds, it also
re-creates the settlement task of the earliest one
off the page (idempotent by name) and reports more work until that
succeeds, so a hold whose wake failed after the
commit is recovered from its stored deadline even if its source never
returns to a page: no hold ends up with
neither a wake nor a continuation.

**The new query.** The pending page is ordered by `v3_pending_since`,
not capture time. When it is full, a held
file's sibling can sit off the page, and the stretch would settle
without it. Then, and only with settling on landing
on (the same switch the builder reads), `load()` looks for the off-page
pending siblings of held device-sync files
(`_hold_for_pending_siblings`, on the existing
`conversations_v3_pending_capture_continuation` index):

- seeds are unplaced device-sync files with a known device whose old
speech landed within the lock delay, or that
  store a deadline; ordinary recordings never qualify;
- both sides use capture time (`capture_span_without_transcript`, never
an arrival-stamped `finished_at`): it reads
captures that start within 20 minutes of a seed cluster's capture span.
A sibling is evidence only with the same
known, non-empty device and a gap strictly below the silence gap, as
grouping joins speech;
- it reads capture metadata only. It never decodes a sibling or adds it
to the pass, so an optional sibling can
trigger no transcript (lake) read and no neighbour reads. Only one of
the device's captures found within the
silence gap of the cluster's span marks the stretch, which waits until
both share a page, up to
  `policy.TRANSCRIPT_WAIT` (15 min) past its deadline;
- one pass reads at most 32 documents and spends at most 10 s
(`SIBLING_SECONDS`, far inside the 240 s builder lease)
for every held cluster across all its load attempts (`SiblingReads`,
created per reconcile pass beside
`UnlockedPage` and shared by the bounded-load ladder and its batch-cap
retry), 16 documents at a time, each query
within 3 s. Each RunQuery's whole limit is taken from the allowance
before it is sent, and it is never resumed
(`FIRESTORE_NO_RETRY`: the SDK's resume after a mid-stream error asks
for the same limit again), so no call can
return more than was charged; a finished call gives back what it did not
return;
- a lookup that cannot finish (the allowance is spent) or fails marks
nothing: the stretch keeps main's plan. A
failure (a read, or a capture field it cannot parse) ends the lookup for
the rest of the pass, every later load
attempt included (`SiblingReads.failed`), is logged and counted as a
degraded fallback, and the pass goes on. Main's
  load path is unchanged with the switch off.

**Stored data and clock arithmetic are best effort.** Every stored field
this path reads goes through
`outline.instant`, a guarded capture clock and bounded audio durations:
a value that is not a valid instant in
2000–2100 or a valid duration counts as absent. Every clock sum on the
path (skew, lock delay, transcript wait,
deadlines, coverage, lookup windows) goes through one helper,
`outline.shifted`, which gives no result when the sum
overflows or leaves that range; the caller then keeps main's plan. Only
an eligible stretch's clocks are read.
`_audio_covers` skips a row it cannot read (no coverage), an unreadable
stored deadline is no hold, capture spans
treat an unreadable field as absent, and in `has_pending` an unreadable
stamp is owed work, as on main. A failed
pending-order read in `has_pending` (3 s timeout, never resumed) keeps
main's answer, and `has_pending` answers owed
work the moment it reads it, so a later failure of the same read cannot
lose it. None of them fails the pass.

The queries are registered with the Firestore query-shape drivers.

**Observability.** `omi_conversations_v3_settle_older_total` counts
passes that hold an older stretch, and
`backend-sync`'s managed Prometheus keep-list scrapes it
(`deploy/cloud_run_gmp_sync.yaml`).

**Relation to #26769.** Late-speech absorption joins an earlier file
into a later published card, backward only, and
costs a notes rewrite. It cannot join the upload order, which is the
shape reproduced on production below. This PR
joins both orders without publishing the partial card first. Absorption
still applies wherever this PR keeps main's
plan.

## Not changed here (follow-ups)

Review rounds had added the changes below on shared paths. None is
needed to keep the older talk on one card, so this
branch restores main's code for each (`f4d380410d`). Main already lives
with future `v3_pending_since` stamps from
held Finishes and previews: such a recording stays pending and is
planned by the deadline wake or any pass that loads
it. Each item is a separate follow-up:

1. **Pull a future `v3_pending_since` back to now when speech lands or a
recording is re-armed.** This covers the live
transcript writer (`database/conversations.py`
`update_conversation_segments`), `mark_pending` and
`promote_manual_end`. It would make a held recording with fresh speech
head the pending page on its first pass,
   instead of at its deadline.
2. **Clamp a future `v3_pending_since` on Finish and native re-arm**
(`_window_tail_plan`, `_finish_capture`,
`permits_native_source`). A deferred older stretch is never the newest
capture a Finish targets.
3. **Split unreadable recordings into terminal and retryable failures.**
Terminal ones would be a missing blob, a
shredded key, a missing file or corrupt segments; retryable ones decode,
type or fetch errors. Retryable ones would
stay pending on a rotating retry, and an older stretch would wait while
a sibling is temporarily unreadable. Main
already treats corrupt segments as unreadable
(`TranscriptSegmentsDecodeError` is a `ValueError`).
4. **Treat a lake-fetch outage (`TranscriptPointerFetchError`) as a
retryable race (`recording_decode_retryable`)**
instead of failing the pass, on the main load path. (The new sibling
read already isolates its own failures.)
5. **Keep a transient lake fetch on an unlocked preview's source out of
the owner's deterministic backoff.**
6. **Count only due pending work in the pass chain for every kind of
hold.** `has_pending` now skips settlement holds
only (see "The pass chain"); main's other future holds keep their
behaviour.

Also not changed: device-sync uploads that land more than 5 minutes
apart (28 pairs; the builder has no sign that
more audio is coming, so this needs a client signal such as the phone's
pending WAL count), and concurrent double
captures (29 pairs, a duplicate-capture problem, not a reconnect).

## Expected latency cost

- **A device's synced old speech landing behind that device's newer
speech, with no transcribed audio after it:** its
card appears up to the lock delay (5 min) after its last file lands,
instead of at once. That is the wait the
newest stretch already has. Production, same 24 h, metadata only: 25,408
of about 116,000 completed v3 cards were
built from speech over 5 minutes old and finished within 4 minutes. In a
random 1,500-card sample, 442 had no
transcribed audio covering the next 5 minutes (the `_audio_covers`
rule); 213 of those were device-sync files from
one device, and 186 had newer speech from that device before the card
was built. So about 3,150 cards a day
(about 2.7%, two thirds of them hidden from Home) wait up to 5 more
minutes. Before this round the gate let up to
  about 7,500 a day wait.
- **A pending sibling off the page:** only on a full pending page; that
stretch waits until both share a page, up to
  15 minutes past its deadline, re-checked once a minute.
- **Everything else is unchanged:** live, batch and rotation captures,
synced speech behind only another device's
speech, the newest stretch, older stretches followed by transcribed
audio, placed stretches, backfill, re-derive
  and on-open.
- **Reads and writes:** the sibling lookup runs only on a full pending
page with the switch on, for held device-sync
files: at most 32 metadata documents per pass, and no transcript read.
`has_pending` reads a second page only when every other pending source
it
found is held until a future deadline. A held stretch writes its
deadline once (again when a new landing moves it)
  and gets no outline call until it is planned. Lab, all 27
scenarios against main (flag on): 33 fewer reads, 21 fewer writes, 7
fewer LLM calls and 3 more no-op writes, all in the new
  scenario; flag off, none.
- **Default:** none of the above. With
`CONVERSATIONS_V3_SETTLE_OLDER_OWNERS` empty (the default) nothing
changes;
the numbers above are for `*`, and a test allowlist costs only its
owners' share.
- **Rollback:** empty `CONVERSATIONS_V3_SETTLE_OLDER_OWNERS`, or
`CONVERSATIONS_V3_SETTLE_ON_LANDING=off` on the
  builder runners. That also turns off landing settlement
for the newest stretch: at the default timing every stretch then counts
from its last speech, and the sibling read
  does not run.

## Product invariants affected

none

## How it was verified

- **Review round 1 replays.** The reviewer's replays are tests now
(synthetic rows). On `f3c75432bb` 18 cases fail,
  each one below; here they pass:
- **Ordinary captures:** a live batch capture landing late behind
another device's speech, with and without a
rotation stamp, gets its card on the first pass and stores no deadline
(it was held 280 s). Main's separate-origin
Finish test (`test_conversations_v3_finish_late_predecessor.py`) is
restored unchanged and passes. Live captures,
sync-extended live captures, another device's newer speech and an
unknown device each keep main's plan.
- **Read cost:** with the switch off, a full page of 32 seeds, each with
65 pending captures behind it, reads one
capture-order document, as main does (it read 2,081). Ordinary
recordings never seed the read with the switch
on. 32 held sync clusters share one budget of at most 32 documents and
wait (bounded) for what it did not finish.
- **Capture time and isolation:** an arrival-stamped `finished_at` no
longer stretches a seed onto another device's
recording an hour later. Another device's adjacent capture, or one of
its own device's an hour away, does not
hold a sync file; its own device's off-page sibling does, without being
read, and a lake fault on that sibling
    cannot fail the pass.
- **Continuation:** two held rows across a one-source page no longer
keep the pass chain going, owed work still
does, and an overdue settlement wake keeps its own task name next to an
ordinary wake of the same minute.
- **Review round 2 replays.** On `776621f5eb` 9 cases fail; here they
pass:
- **Budget:** sibling streams that fail after 15 documents read at most
32 in all (they read 480), and the
bounded-load ladder's 32-, 8- and 1-seed attempts share one 32-read
budget (they read 96).
- **Best effort:** an off-page sibling next to another device's
historical card, whose lake read fails, neither
fails the load nor blocks an ordinary card in the same reconcile (both
aborted). The lookup never decodes a
sibling; a held file waits for its device's off-page sibling without
reading it, and the two form one stretch
    once they share a page.
- **Wakes:** two holds with distinct deadlines each get a settlement
task, so the second keeps its wake after the
    first deadline's one-source pass loads only the first.
- **Review round 3 replays.** On `8d3432b10e` 7 cases fail; here they
pass:
- **Budget:** the installed SDK's RunQuery stream on a fake transport
that breaks every 15 results makes one RPC
and stops (it resumed with the original limit and read 51 documents
against 32).
- **Best effort:** a seed whose stored audio duration overflows a
timedelta neither fails the load nor blocks an
    ordinary card in the same reconcile (both aborted).
- **Wakes:** one transient failure creating the later deadline's task is
retried and the pass commits (it raised,
and the later hold had neither a task nor a continuation); a settlement
wake that cannot be created is reported
as more work; and an off-page hold whose wake cannot be created keeps
the chain going until a pass creates it.
- **Review round 5 replays (the allowlist on).** On `8c48da5abd` 22
cases fail; here they pass:
- **Time:** a year-9999 landing on an ordinary older card, a year-9999
stored deadline, and a year-9999 coverage end
no longer overflow before the commit; the ordinary Home card is
published, as on main. Clock sums that leave
    2000–2100 give no result.
- **Optional I/O:** a stalled optional query takes its 3 s timeout, not
RunQuery's 300 s past the 240 s lease: the
    pass commits and publishes (it returned `raced` with no Home card).
- **Evidence:** a candidate with no device ID, or exactly a silence gap
away, no longer holds the seed across three
    passes; it is published on the first, as on main.
- **Provenance:** a malformed `sync_recorded_end_at` is no provenance (a
normal recording behind newer same-device
speech was withheld); only a positive integer `sync_content_revision`
counts.
- **`has_pending`:** an owed row read before the stream fails is kept:
true, as main answers.
- **Containment:** with the owner off the allowlist, two synced files
are planned on arrival as on main (two cards,
no stored deadline), the loader runs no sibling query, `has_pending` is
main's ids-only read, and the commit
    writes no settlement field.
- **Review round 4 replays, and the audit of the new path.** On
`46c4b82471` 19 cases fail; here they pass:
- **Parsing:** a legacy row whose optional `recorded_start` is not an
instant no longer aborts the reconcile, and
its ordinary card is published, as on main. Unreadable coverage fields
count as absent (the next readable field
still proves coverage), an unreadable stored deadline is no hold,
capture spans read unreadable stamps, absurd
audio durations and odd types as absent, and `has_pending` counts
unreadable stamps as owed work.
- **Lookup results:** one interrupted sibling query and a real claim
closure that overflows the 32- and 8-seed
loads: the failure is carried through the ladder, the one-seed pass
makes no further sibling read, and the card
is published at its deadline, as on main (it was held 60 s past it). An
allowance spent before a cluster is
reached, or a lookup that cannot finish, keeps main's plan; a failed
pending-order read keeps main's answer.
- **Pipeline lab on the merged tree (`7d57d903e0`, main `e26598ae7f`
merged in), against main at `197be6283a`, all 27
  committed scenarios.** The new scenario turns the allowlist
on in its own `env` (`CONVERSATIONS_V3_SETTLE_OLDER_OWNERS: "*"`); every
other scenario runs the default (off).
- **Flag off** (`scenario compare --arm main@origin/main --arm head`,
the allowlist emptied on both arms by arm
env): no difference. 27 of 27 scenarios are the same, and 0 of 376
metric keys (operations, outcomes, speakers,
stages, STT routing) differ from main. `sync_files_after_newer_speech`
fails identically on both arms there,
    since its expectations need the feature.
- **Flag on** (`scenario compare origin/main --worktree`): 26 are
identical on both arms (same outcomes,
conversations and operation counts), among them
`late_sync_joins_published_card` (#26769),
`sync_safety_copy_repeats_live` (#26699) and main's seven `stage_queues`
scenarios (#26824).
`sync_files_after_newer_speech` fails on main (the older talk as two
conversations, F1 and F2) and passes here
(one conversation, F1+F2, on Home with notes), with 33 fewer reads, 21
fewer writes, 7 fewer LLM calls and 3 more
no-op writes. Its 15 checks follow F1 through the newer conversation
(the same device's) locking and leaving the
page, an unrelated empty sync wake, another device's capture, and F2
moving the deadline. They check that no
partial card exists at any of those points and that the joined card
appears at the deadline.
- All 27 scenarios with `--jobs 4 --repeat 2 --stt replay` passed in
both repeats (summary below), and
    `scenario/reach.json` is re-measured on the merged tree.
- **Replay tests.** Multi-pass replays drive the real
`service.reconcile` and projection commit on the strict
Firestore fixture, with the older files as device-sync landings of the
owner's device:
- two files of one older talk landing a minute apart while the owner is
talking make one card, in upload order and
    in reverse order, with no partial card in between;
- a second file appended to the first file's recording joins its card.
That is the production shape below; main
    gives two cards;
  - the hold survives the newer card leaving the page;
- with settle-on-landing off, after a placed first file, and behind only
another device's speech, the plan is
    main's.

Loader tests cover the held-sibling lookup across a page boundary (the
held file waits, then joins its sibling once
both share a page), its metadata-only reads, and a lookup the budget
cannot finish (main's plan). Pure `stretches`
  cases cover every condition above.
- **Production repro of the bug, test account, current main.** A 90 s
socket capture landed first, and its card was
open. Then two abutting 120 s WAL files of a talk two hours older went
through `/v2/sync-local-files`, the second
after the first had a card. The first file's card was `processing` 32 s
after its file landed. Sync appended the
second file to the same recording, and it became a second card. Final
state: two cards from one recording, split
exactly at the file seam. Not deployed, so there is no production
after-run; the replay above is that shape.
- **Live-STT lane (not a bug).** On the test account with private cloud
sync off for the run, a 240 s + 460 s call
  with a 1.5 s reconnect gave one card holding both recordings.
- **Unit suites, after merging main.** All `test_conversations_v3*`
files and every file importing the
v3 modules, `transcript_multipart` or `sync_repeats` (78 files) in one
xdist session: 3,797 passed; the 13 failures
are all `test_conversation_events_bounds.py`, which passes alone (21
passed): cross-file `sys.modules`
contamination in a shared session, as `backend/AGENTS.md` warns. The
Firestore query-shape, contract and
index-oracle guards (the held-sibling lookup, its capture-window query
and both `has_pending` paths registered;
`commit_projection`'s digest re-pinned for its allowlist gate), the
pipeline lab tests, main's
`test_sync_live_repeat_lines.py`, `test_home_index_cutoff.py` and
`test_mcp_conversation_detail_paging.py`: 1,742
passed. The feature-flag registry renders and checks clean (its tests:
122 passed). `pipeline_lab affected` selects
every scenario. Pyright: 0 errors. The async-blocker scan finds nothing
in the changed ranges.
- **Preflight:** `scripts/pr-preflight --pr-body-file` with this body
passed every check, including the line-count
  exceptions, the failure class and the product invariants.

## Tests

`backend/tests/unit/test_conversations_v3_settle_older.py` (new, 107
cases; the allowlist is `*` there unless a case
clears it):

- **Pure `stretches`:**
  - the wait and its deadline, and a file landing in the wait moving it;
- main's plan for placed, shared, manually ended, settled,
live-younger-than-the-lock-delay,
followed-by-transcribed-audio, live-capture, sync-extended-live,
other-device and unknown-device stretches, and
    for manual-end and window-cap bounds;
  - the newest stretch is never left out;
- only resolved transcription proves recorded silence, and a skewed
`finished_at` cannot veto the wait.
- **Wake:** at the deadline, a one-minute settlement retry once past it,
and none on derive.
- **Stored deadline:**
  - cleared when a held source turns out unreadable;
  - an unreadable sibling does not block the readable one;
  - the hold survives the newer card leaving the page;
  - the metric is in the sync keep-list.
- **Replays:** the multi-pass shapes above.
- **Loader:** an off-page held sibling keeps the held file waiting until
both share a page, the lookup never decodes a
  sibling, and a lookup the budget cannot finish keeps main's plan.
- **Review rounds 1 to 5:** the replays and audit cases listed under
"How it was verified".
- **Containment:** the flag-off plan, loader, `has_pending` and commit
are main's.

`backend/tests/unit/test_conversations_v3_contract.py`: the
`settlement_deadline` wake answers 503 while the lease is
busy and runs once free. Its task name never collides with a same-minute
arrival wake.

`backend/tests/unit/test_conversations_v3_finish_late_predecessor.py`:
restored to main's version.

`backend/tests/unit/test_conversations_v3_review.py`:
`MemoryQuery.stream` accepts the SDK's retry and timeout options
(the sibling lookup streams with `retry=FIRESTORE_NO_RETRY`).

`backend/tests/support/firestore_conversations_v3_drivers.py`: the
held-sibling lookup (a held sync seed, and its
capture-window query) and both `has_pending` reads are registered query
shapes.

## Pipeline lab

**Pipeline lab scenarios: passed** (27 scenario(s) x2, jobs 4, stt
replay, 272.9 s, ref `7d57d903e090`)

| scenario | outcome | checks | seconds | transcripts | reads | writes |
no-op writes | stt | llm |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| audio_single_recording_finish | passed | 9/9 | 22.706 | synthetic |
186 | 52 | 5 | 2 | 6 |
| finish_after_long_reconnect_gap | passed | 8/8 | 19.743 | scripted |
236 | 64 | 7 | 1 | 6 |
| finish_after_reconnect_late_transcript | passed | 8/8 | 20.508 |
scripted | 267 | 74 | 8 | 1 | 7 |
| finish_after_second_close | passed | 10/10 | 26.509 | scripted | 296 |
74 | 12 | 1 | 6 |
| finish_cloud_audio_off | passed | 9/9 | 25.538 | scripted | 181 | 53 |
5 | 0 | 6 |
| finish_double_tap | passed | 11/11 | 24.488 | scripted | 195 | 55 | 5
| 1 | 7 |
| finish_next_opens_before_close | passed | 10/10 | 18.926 | scripted |
236 | 68 | 7 | 1 | 7 |
| finish_no_closed_recording | passed | 9/9 | 16.804 | scripted | 166 |
47 | 4 | 0 | 6 |
| finish_on_visible_conversation | passed | 10/10 | 16.254 | scripted |
170 | 47 | 4 | 0 | 6 |
| finish_privacy_refused_fast_finish | passed | 8/8 | 12.832 | scripted
| 37 | 8 | 1 | 0 | 0 |
| finish_single_recording_fast | passed | 9/9 | 15.157 | scripted | 198
| 55 | 5 | 1 | 7 |
| finish_transcript_never_lands | passed | 7/7 | 15.157 | scripted | 237
| 65 | 7 | 0 | 6 |
| home_paging_past_hidden_runs | passed | 8/8 | 19.793 | scripted | 1027
| 47 | 4 | 0 | 6 |
| late_sync_joins_published_card | passed | 9/9 | 17.909 | scripted |
308 | 78 | 7 | 0 | 10 |
| reconnect_successor_lands_late | passed | 9/9 | 17.895 | scripted |
367 | 85 | 18 | 0 | 7 |
| speaker_owner_absent | passed | 8/8 | 17.452 | local | 172 | 58 | 4 |
1 | 6 |
| speaker_owner_and_person_finish | passed | 8/8 | 12.886 | local | 171
| 58 | 4 | 1 | 6 |
| speaker_partial_final_pass_keeps_voices | passed | 8/8 | 12.46 | local
| 157 | 55 | 4 | 1 | 5 |
| stage_queues_automatic_end | passed | 11/11 | 11.036 | scripted | 175
| 52 | 4 | 0 | 7 |
| stage_queues_late_text_rewrite | passed | 14/14 | 18.625 | scripted |
307 | 79 | 7 | 0 | 9 |
| stage_queues_missing_queues | passed | 15/15 | 17.407 | scripted | 359
| 100 | 9 | 1 | 12 |
| stage_queues_model_failures | passed | 14/14 | 15.771 | scripted | 204
| 54 | 4 | 0 | 7 |
| stage_queues_switch_flipped_in_flight | passed | 19/19 | 19.905 |
scripted | 694 | 181 | 20 | 0 | 22 |
| stage_queues_user_end | passed | 12/12 | 20.043 | scripted | 207 | 59
| 5 | 1 | 7 |
| stage_queues_user_end_during_backlog | passed | 14/14 | 20.379 |
scripted | 337 | 94 | 7 | 1 | 12 |
| sync_files_after_newer_speech | passed | 15/15 | 23.598 | scripted |
672 | 152 | 21 | 0 | 18 |
| sync_safety_copy_repeats_live | passed | 3/3 | 20.525 | scripted | 225
| 59 | 8 | 0 | 6 |

Coverage: all 27 committed scenario(s) ran x2 and evaluated their
checks.

The run used `7d57d903e0`, the merge of main. `4835648f91` after it
commits only the re-measured `reach.json`,
so the code under test is the head's.

## UI evidence

UI-Evidence: none -- backend-only change

## Failure class (fixes)

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

Line-Count-Exception: backend/utils/conversations/v3/service.py | 2395
-> 2511 | the settlement wakes sit beside the held-Finish wake in
`_after_projection` with a bounded-retry helper whose failure keeps the
pass chain going, `has_pending` skips settlement holds with one more
read in pending order and re-creates an off-page hold's wake, the pass's
sibling-read allowance is threaded through the load ladder, plus the
`settle_older` argument at the live `stretches` call
Line-Count-Exception: backend/database/conversations_v3.py | 2832 ->
3052 | the held-sibling lookup (gated, metadata-only, one pass budget)
reads the same pending-page state `load()` already holds, and the
projection commit stores the settlement deadline in the recording update
it already writes

🤖 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