Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(augment): gate the rescue's FTS fallback on query-token coverage (#2092) - #2214

Open
punk-dev-robot wants to merge 3 commits into
repowise-dev:mainfrom
punk-dev-robot:fix/rescue-fts-token-coverage
Open

fix(augment): gate the rescue's FTS fallback on query-token coverage (#2092)#2214
punk-dev-robot wants to merge 3 commits into
repowise-dev:mainfrom
punk-dev-robot:fix/rescue-fts-token-coverage

Conversation

@punk-dev-robot

@punk-dev-robot punk-dev-robot commented Sep 11, 2026

Copy link
Copy Markdown

What

Fixes #2092. The zero-result grep rescue's FTS fallback (_rescue in cli/commands/augment_cmd/search.py) returned the first FTS row pointing at a code page with no quality check, so a multi-token pattern where only one common token matched produced a confident Wiki suggests ... line for an unrelated file (repro in the issue: bluetooth codec negotiation fallback riding on "fallback").

Shape

Token coverage, per @RaghavChamadiya's spec in #2092 (comment) (first comment) — not the BM25 floor I originally proposed: SQLite BM25 is unbounded while PostgreSQL ts_rank is ~0–1, so any constant floor silently kills the fallback on one dialect, and SQLite scores are clamp-postprocessed besides.

  • New fixed tunable _RESCUE_FTS_MIN_TERMS = 2, documented next to the other rescue tunables.
  • Gate in _rescue's FTS loop: needed = min(_RESCUE_FTS_MIN_TERMS, len(_pattern_terms(pattern))) distinct query tokens must appear in the row's title + target_path + snippet (lowered). Reuses _pattern_terms, the same guard family as the widened path's single-token check.
  • Single-token patterns still fire (needed = 1): the zero-result rescue deliberately allows generic names, and the gate must not mute that.
  • A below-coverage row is skipped with continue (a later row may cover) and logged at debug level — visible under augment --verbose — so we can watch what the gate is eating, as requested.

Measurements

From my local before/after run on the dotfiles repo (the table in #2092): the weak query covers 1/4 terms → now silent; btrfs space monitoring, containerd image cleanup, hyprland monitor workspace all cover ≥2 terms in the suggested row → still rescue. The unit tests encode the weak repro verbatim.

Tests

TestRescueFtsCoverageGate in tests/unit/cli/test_augment_search.py: weak single-token ride silent, covered row fires, gate scans past a weak first row, single-token pattern still fires, non-code page still skipped. Sabotage-verified: with the gate neutralized (needed = 0), the silent-ride and scan-past tests fail.

@punk-dev-robot

Copy link
Copy Markdown
Author

Checked both bot items:

  1. _log_search_firing is untouched — git diff main...HEAD has no hunk containing it (looks like a false positive on the signature-change detection). The two named callers in test_augment_served_reads.py pass.
  2. Ran the three importing test files plus this PR's: test_augment_fast_lookup.py, test_augment_search_digest.py, test_augment_served_reads.py, test_augment_search.py — 165 passed.

PunkDevRobot added 2 commits September 11, 2026 14:30
The coverage gate pushed _rescue near 80 lines. Pull the FTS-fallback
leg into its own helper, mirroring _rescue_wide_text, which is the same
extraction for the widened leg. Pure function of (pattern, rows); the
page-type check becomes a guard clause instead of a nested branch.
No behaviour change.
… change

ruff format swept rewraps of untouched code into the PR (main is not
format-clean and CI only runs ruff check) — that is what tripped the
bot's 'signature changed: _log_search_firing' and 'introduced complex
method: _handle_search_post' warnings; both functions are semantically
untouched. Restore main's formatting on every line this PR does not
own.
@punk-dev-robot

Copy link
Copy Markdown
Author

Both warnings were artifacts of a whole-file ruff format sweep: main is not format-clean (CI runs ruff check only, never format --check), so the formatter rewrapped _log_search_firing's def line (2→1 lines, same signature) and a line inside _handle_search_post (complexity 21 is pre-existing, not introduced). fe597fb restores main's formatting on every line this PR doesn't own — the diff is now exactly the #2092 change: the tunable, the gated _rescue_fts_text helper, and its tests. All named callers still pass.

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.

augment: grep-rescue FTS fallback fires on weak matches — add relevance floor

1 participant