Repository navigation
fix(conversations): one relevance decision for every processed conversation - #16587
Merged
Merged
Conversation
…levance decision
Offline-sync fragments ("Oh", "Brief acknowledgment") reached users with full
LLM summaries because `force_process=True` silently meant "skip discard", and
four of six production callers pass it on first processing: sync append,
POST /v1/conversations, POST /finalize, and desktop first open. The discard
gate only ran on listen finalization and the developer API.
- utils/conversations/relevance.py: callers name a ProcessingTrigger; a policy
table maps each to assess or keep (keep only for user actions: first open,
reprocess, merge). Assessment is tiered: user restore, stdlib-only rules,
then the conv_discard model; calendar overlap overrides any discard.
force_process now only means "run now".
- relevance_rules.py: the deterministic tier, shared by sync intake,
processing, and the model tier's word threshold.
- The decision is stored as `relevance_decision` (server-only) and counted in
conversation_relevance_decision_total, including model fail-open.
- Only user actions protect a review row; a generated summary no longer does.
- Any restore records sync_relevance_user_kept, so reassessment cannot
re-discard what a user kept.
- Removes the hand-copied visibility predicate in sync/assignment.py; stubbed
harnesses register the real pure modules instead.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…elevance rules Replaces the placeholder filler rule with rules designed and measured against 286 hand-labelled conversations from one real account (106 keep, 94 discard): 0 discards of a keep label, 44 of 94 junk settled without a model call (the previous sync filler check settled 8); held out: 0/28 keeps discarded. Rules, first match wins: empty -> discard; explicit reminder phrasing -> keep; fillers/backchannels only (incl. CJK and other common backchannels) -> discard; over 100 word-equivalents -> keep; unreadable script -> model; mic check -> discard; <=25 function/filler tokens with no digit or likely name -> discard; else the model decides. Duration is never used. Standalone "yes"/"no" stay with the model (an existing intake contract), and repetition alone never discards: a looping transcriber and pronunciation practice look alike. A trusted wake word skips the rules in both directions so the model's wake-word rules judge it, as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…arnesses conversation_processing.py now imports `from utils.conversations.relevance_rules import KEEP_WORD_COUNT` at module scope (PR #16587's relevance gate). Two legacy per-file test harnesses stub `utils.conversations` as an empty package and then exec conversation_processing.py from disk via `_load_module_from_file`, so the import resolves against the stub instead of the real stdlib-only module and CI fails with `ModuleNotFoundError: No module named 'utils.conversations.relevance_rules'` (test_action_item_date_validation.py, test_conversation_structure_timezone.py). Load the real relevance_rules module first, the same way these harnesses already load wake_word and summary_selection. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Git-on-my-level
added a commit
that referenced
this pull request
Sep 23, 2026
…ps it The Cloud Run managed-Prometheus sidecar keeps only omi_.* metric names, so conversation_relevance_decision_total was exported but dropped at ingestion after the #16587 deploy. Renamed to omi_conversation_relevance_decision_total and pinned by a test that reads the sidecar keep rule from the deploy YAML. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Git-on-my-level
added a commit
that referenced
this pull request
Sep 23, 2026
…ps it (#17280) * fix(metrics): name the relevance counter so the Cloud Run sidecar keeps it The Cloud Run managed-Prometheus sidecar keeps only omi_.* metric names, so conversation_relevance_decision_total was exported but dropped at ingestion after the #16587 deploy. Renamed to omi_conversation_relevance_decision_total and pinned by a test that reads the sidecar keep rule from the deploy YAML. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(metrics): linearize the sidecar-keep test's name extraction CodeQL flags the test's regex (py/redos, high): (?:\\s*#[^\\n]*)*\\s* has nested quantifiers and \\s matches newlines, so adversarial input can backtrack exponentially. Replace the comment-skipping regex with a linear line filter — same behavior, no backtracking class. Addresses CodeQL alert #359 on the new test file. --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: David Zhang <[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.
Why
Users see "conversations" that are one word long — a 0.32 s "Oh" titled Brief Utterance, Brief Acknowledgment, Unclear Utterance — each with a full LLM summary. On one real account, 12 of the 13 such items in two days came from the offline-sync path.
Root cause:
process_conversation(force_process=True)meant both "run enrichment now" and "skip the discard gate". Four of six production callers pass it on a conversation's first processing:sync/pipeline.py)SYNC_UPDATEPOST /v1/conversationsCLIENT_FINALIZEPOST /v1/conversations/{id}/finalize(via finalizer job)CLIENT_FINALIZEFIRST_OPENUSER_REPROCESSMERGECAPTURE_ENDThe sync intake's own filler check only recognised
mm/hmm/uh/um/ha, and the read-side fragment filter then treated the generated summary as evidence the user cared, so nothing downstream caught these either.What
One relevance decision,
utils/conversations/relevance.py:Callers name a
ProcessingTrigger;RELEVANCE_POLICYmaps each to assess or keep. Keep is reserved for triggers that are themselves a user action.force_processnow only means "run now". A test enforces that every trigger has a policy.Tiered assessment: user restore → stdlib-only rules (
relevance_rules.py) →conv_discardmodel for the ambiguous middle → calendar overlap overrides any discard (SCA-381, unchanged). Trusted wake words and photos always reach the model. Model errors still fail open to keep, now visibly.Every decision is stored as
relevance_decision(server-only Firestore field, deliberately outside the wire model — no client codegen churn) and counted inconversation_relevance_decision_total{trigger,verdict,decided_by,reason}. A path skipping the gate is nowdecided_by="policy"on a dashboard instead of junk in a list.Only user actions protect a hidden fragment (starred, renamed, restored, shared, foldered). A generated summary no longer does; the MCP projection stops reading the arrays that fed that check.
Any restore persists
sync_relevance_user_kept, so a model-discarded sync row that the user restores is never re-discarded by a later append.Deterministic rules, measured on real data (
relevance_rules.py, stdlib-only, ~60 µs): empty → discard; explicit reminder phrasing → keep; fillers/backchannels only (incl. CJK and other common backchannels) → discard; >100 word-equivalents → keep; unreadable script → model; mic check → discard; ≤25 function/filler tokens with no digit or likely name → discard; else the model. Duration is never used (segment spans are unreliable). Standalone "yes"/"no" stay with the model; repetition alone never discards.Short conversations reaching the model drop from 89% to 72%. The rules see only transcripts, never generated titles. Test cases are synthetic; no real transcript text is in the repo.
Simplifications: the duplicated notes-v2 structuring block in
_get_structuredis gone (one copy, legacy reprocess prompt selected inline); the hand-copied visibility predicate insync/assignment.pyis gone — stubbed harnesses now register the real pure modules viatesting.import_isolation.register_pure_relevance_modules.Product decision flagged for review
CLIENT_FINALIZE(a user ending a conversation in the app) now assesses instead of always keeping. It has skipped discard since 2025 with no recorded rationale. The discard is recoverable (Show discarded → restore), and a restore sticks. If always-keep is preferred, it is a one-line change inRELEVANCE_POLICY.Product invariants affected
Not in this PR (follow-ups)
discarded+sync_relevance=review+ empty-title + merged-donor tombstones.force_process/is_reprocessthemselves from the trigger (they also drive free-tier spend policy).Verification
test.sh(127 files): green. Two CPU-duration guards (0.35 s / 0.39 s vs 0.30 s) tripped only under a saturated parallel run and pass in isolation;test_sync_cloud_tasksneedsfakeredis+lupalocally.tests/unit/test_conversation_relevance.py(policy exhaustiveness, tier ordering, fail-open record);test_conversation_relevance_rules.py(57 synthetic cases); forced sync/client-finalize processing reaches the content gate (test_process_conversation_duplicate_capture.py); sync pipeline passesSYNC_UPDATE+ the stored restore marker; restore of a non-review row persists the user choice.Failure-Class: new
Failure-class transition narrative
Adds
FC-run-now-flag-skips-content-gate. Violated contract: a keep/discard decision every processed record must pass was skipped as a side effect of an unrelated "run now" flag (force_process), on four first-processing paths, with no trace. Canonical guard: callers name aProcessingTrigger, one exhaustively tested policy table decides whether a trigger assesses, and every decision is stored and counted by deciding tier. Evidence: one real account, 2026-09-21..22, 12 of 13 junk conversations came through the sync path with full summaries.Line-Count-Exception: backend/routers/conversations.py | 2133 -> 2137 | names the processing trigger at three call sites plus its import
Line-Count-Exception: backend/utils/llm/conversation_processing.py | 1968 -> 1976 | model tier reports failure through on_error and shares the rules' word threshold
Line-Count-Exception: backend/utils/sync/pipeline.py | 2518 -> 2524 | sync reprocess names its trigger, passes the stored restore marker, and counts intake rule discards
🤖 Generated with Claude Code