Skip to content

feat(review): verify each finding's line against the source line the model quotes - #734

Merged
ajianaz merged 1 commit into
developfrom
feat/finding-position-validation
Nov 16, 2026
Merged

ajianaz merged 1 commit into
developfrom
feat/finding-position-validation

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

What

Findings are checked against the source line the model quotes. The review and scan prompts ask for a snippet, and judge::admit moves a drifted line to the line that holds the quote, or makes the finding file-level when the quote cannot be found.

Why

Closes #721. admit (#644) already drops a file that is not in the diff and drops a line that the diff or file does not contain. What it could not catch is a line that exists but is the wrong one (the model is off by a few lines), so a review comment, a SARIF location, findings, fingerprint auto-resolve and debt trends could all point at code the finding is not about. The inspiration is the "external positioning module" of alibaba/open-code-review (Apache-2.0); this version fits the existing admission point instead of adding a second pass.

How

  • ReviewIssue.snippet: Option<String>: read from the model reply, skip_serializing, so JSON, SARIF and the database are unchanged. ReviewIssue::new sets it to None.
  • engine/llm/prompts.rs: the review and scan response schemas gain "snippet".
  • engine/judge.rs: verify_position(source, file, line, snippet) runs inside admit, after the existing "line must exist" step, so it covers review, scan and the MCP tools at once:
    • the quote is on line: unchanged;
    • on exactly one line within 25 lines of line (the nearest wins unless two are equally near): line moves there;
    • with no line, a unique match in the file sets it;
    • otherwise the finding becomes file-level, the same way security(review): treat judge output as untrusted input; self-contained Packet; correct cache key #644 treats a missing line.
    • The quote is the first non-empty line of the snippet, with a +/- marker removed and whitespace collapsed; it matches by substring. Quotes shorter than 4 characters are not trusted. No quote, or a file the source does not cover: unchanged. A line outside the diff is recovered from its quote.
  • Why not a fuzzy match or more fields: the quote is one verbatim line, so exact-after-normalization is enough, cheap and predictable; a miss degrades to file-level rather than guessing.
  • Not in this PR: end_line ranges and feat(review): reflection pass — filter false positives & normalize severity before persisting #723 (reflection).
  • Docs (configuration.md, Anti-Hallucination) and the changelog are updated.

Testing

  • cargo test --features tree-sitter passes (1349 unit tests + integration suites)
  • cargo fmt --all -- --check passes
  • cargo clippy --all-targets --features tree-sitter -- -D warnings passes
  • cargo build --release --features tree-sitter passes (left to CI)
  • Manual check with the real binary and a local fake OpenAI-compatible server that always answers with one finding claiming line 6 of a 6-line diff whose real line is 3: with a matching snippet the finding is reported on line 3; with a snippet that is not in the file it is file-level; with no snippet it stays on 6 (old behaviour).
  • Mutation check: with verify_position disabled, 7 of the new tests fail.

New tests (11): quote on the claimed line, drift snapped, whitespace and + marker ignored, quote found nowhere, two equally near matches (ambiguous) and the nearer one winning, no claimed line with a unique and a repeated quote, a line outside the diff recovered from its quote, too-short quote ignored, no quote keeps the old behaviour, full-file source (near drift fixed, a match 98 lines away not followed), and snippet read from JSON but never written.

Related Issues

Closes #721. Related: #644, #723.

Checklist

  • Branch name follows convention (feat/)
  • Branch is from develop
  • Commit messages follow Conventional Commits
  • No secrets or credentials committed
  • One logical change per PR (no mixed concerns)

ajianaz added a commit that referenced this pull request Nov 16, 2026
…729)

## What
The three CI fixes that only work together, in one PR: the Clippy
`needless_bool` rewrite, the `Cargo.lock` bumps for `rustix` and
`libz-sys`, the `rusqlite` 0.41 upgrade for the SQLite CVE, and the
sorted directory walk that de-flakes a test. It supersedes #728 and
#730, whose commits are included here.

