Skip to content

feat(review): each finding group gets a model-written explanation and plan grounded in the rule's documentation at the installed tool version, kept apart from findings, with every quote, citation, version and code block checked #1147

Closed

Description

@dan-petty

Problem

  • The model output has been worthless: 412 model calls and 3.41M prompt tokens per run produced 0/94 strictly valid VERIFIED rows [measured: loop].
  • What the owner asked for instead: the model correlates, investigates and plans; it does not originate findings.
  • Rule documentation exists offline at the installed version. ruff rule --all --output-format json gives 970 rules, 952 with an Example [measured: u-reference]. Pack and Semgrep metadata, and kube-linter checks list, are also available.
  • Gaps an unchecked explanation would leave open [c-fidelity]:
    • free prose can repeat the outdated training-data advice the owner reported;
    • an applied diff is not a correct diff;
    • "related locations" can be a model-originated finding in disguise;
    • doc quotes and version strings can be invented;
    • model prose in findings.sarif would break "identical on every run".

Acceptance criteria

  • Deterministic groups:
    • (path, enclosing symbol) for regions;
    • (manifest, object) for Kubernetes;
    • (lockfile, purl) for advisories.
    • One model job per group.
  • Inputs: anchor regions ± N lines, symbol-graph neighbours, rule docs at the installed version, matching KB manuals (feat(ai): knowledge-base manuals state the tool, language and dependency versions they apply to, and reviews ground explanations in the manuals that match the reviewed project #1149), and environment facts (language floor and pin, tool versions).
    • Each job records the keys it needed, the keys it received and the keys it dropped, with a reason (for example budget).
    • Coverage = received ÷ needed.
    • A test forces a budget overflow and checks that review.md names the dropped rule doc.
  • The output schema:
    • explanation and root cause;
    • related items, each an admitted finding id or a provided neighbour, with a fixed relation (caller, callee, same-symbol, same-rule);
    • plan steps citing finding ids;
    • doc quotes (key + text);
    • an optional suppression note (text only).
    • It has no diff field and no field for state, severity, a finding's location or a new finding (schema test).
  • G10 checks, with failures dropped and counted by reason:
    • finding ids exist;
    • related targets are admitted ids or provided neighbours;
    • code quotes are byte-equal to the commit's lines;
    • doc quotes are byte-equal to the provided reference text, and cited keys were provided;
    • every package or version string exists in the locked inventory, the tools lock or the advisory's fixed versions;
    • every fenced Python block gets no syntax error and no F or UP finding from ruff check --target-version <floor>.
  • From fix(review): the verifier sees masked windows around the cited lines, not the whole file and the linked-file skeletons #1017: every excerpt sent to a model (anchor regions ± N lines) passes through mask_secrets first. A test with a fixture secret in an anchor region shows it masked in the job input.
  • Output location:
    • Output goes to analysis.json and a review.md "Model analysis" section labelled model-written.
    • findings.json and findings.sarif never contain it. A property test shows they are byte-identical with this stage on and off.
  • A suppression note is text only. A person writes any suppression, with its reason and expiry, into .devops/review.toml through a PR.
  • Dispatch goes through the existing pool, capped at the slots table (fix(ai): review calls through the gateway no longer stall for about 190 s on ollama, with the cause measured first #1069). Sampling is recorded (fix(ai): sampling settings reach the model or are refused, review sessions record them, and the reply cache key includes them #1070). The prompt lives in Markdown under src/devops_cli/ai/.
  • (person-run) On the loop input:
    • model calls ≤ groups;
    • a person rates 10 explanations, with 0 statements contradicting the floor or the locks;
    • the rejection rate is recorded.
  • Tests run offline with fakes and recorded tool output: no network, no real scanner, no model; each test under 1 s.
  • changelog.d/<n>.md records the change; CHANGELOG.md and docs/ROADMAP.md are not edited.
  • uv run devops ci passes.

Key questions

  • Why no diffs here? (proposed) An applied diff is not a validated one. P4-1 brings diffs only once tools and tests confirm them, which avoids building a second, partial validator.
  • Can the model ask for more context? (proposed) Not in P1b. Fixed inputs keep prompts reproducible. A recorded, read-only lookup loop is considered once the rejection rate is known.
  • Sampling? (proposed) The model card's values with a fixed seed, recorded.
  • Prompt injection (feat(ai): synthetic prompt adversaries for injection resistance #417)? (proposed) The worst outcome is labelled prose that the checks above bound.

Strategic alignment

Proposed design

Problem statement

The current model-generated review process produces worthless outputs with no validation, leading to a high rate of false positives and unverifiable findings. The system needs to shift from model-generated findings to tool-generated findings with model-written explanations and plans grounded in rule documentation.

Acceptance criteria

  • Criterion 1: Each finding group gets a deterministic model job that correlates, investigates, and plans without originating findings
    Verification: Model jobs are run per group with (path, enclosing symbol), (manifest, object), or (lockfile, purl) deterministically, with one model call per group
  • Criterion 2: Model output schema includes explanation, root cause, related items, plan steps, doc quotes, and suppression notes without diff field
    Verification: Output schema test validates that the generated JSON matches the defined schema with required fields and no diff or finding-related fields
  • Criterion 3: All model outputs are checked for accuracy including code quotes, doc quotes, version strings, and package names
    Verification: G10 checks validate that all code quotes are byte-equal to commit lines, doc quotes match provided references, versions exist in locked inventory, and fenced Python blocks pass syntax check
  • Criterion 4: Model inputs include anchor regions with N lines, symbol graph neighbors, rule docs at installed version, and environment facts
    Verification: Test forces budget overflow and verifies that review.md names dropped rule docs, checking coverage = received ÷ needed
  • Criterion 5: Excerpts sent to model are masked for secrets using mask_secrets function
    Verification: Test with fixture secret in anchor region shows it masked in job input
  • Criterion 6: Output goes to analysis.json and review.md "Model analysis" section, findings.json and findings.sarif never contain model-written explanations
    Verification: Property test shows findings.json and findings.sarif are byte-identical with this stage on and off

Key questions

  • Why no diffs here?: An applied diff is not a validated one. P4-1 brings diffs only once tools and tests confirm them, which avoids building a second, partial validator. [sources: src/devops_cli/ai/review/runner.py]
  • Can the model ask for more context?: Not in P1b. Fixed inputs keep prompts reproducible. A recorded, read-only lookup loop is considered once the rejection rate is known. [sources: src/devops_cli/ai/review/runner.py]
  • Sampling?: The model card's values with a fixed seed, recorded. [sources: src/devops_cli/ai/review/runner.py]
  • Prompt injection (feat(ai): synthetic prompt adversaries for injection resistance #417)?: The worst outcome is labelled prose that the checks above bound. [sources: src/devops_cli/ai/review/runner.py]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#871, #1069, #1019

Activity

  1. added
    type/feature
    scope/ai
    on Oct 3, 2026
  2. added
    scope/review
    priority/p1-high
    on Oct 3, 2026
  3. dan-petty commented on Oct 9, 2026

    @dan-petty
    OwnerAuthor

    Folded in from the #1138 re-scope (2026-10-09)

    The reference-coverage tolerance in ai runs check moves here from #1138 (also listed in #1137's P2 scope): nothing records reference coverage (received ÷ needed per job) until this item does, so #1138 has no metric to check.

  4. added this to the v0.2.36 milestone on Oct 11, 2026
  5. dan-petty commented on Oct 11, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at 6e862cd (see proposed design in issue body).

  6. added
    status/in-progress
    status/in-review
    and removed
    status/in-progress
    on Oct 17, 2026
  7. removed
    status/in-review
    on Oct 17, 2026
  8. added a commit that references this issue on Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p1-highscope/aiscope/reviewtype/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions