Repository navigation
fix(sync): dedupe batch transcripts and prevent misfiled uploads - #25463
Conversation
Handle long stored donors with bounded local lexical windows, apply the same rule to late sync appends, and preserve repeat-only redirect writes. Refuse non-contained input and donor absorption into pinned batch-live recordings. Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep stored transcripts and citation IDs intact while selecting placed, richer copies for normal and compact summary input. Preserve same-scope or later repetition, known distinct speakers, manual lines, translations and protected words. Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]>
Narrow numeric bounds explicitly for the enforced typecheck and preserve malformed clocks without using them as repeat evidence. Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8a7ae66049
ℹ️ 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".
| if not segments: | ||
| return conversation_transcript_for_llm(uid, conversation, people), {} | ||
|
|
||
| segments = canonical_prompt_segments(segments) |
There was a problem hiding this comment.
Preserve full speaker evidence when filtering compact prompts
When a removed duplicate carries the conflicting non-owner label for a cluster, filtering here removes that contradiction before either compact-renderer branch resolves speaker identities. A cluster containing one non-owner-labelled duplicate and one positively owner-labelled commitment is unknown under speaker_role_map on the full transcript, but becomes primary_user after the duplicate is removed, attributing the remaining commitment to the account owner without new identity evidence. Preserve the full transcript for speaker-role decisions and filter only rendered turns, as the normal renderer already does with evidence_segments=segments.
Useful? React with 👍 / 👎.
| kept = dedupe_donor(incoming, {}, {'started_at': _ORIGIN, 'transcript_segments': candidates}).kept | ||
| if not kept: | ||
| continue |
There was a problem hiding this comment.
Keep disjoint placed utterances across batch-unit scopes
When the same sentence is genuinely spoken in successive batch units, this lexical fallback can omit its later occurrence despite both spans being correctly placed and non-overlapping. projection_parts.py:14 assigns final:batch:<id> per unit, so different scopes do not establish duplicate audio: the 12-word sentence used by the new tests at [0,10] in unit A and [30,40] in unit B is reduced to A because both midpoints fall within the 45-second window. This hides genuine repeated questions or commitments and their second segment IDs from both summary and task prompts. Require additional duplicate-audio or clock-shift evidence before suppressing disjoint placed spans.
Useful? React with 👍 / 👎.
Require unambiguous placed matches and bounded ordered clock alignment for long donors without frame proof. Retain later repeated speech and uncertain candidate windows. Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 752b5d1026
ℹ️ 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".
| batch_repeats = dedupe_donor(survivors, incoming, live_row) | ||
| survivors = batch_repeats.kept |
There was a problem hiding this comment.
Require occurrence proof for short late-sync appends
When a late upload recovers a missing span in a finalized batch and both pools have at most 64 segments, this new write-side pass disables occurrence alignment and accepts lexical matches up to 1,800 seconds away. A genuine repeated sentence at [30,40] is therefore discarded against an earlier [0,10] occurrence without capture receipts; the previous proof-gated fresh-intake path retained it. Empty survivors then triggers repeat-only acknowledgement, and store_intake_audio() skips the uploaded audio. Require capture or occurrence proof for this fallback regardless of pool size, consistent with backend/AGENTS.md’s “never drop uncommitted audio” rule.
AGENTS.md reference: backend/AGENTS.md:L323-L323
Useful? React with 👍 / 👎.
| Finalized batch-live targets also apply the stored-donor lexical rule to late | ||
| sync appends, including older uploads without source-frame receipts. This |
There was a problem hiding this comment.
Add the required pipeline change note
This commit changes transcript suppression and batch-live recording ownership, but adds no pipeline change note. backend/AGENTS.md explicitly requires audio, transcription, and conversation-lifecycle changes to “add a note under docs/listen_pusher_pipeline/changes/ in the same PR.” Add that note with the unconditional recording-bound behavior, gated dedupe behavior, rollout/rollback controls, and validation evidence; the config docstring does not satisfy the required operator-facing documentation.
AGENTS.md reference: backend/AGENTS.md:L164-L164
Useful? React with 👍 / 👎.
…im read test The fixture's module stubs unload newly imported modules between tests; the prompt-canonicalization import chain registers Prometheus metrics, so a second import raised a duplicate-timeseries error on CI. Import it at collection. Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]>
The render import chain now reaches utils.metrics, which imports database.fsr_cache_telemetry. Three tests stubbed `database` with an empty __path__, so collection failed. Point the stub at the real package directory; explicitly stubbed submodules stay stubbed. Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b1b9a98eba
ℹ️ 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".
| if batch_repeats.capture or batch_repeats.lexical: | ||
| methods = set(report['methods']) | ||
| report['alignment_method'] = next(iter(methods)) if len(methods) == 1 else 'mixed' | ||
| live_stats['exact_retries'] += batch_repeats.exact_retry |
There was a problem hiding this comment.
Preserve completion debt from the new batch exact-retry pass
When a late upload exceeds 64 segments and contains long batch copies plus a short sync:-scoped retry from an append that crashed before completion, the initial exact-retry pass leaves sync_retry=False because its incoming pool is oversized. The new dedupe_donor pass can remove the long copies and then exact-retry the short remainder, but it discards drop_proven_exact_retries' third return value, and this block only adds the retry count. With no survivors, assignment returns repeat-only without _sync_lineage_completion_pending, so complete_sync_intake() neither enrolls _merged nor calls finish, acknowledging the retry without resuming the previous append's completion. Propagate the second pass's sync-retry signal into live_stats['sync_retry'] as well.
Useful? React with 👍 / 👎.
Problem and change
A phone upload and a finalized live batch can contribute transcripts for the same audio. Stored donor dedupe previously skipped chapters above 64 segments, and its 30-minute candidate window overflowed on long recordings. Late uploads without frame receipts also missed the stored-donor lexical rule. This change keeps the already durable canonical transcript when the bounded matcher independently covers the repeated words, handles stored chapters up to 4,096 segments with local candidate windows, and commits donor redirects/ancestry even when every incoming word repeats.
For long pools, the 90-second window is candidate discovery only. Without frame proof, a drop additionally requires an unambiguous placed occurrence: normalized exact text at centisecond-equivalent endpoints, or three consecutive one-to-one monotonic matches with a clock displacement of at most 30 seconds and start/end residuals agreeing within 2 seconds. Repeated phrases in either copy, competing reference windows, unplaced speech and inconsistent neighbour timing abstain. This prevents a phrase spoken again 60 seconds later from being deleted while retaining true-copy matching across realistic clock skew. Frame-proven matching and the pre-existing short-pool policy retain their existing authority.
A sealed batch recording now accepts only sync input and whole donors inside its recording bounds. A stale phone stamp or a gap-connected earlier donor can no longer place a long chapter at negative offsets inside a later short recording. Non-contained content remains on its own correctly timed sync row; temporal discovery prefers a containing recording.
Matching retains novel words, negations, numbers, uncertain alignments and over-budget content. A bounded prompt-only projection also excludes independently matched cross-scope batch copies from normal and compact summary input, preferring placed and richer text while retaining source IDs and stored annotations. Identical cross-scope text at centisecond-equivalent endpoints is omitted even below the long-line lexical threshold; short acknowledgments, same-scope repetition and occurrences beyond the prompt's local time window stay. This covers existing rows when they are processed without mutating their stored transcripts. Existing stored transcripts are not backfilled by this PR. Conservative matching can retain ambiguous repeats; this is not a claim to eliminate every heuristic near-duplicate. The existing default-on
SYNC_LINEAGE_LIVE_DEDUPE_ENABLEDkill switch and lineage cohort gate remain in control of transcript dedupe. Recording-bound correctness is unconditional for batch-live targets. Prompt filtering uses the same kill switch and requires multiple capture scopes. No new flag, production operation, provider-call site, billing-policy change, audio acknowledgment or erasure-path change.Validation
Synthetic fixtures exercise long donors, changed wording/negation/numbers, late sync appends without frame receipts, all-repeat ancestry, out-of-bounds stamps, gap-connected donors, pre-existing negative offsets, open-recording append, containing-target selection, and malformed prompt clocks. Added regressions cover the 65-segment later-occurrence reproduction, positive copies at ±26.4-second skew, repeated phrases in either input, mismatched durations, reordered/contradictory neighbours, one-to-one reference ownership and preservation of frame-proof authority. Production assignment and projection tests run with strict Firestore transaction fakes and no cloud credentials.
484 focused tests passed across these 12 suites:
test_sync_batch_transcript_ownership.py,test_sync_donor_live_dedupe.py,test_batch_pipeline_projection_donor_dedupe.py,test_sync_live_overlap.py,test_sync_pending_live_bridge.py,test_batch_pipeline_live.py,test_sync_live_speech_dedupe.py, andtest_sync_cross_job_assignment.py,test_batch_transcript_prompt_repeats.py,test_summary_transcript_user_name.py,test_compact_speaker_transcript.py, andtest_task_transcript_provenance.py.The previous reviewed head passed the required CI-lane manifest (37 checks), the normal pre-push hook and
make preflight. The occurrence-alignment revision752b5d10260f0b878f8e7106ef45c719b42ac3e5passed 484 focused tests, pinned formatting and all 37 required CI-lane manifest checks. The normal pre-push gate also passed, including the full pinned backend typecheck, bounded selected unit tests and local manifest. The remote PR head is verified at that exact SHA; GitHub CI and independent re-review remain pending. No live endpoint or device acceptance was run. The internal projection transaction is exercised directly; production was read-only. No fleet duplicate-audio rate is claimed; an aggregate job count does not identify redundant source audio. Offline prompt replay is unchanged by the occurrence guard. A paired stored-donor snapshot replay retains more ambiguous content, as expected. Neither replay is a historical transaction replay or a measured summary-quality outcome. No customer data or packet fixtures are included.Line-Count-Exception: backend/utils/sync/assignment.py | 1582 -> 1606 | Keep target and donor containment, final-batch lexical matching and repeat-only ancestry inside the existing atomic assignment transaction; matching policy remains in bounded pure helpers.
Failure-Class: none
🤖 Generated with Claude Code