Skip to content

fix(conversations): one relevance decision for every processed conversation - #16587

Merged
Git-on-my-level merged 3 commits into
mainfrom
fix/one-relevance-gate
Sep 23, 2026
Merged

Git-on-my-level merged 3 commits into
mainfrom
fix/one-relevance-gate

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

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:

Caller Trigger Before After
Sync append (sync/pipeline.py) SYNC_UPDATE gate skipped assessed
POST /v1/conversations CLIENT_FINALIZE gate skipped assessed
POST /v1/conversations/{id}/finalize (via finalizer job) CLIENT_FINALIZE gate skipped assessed
Desktop first open FIRST_OPEN skipped kept (user action)
Manual reprocess USER_REPROCESS skipped kept (user action)
Merge MERGE skipped kept (user action)
Listen finalization, developer API CAPTURE_END assessed assessed

The 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_POLICY maps each to assess or keep. Keep is reserved for triggers that are themselves a user action. force_process now only means "run now". A test enforces that every trigger has a policy.

  • Tiered assessment: user restore → stdlib-only rules (relevance_rules.py) → conv_discard model 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 in conversation_relevance_decision_total{trigger,verdict,decided_by,reason}. A path skipping the gate is now decided_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.

    286 hand-labelled conversations, one account, 2026-08-11..09-22 Discarded a KEEP label Junk settled without the model
    Old sync filler check 0 / 106 8 / 94
    New rules 0 / 106 44 / 94
    New rules, held-out 30% 0 / 28 8 / 23

    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_structured is gone (one copy, legacy reprocess prompt selected inline); the hand-copied visibility predicate in sync/assignment.py is gone — stubbed harnesses now register the real pure modules via testing.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 in RELEVANCE_POLICY.

Product invariants affected

  • INV-MEM-4 — matched by path only. A discarded conversation produces no memory intake, as before; kept conversations take the unchanged Short-term route. No promotion path is added.
  • INV-TASK-2 — matched by path only. Action-item extraction, the proposing/writing split, and prompts are untouched; the relevance step runs before extraction and can only prevent it.

Not in this PR (follow-ups)

  • One stored visibility field replacing discarded + sync_relevance=review + empty-title + merged-donor tombstones.
  • Attaching short sync fragments to an adjacent conversation instead of judging them alone (sync fragmentation).
  • One-time reassessment of existing leaked sync rows (writes to production data; needs an explicit go-ahead).
  • Desktop legacy deferred capture (flag-off, must stay byte-identical) still stores raw transcripts unassessed; first open keeps by policy.
  • Deriving force_process / is_reprocess themselves from the trigger (they also drive free-tier spend policy).

Verification

  • Backend unit suites touching these modules, run file-isolated via 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_tasks needs fakeredis + lupa locally.
  • New: 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 passes SYNC_UPDATE + the stored restore marker; restore of a non-review row persists the user choice.
  • pyright: 0 errors in the changed production modules.
  • Not measured: live behaviour on dev/prod. Nothing here was deployed.

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 a ProcessingTrigger, 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

Review in cubic

Git-on-my-level and others added 3 commits September 23, 2026 09:19
…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
Git-on-my-level merged commit 64e07a0 into main Sep 23, 2026
61 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/one-relevance-gate branch September 23, 2026 03:24
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]>
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