Skip to content

fix(speakers): honor the manual-assignment receipt at every transcript boundary - #15345

Merged
Git-on-my-level merged 7 commits into
mainfrom
fix/speaker-identity-hardening
Sep 21, 2026
Merged

Git-on-my-level merged 7 commits into
mainfrom
fix/speaker-identity-hardening

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

Why

PR #15247 made cross-conversation speaker labeling viable on mobile. An external review of the merged
head then found that the manual-assignment receipt it introduced is not honored at every boundary. Three
independent verification passes plus executed reproductions confirmed the core of it. This PR closes those
gaps.

The headline defect is not cosmetic: a live merge could widen a labeled segment's span, and the voice
enrollment window is cut from the centre of a segment's current bounds
(utils/speaker_identification.py, SPEAKER_SAMPLE_WINDOW_HALF = 5.0). A 1-second label absorbed into a
10-second span therefore fed another person's voice into the labeled person's profile.

What was wrong, and what this changes

Live merging ignored the receipt (R3 + R5a). combine_segments had no identity guard at all —
person_id appeared zero times in it. The forward-merge branch also emptied the accumulator without
recording the absorption, so a label applied to a live bubble was silently lost and its enrollment
silently skipped (Segment ... not found → continue).

Fresh STT input is no longer merged before persistence. The live call passes it through to the existing
transcript transaction, which decodes the current persisted transcript and receipt and plans the merge
there via merge_live_segments. Any merge or partial transfer touching covered speech is refused — selected
ids, speaker-wide defaults, clears, opt-outs, and legacy receipts that carry ids but no newer fields. The
transaction returns the accepted transcript plus removal/absorption metadata, so the client and storage
cannot disagree about which ids exist.

A cache-based guard was designed first and rejected: the live ConversationCache holds a snapshot for
30 s and assign_conversation_speaker invalidates only the client projection, so the guard read an empty
receipt in exactly the dangerous window. A cache guard can be an optimization; it cannot be the correctness
boundary.

Sync could absorb and tombstone a labeled conversation (R2). The labeled-donor protection in
utils/sync/assignment.py was gated on not target_id, so the routine offline path
(/v2/sync-local-files?conversation_id=…) bypassed it. auto_mergeable does not consider
manual_speaker_assignments, so a labeled row was still auto-mergeable. Labeled donors are now excluded
before they widen the search extent, and a labeled retry anchor cannot be retargeted — raising
SyncAssignmentSuperseded, not SyncAssignmentConflict, because the latter is a loud retryable error
and this condition is permanent.

Two of three transcript writers dropped the receipt (R1). upsert_conversation_with_lifecycle and
persist_processing_result_with_lifecycle re-read inside their transaction and preserve title/folder, but
never re-applied manual decisions; sync_content_revision never arms for listen/desktop rows. A processor
holding a pre-label snapshot reverted the user's label while the receipt sat orphaned, which also
de-authorized teaching via acknowledged_teaching. Both writers now overlay the current stored receipt, and
scripts/check_conversation_lifecycle_writes.py was extended so a fourth writer cannot reintroduce the
asymmetry.

Storage (R6a, R6b, R4). Protection migration now moves the receipt with the transcript under one
transactional document decision. update_conversation_segments takes the stored protection level over a
caller hint. A non-dict receipt is rejected at the write side — deliberately not by making the read
decoder raise, which would have turned an unreachable silent bug into a reachable outage in the ~0.6 s live
persistence loop.

Retired ids could be resurrected (R5b). Translation and speaker-flush writers shipped whole segment
lists they did not own. They now patch only their own fields, intersected with current persisted ids.

Client (R8). unassignConversationTranscriptSegment had zero call sites; deleted rather than patched. A
transport exception in assignSpeaker now returns false instead of propagating.

Latency

Merge planning moved inside a transaction, so it runs under retry amplification. Measured
(.local/benchmark_live_merge.py, 60 samples/case), planner computation only:

Stored / fresh p50 p95
1,000 / 8 (≈1 h of speech) 0.088 ms 0.091 ms
10,000 / 1,000 (buffer cap, stress) 4.562 ms 12.245 ms

Against the 600 ms live interval this is immaterial in the realistic case. Worst case with the SDK's 5
contention attempts and up to 3 expiry restarts is a computed ceiling of ~184 ms (~31% of the interval) —
disclosed, not measured under real contention. Mitigated by hydrating only the mutable tail and fresh batch;
no additional transaction read was introduced.

Verification

Not verified: physical-device acoustic acceptance, real STT/embedding/LLM, real Firestore contention,
dev/prod backend. No recognition-quality claim is made by this PR. Matcher thresholds, embeddings and
recognition policy are untouched.

Deliberately not in this PR

  • REST→live-session wake. registry.py only subscribes to proactive_message:listen and always builds a
    ProactiveMessageEvent, so a distributed assignment wake needs new typed dispatch — and it cannot make
    merging correct. Consequence: a label saved elsewhere may look stale in the live view until a reload,
    socket notification, or covering update. The transaction still protects the saved span throughout.
  • Durable enrollment worker; macOS/Windows/web adaptation to canonical speaker_id; processor snapshots
    staleness in content for non-sync rows; the e2ee codec level; R7 same-conversation profile refresh
    (an intentional scope decision, not a defect).

Line-Count-Exception: backend/database/conversations.py | 2695 -> 2788 | Receipt overlay helper shared by both lifecycle writers, transactional migration reread, and the live merge planner entry point stay with the transaction owner.

