Repository navigation
feat(backend): fold silence-split pendant conversations with Jev (default off, shadow/merge modes) - #19777
Merged
Conversation
…efault off) Adds the pieces that decide whether a finished pendant conversation continues the immediately preceding one and, in merge mode, fold it in: - config/conversation_smart_merge.py: CONVERSATION_SMART_MERGE_MODE (off|shadow|merge, default off) and the benchmark-derived constants (threshold 0.35, gap 120 s-60 min, 3 s / one attempt, state caps, snowball caps). - smart_merge_state.py: benchmark question wording A and chain-aware state. - smart_merge_policy.py: deterministic eligibility, gaps, stretch, and absorb payloads reusing the sync bridge redirect contract. - database/smart_merge.py: preceding-row query (registered spec on the existing conversations_discarded_source_status_created index), decision record, absorb transaction, survivor refresh lease. - smart_merge.py: orchestration, fail-open before commit, replayable after. - ProcessingTrigger.SMART_MERGE and omi_conversation_smart_merge_* metrics. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…repair WALs to the survivor The finalizer calls the smart-merge step behind the fanout claim and before duplicate-capture linking or any derived effect, for CAPTURE_END jobs only. An absorbed conversation skips its own derived effects and completes fanout; a donor always resumes its cleanup and survivor refresh on retry, whatever the mode. Flag off adds one env read and no I/O. Sync assignment follows a smart-merge donor's redirect when a late repair WAL targets it, so the audio appends to the survivor instead of recreating the donor as a duplicate row. Sync bridge donors keep the temporal fallback. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Registers CONVERSATION_SMART_MERGE_MODE and CONVERSATION_SMART_MERGE_UID_ALLOWLIST (no deploy manifest declares either) and records the finalizer, redirect and sync-assignment contracts in the conversations/sync ARCHITECTURE files and the listen/pusher pipeline doc. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Git-on-my-level
marked this pull request as ready for review
September 29, 2026 12:18
…erge Co-Authored-By: Codex Luna <[email protected]>
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Live capture ends a conversation after about two minutes without speech, so one occasion can become many rows (one evening on 2026-09-28 became 7 conversations with 2-10 minute boundaries). Nothing on
mainmerges silence-split live conversations by topic.This PR adds a default-off, three-mode step to the durable finalizer that asks Jev whether a just-finished pendant conversation continues the immediately preceding one from the same device, and in
mergemode folds it in. With the flag unset nothing changes.CONVERSATION_SMART_MERGE_MODE:off(default, and any unknown value): one env read in the finalizer, no reads, no model call, no writes.shadow: select the candidate, build the state, ask Jev, store a server-onlysmart_merge_decisionrecord on the new conversation (shadow_would_merge/shadow_keep), emit metrics. Never merges.merge: same, and atp_same >= 0.35the earlier conversation keeps its id and absorbs the new one.CONVERSATION_SMART_MERGE_UID_ALLOWLIST(optional): when set, only those users are considered (empty = everyone), so shadow can run on one account first. Neither flag is declared in any deploy manifest. Enabling either mode is a separate decision.Design (what and why)
finalize_persisted_conversation, after the fanout claim isclaimedand before duplicate-capture linking and the derived-effects bundle, forCAPTURE_ENDjobs andomi(pendant) source only. That point runs exactly once per job under the existing lease. A merged conversation's memories, action items, webhooks and vectors are never produced, so there is nothing to retract.CLIENT_FINALIZEcounts as a manual split and is honoured. Sync and desktop are out of scope: the benchmark was 113/138 pendant pairs and desktop recall was 0/2.perform_merge_async, which mints a new id. The new row becomesdeleted + discarded + sync_merged_into=<survivor>, and the survivor getssync_merged_from. Existing redirect readers work unchanged: detail GET redirects to the survivor, manual speaker assignment follows the chain, list/count/search hide the tombstone, and deleting the survivor purges retained donors. The transcript is appended on the survivor's absolute timeline. Speaker ids are reallocated throughConversationSpeakerIdAllocatorso two voices never collapse, and segment ids are kept.FirestoreQuerySpecwhose signature is the existingconversations_discarded_source_status_createdindex.firestore.indexes.jsonis unchanged, so no index is provisioned.smart_merge.fragmentsledger, never the regenerated merged summary, which the benchmark did not test. Jev goes through the existingutils/llm/jev_client.ask_jevon laneconversation_smart_merge(gateway laneomi:auto:jev-decisions), 3 s, one attempt. Any error keeps both conversations.ProcessingTrigger.SMART_MERGE: run now, reprocess, bypass JIT, relevance KEEP), plus a re-embed. There is no debounce: a one-refresh-per-chain debounce needs a durable delayed trigger that the live path does not have. Sync appends are not debounced either.refreshed_revision == revisionon the survivor, and the refresh runs under a short lease, so a refresh can never persist over a newer append. The transaction re-reads both rows, so a concurrent star, title, edit or delete aborts the merge. The decision record is sticky, so a retried job never re-asks Jev. Once the transaction commits, the donor branch resumes cleanup and refresh on every retry, in any mode. It never runs the donor's own derived effects.app/libanddesktop/macos, not assumed): neither client knowssync_merged_into. The listenmemory_createdevent for a merged conversation carries the tombstone withdiscarded=true, so Flutter drops its processing card and hides the row, and macOS reloads a list that no longer contains it. Known client gaps, not fixed here:Benchmark provenance (offline, 2026-09-29)
The private report lives outside git on David's machine (
~/.local/share/jev-pilots/adjacent-merge/REPORT.md). No transcript text is in this PR, and all fixtures are synthetic.>= 0.35) on held-out: AUC 0.918 (bootstrap 95% CI 0.84–0.98), 25/49 continuations merged, 0/19 false merges (exact one-sided 95% upper bound 14.6%). The nearest held-out negative scored 0.305.Verification
Worktree
lane/smart-merge-jev, baseorigin/maind97f753. All runs are local and hermetic. Each result names the layer it measured.BACKEND_UNIT_TEST_FILE_LIST=… bash backend/test.sh: all passed.test_conversation_smart_merge_state.py(8): exact template texttest_conversation_smart_merge_policy.py(29): every exclusion, gap edges 119/120/3600/3601, speech-gap shard, word minimum, caps, stretch 30-minute link, absorb payloadstest_conversation_smart_merge.py(38), which covers:test_conversation_smart_merge_finalizer.py(4): derived effects skipped on absorb, unchanged path when kept or offtest_sync_cross_job_assignment.py(+4: donor-redirect repair WAL, deleted survivor, bridge donor unchanged).test_sync_v2,test_sync_cloud_tasks,test_sync_transcription_prefs,test_sync_bridge_lifecycle, archive filterbackend/scripts/typecheck.sh(pyright): 0 errorsscripts/backend-python-format --check: cleancheck_conversation_lifecycle_writes.py: passfirestore_query_coverage.py --check-ratchet: passgenerate_firestore_indexes.py: manifest unchangedcheck_feature_flag_registry.py: OKmake runtime-image-source-closure: passmain(236 modules; no onnxruntime/torch).ask_jev)process_conversationrefresh (faked at its seam)Deploy targets (when David decides to deploy)
Rollback: leave
CONVERSATION_SMART_MERGE_MODEunset/off. Ifmergewas ever on, the redirect tombstones keep each donor's full document and original audio. A merge is reversible by an operator (restore the donor, remove its segment ids from the survivor, reprocess both); no route or script for that ships here.Known risks / for review
typesafe/jev-1.13.Product invariants affected
Line-Count-Exception: backend/database/firestore_index_registry.py | 1527 -> 1545 | the registry is the single place a serving compound query may be declared; the new spec reuses an existing index signature
Line-Count-Exception: backend/database/conversations.py | 3191 -> 3204 | the canonical processor persistence transaction must fence smart-merge refresh leases
Line-Count-Exception: backend/utils/conversations/process_conversation.py | 3416 -> 3421 | the processor must pass the refresh fence to canonical persistence
🤖 Generated with Claude Code
Review round 1 (Codex Sol)
Confirmed and fixed: invalid Jev scores could merge or be stored; merge decisions were not durable before absorb; stale processors could overwrite a newly merged live survivor; a revisioned survivor could lose live-target sync repair semantics; a refresh could be marked complete after its lease was lost or after vector failure; custom-STT budget denial could leave a survivor permanently owing refresh; metric reasons and fragment metadata were insufficiently bounded. The lifecycle guard now inventories the variable-payload tombstone writer.
Hermetic regression tests went red before each fix. Three deliberate mutants (revision fence, flag-off path, user-managed exclusion) each made its targeted test fail. The 33-file backend suite named above plus new regression files passed locally through
backend/test.sh; pyright reported 0 errors; formatter, runtime image source closure, and lifecycle guard passed. Pusher's reachable third-party set contains no onnxruntime or torch. No live Jev, Firestore, client, deployment, or merge-mode acceptance was run. BYOK refresh without a reusable key remains a merge-mode blocker; shadow mode does not refresh.