Skip to content

feat(guard): minimum term overlap before preflight injects a memory - #255

Merged
CryptoJones merged 2 commits into
mainfrom
preflight-min-terms
Aug 15, 2026
Merged

feat(guard): minimum term overlap before preflight injects a memory#255
CryptoJones merged 2 commits into
mainfrom
preflight-min-terms

Conversation

@CryptoJones

Copy link
Copy Markdown
Owner

Problem

The proactive turn preflight injects the top-ranked vault note on any score > 0. A one-word prompt ("retry") reliably pulled an unrelated note (the Ghidra retry-budget memory) into every session, fleet-wide — top-ranked is not the same as relevant.

Fix

  • retrieve.matched_terms(task, text) — distinct stemmed task-term overlap; shares _tokens with overlap_score so relevance vocabulary stays unified.
  • retrieve.preflight_min_terms() — injection threshold, default 2, overridable via OMIND_PREFLIGHT_MIN_TERMS (0 restores legacy always-inject).
  • guard.preflight_turn() — a weak match now behaves exactly like a miss: nothing injected, consult gate auto-clears (honors OMI_GATE_MISS_STRICT=1), compliance-logged under omi-gate-weak-match.

An absolute count is used deliberately: recall-ratio scores can't gate this (a one-term task trivially scores 1.0 against any note containing the word).

Gate-deny suggestions are unchanged — naming the best candidate on a block is still right even at one shared word; this only stops unsolicited per-turn injection.

Validation

  • 3 new guard tests (weak-match auto-clear / strict opt-in / env disable) + 2 retrieve tests
  • ruff check + ruff format clean, mypy --strict clean on touched sources
  • full suite: 972 passed, 1 skipped

Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/

🤖 Generated with Claude Code

https://claude.ai/code/session_01XRHMqf9JLj1P6Gbb9XpFsh

…a memory

The turn preflight injected the top-ranked note on ANY score > 0, so a
one-word prompt like 'retry' pulled an entirely unrelated note into every
session (observed fleet-wide; ranked 'best' is not the same as relevant).

- retrieve.matched_terms(): distinct stemmed task-term overlap, sharing
  _tokens with overlap_score so 'matched' means the same thing everywhere
- retrieve.preflight_min_terms(): threshold, default 2, env-overridable
  via OMIND_PREFLIGHT_MIN_TERMS (0 disables the filter)
- guard.preflight_turn(): a weak match is treated like a miss — no
  injection, gate auto-clears (honors OMI_GATE_MISS_STRICT), logged as
  omi-gate-weak-match

Ratio scores cannot gate this (a one-term task trivially scores 1.0),
hence an absolute match count.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XRHMqf9JLj1P6Gbb9XpFsh
@coderabbitai

coderabbitai Bot commented Aug 15, 2026

Copy link
Copy Markdown

Important

Review available on request

  • 🔍 Trigger review

Reviews should be triggered manually for repositories with fewer than 10 stars. Select Trigger review above or comment @coderabbitai review to review the latest changes. For a full review, comment @coderabbitai full review.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1611f43c-4769-4da3-81d4-b75a4d5c2b7e


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@CryptoJones
CryptoJones merged commit 39c7078 into main Aug 15, 2026
16 checks passed
@CryptoJones
CryptoJones deleted the preflight-min-terms branch August 15, 2026 14:12
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