Failure-Class: FC-fixture-mock-signature-drift

Removing the dead update_conversation_segments import from utils/sync/pipeline.py broke three
tests that monkeypatched it by that name — the limiting case of a mock site drifting from
production. That class's canonical prevention is to grep the test tree for monkeypatch sites of a
symbol the PR changes and update them in the same PR; the fix does that, and the invariant those
patches encoded is now a structural source check rather than a patch on a name that no longer
exists.

🤖 Generated with Claude Code

Git-on-my-level and others added 6 commits September 21, 2026 12:15
Exclude labeled donors before widening the interval; preserve an existing labeled anchor and treat explicit retargeting as terminal supersession.

Validation: BACKEND_UNIT_TEST_FILE_LIST=../.local/final-files.txt bash test.sh; test_sync_cross_job_assignment.py: 29 passed (full selected suite recorded in .local/REPORT.md).

Co-Authored-By: Claude Opus 5 <[email protected]>
Keep fresh STT input unmerged until the transaction reads current speech and receipt coverage. Protect selected IDs, speaker defaults, clears and opt-outs across every text-transfer branch. Return accepted client IDs and removals from the same attempt. Fix forward absorption and transitive remapping together with that protection.

Validation: BACKEND_UNIT_TEST_FILE_LIST=../.local/merge-files.txt bash test.sh passed, including all five required import-isolation suites. Native tests cover stale input, attempt replay, partial transfers and client/storage ID agreement. Existing remap tests that expected expanding a manual label were replaced by these production-boundary regressions, based on reproduced R3/R5(a) in merged PR #15247.

Latency: .local/benchmark_live_merge.py measured planner p95 0.091 ms at 1000 stored + 8 fresh segments; 12.245 ms at 10000 + the 1000-segment runtime buffer cap. SDK contention multiplies computation up to 5x; expiry restarts can combine to 15x. These are CPU/local wall measurements, not Firestore latency.

Co-Authored-By: Claude Opus 5 <[email protected]>
Both processing writers decode the committing receipt, overlay it on their encoded snapshot, and encode at the current stored protection level. Extend the existing lifecycle static tripwire to inventory transcript owners and reject an unguarded new snapshot writer.

Validation: BACKEND_UNIT_TEST_FILE_LIST=../.local/final-files.txt bash test.sh: 648 passed across 19 selected files, including 16 new lifecycle receipt cases and existing lifecycle/processing contracts. backend/scripts/check_conversation_lifecycle_writes.py passed. Summaries still require explicit refresh; stale non-sync processor content remains out of scope.

Co-Authored-By: Claude Opus 5 <[email protected]>
Read the current document in each migration transaction and re-encode its transcript and receipt together. Stored protection metadata outranks live caller hints. Reject non-object receipts at the write boundary while retaining tolerant reads for existing malformed shapes.

Validation: BACKEND_UNIT_TEST_FILE_LIST=../.local/final-files.txt bash test.sh passed; 11 storage regressions use real standard/enhanced codecs, both migration directions, legacy absence, an edit after the initial scan, repeat migration and malformed write inputs. No cloud migration was run; e2ee codec handling remains outside scope.

Co-Authored-By: Claude Opus 5 <[email protected]>
Return false on assignment transport exceptions without painting optimistic identity or offering summary refresh. Remove the unused unassignConversationTranscriptSegment method instead of maintaining a second mutation path.

Validation: cd app && flutter test --no-pub test/providers/speaker_summary_refresh_test.dart: 4 passed. Transport failure leaves identity unchanged and an acknowledged retry succeeds. No strings or wire schema changed; device UI was not exercised.

Co-Authored-By: Claude Opus 5 <[email protected]>
Field-only writers intersect their updates with current persisted IDs and preserve current speech text, spans and ordering. Translation publishes accepted results rather than the stale input. Remove the unused sync import and document the complete writer contract and deferred cache wake.

Validation: BACKEND_UNIT_TEST_FILE_LIST=../.local/resurrection-files.txt bash test.sh: 48 passed across nonowning writer, manual assignment and listen runtime suites. Full selected run: 648 passed. Lifecycle checker and async blocking scanner passed; no live service or customer data was used.

Co-Authored-By: Claude Opus 5 <[email protected]>
@mintlify

mintlify Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
omi 🟢 Ready View Preview Sep 21, 2026, 5:31 AM

💡 Tip: Enable Automations to automatically generate PRs for you.

Removing the dead `update_conversation_segments` import from utils/sync/pipeline.py made three
dedup tests fail at `mock.patch` setup: they patched it by that name and asserted it was never
called. The import was already dead at the merge base — imported, never invoked — so the
assertion could not have failed for a behavioural reason.

Replace it with a structural guard so the invariant those patches encoded survives: sync intake
must not acquire a second transcript writer that bypasses the manual-assignment receipt. The
guard reads the source instead of importing the module; importing the real module inside the
call phase cost 1.56s against the runner's 0.30s CPU budget, and a text check also catches a
reintroduced import that was never loaded.

Validation: the file passes via test.sh (46 passed, exit 0, no duration-guard failure), and a
sweep of all 37 test files that patch names on the modules this PR changes passes 1152 tests.

Failure-Class: FC-fixture-mock-signature-drift

Co-Authored-By: Claude Opus 5 <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit ad0218d into main Sep 21, 2026
66 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/speaker-identity-hardening branch September 21, 2026 06:53
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