## Why
Every PR to `develop` fails the same three checks, none of them caused
by the PR, so no single fix can be green on its own and none can be
merged under the required checks:
- **Clippy**: `clippy::needless_bool` at `src/engine/rules/builtin.rs`
on Rust 1.100 (the CI toolchain; local 1.97 does not report it).
- **Security Audit (CVE)**: `rustix 1.1.5` (RUSTSEC-2026-0486),
`libz-sys 1.1.30` (RUSTSEC-2026-0418) and `libsqlite3-sys 0.28.0`
(CVE-2026-119375, SQLite before 3.54.0).
- **Test**:
`mcp::agent_tools::tests::finalize_agrees_with_prepare_only_for_the_same_filters`
depends on the filesystem's `readdir` order.

## How
- `26768e8` (#728): `builtin.rs` returns the condition directly;
`Cargo.lock` only: `rustix` 1.1.6, `libz-sys` 1.1.33.
- `beee771`: `rusqlite` 0.31 to 0.41 (`libsqlite3-sys` 0.39.1, SQLite
3.54.1), `rust-version` 1.85 to 1.89, `usize` binds as `i64` in
`index/brain.rs`, and `[lints.clippy] collapsible_if = "allow"` because
Rust 1.89 enables let-chains and clippy would report 56 hits in
untouched code (a wide mechanical rewrite for a later change).
- `1275b71` (#730): `WalkBuilder::sort_by_file_name`, and the test uses
a selection whose `path` and `source-first` orders differ by
construction.
- Two merge commits bring #728 and #730 in with no conflicts.
- MSRV 1.89 is user-visible for anyone building with `cargo install` on
an older toolchain; the release notes should say so.

## Testing

- [x] `cargo test --features tree-sitter` passes (1313 unit tests +
integration suites)
- [x] `cargo fmt --all -- --check` passes
- [x] `cargo clippy --all-targets --features tree-sitter -- -D warnings`
passes (the CI Clippy check on Rust 1.100 is the real proof for
`needless_bool`)
- [ ] `cargo build --release --features tree-sitter` passes (left to CI)
- [x] Locked versions after the merges: rustix 1.1.6, libz-sys 1.1.33,
libsqlite3-sys 0.39.1, rusqlite 0.41.1.
- [x] Database compatibility of the `rusqlite` upgrade was checked in
both directions (old release binary indexed 800 symbols, new build read,
re-indexed and ran a `brain` search on the same `cora.db`, old binary
read it back, `PRAGMA integrity_check` = `ok`).
- Individually, the earlier runs showed: #728 Clippy green (fix proven),
#730 Test green (flake fixed), #729 Audit with only `rustix`/`libz-sys`
left.

## Related Issues
Supersedes #728 and #730. Unblocks #727, #731, #732, #733, #734, #735,
#736, #737.

## Checklist

- [x] Branch name follows convention (`chore/`)
- [x] Branch is from `develop`
- [x] Commit messages follow [Conventional
Commits](https://www.conventionalcommits.org/)
- [x] No secrets or credentials committed
- [x] One logical change per PR: one logical goal (a green CI), several
small causes that cannot be separated under the required checks

🤖 Generated with [Claude Code](https://claude.ai/code)

https://claude.ai/code/session_01F36Uc6swK21c7x7J14k1wc

---------

Co-authored-by: Claude <[email protected]>
…model quotes (#721)

The review and scan prompts ask for a `snippet`: the exact source line a
finding is about. judge::admit, the single admission point for review, scan and
the MCP tools, now checks `line` against it:

- the quote is on `line`: unchanged;
- on exactly one line within 25 lines (or, with no line, the only line of the
  file): the finding moves there;
- nowhere, or equally near two lines: the finding becomes file-level.

Whitespace and a +/- marker are ignored, quotes under 4 characters are not
trusted, findings without a quote behave as before. `snippet` is read from the
model reply and never serialized.
@ajianaz
ajianaz force-pushed the feat/finding-position-validation branch from a85e386 to 78e8b3d Compare November 16, 2026 01:03
@ajianaz
ajianaz merged commit f918159 into develop Nov 16, 2026
16 checks passed
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.

feat(review): deterministic positioning-validation pass — verify every finding's file/line before storing

1 participant