Skip to content

feat(review): fewer wrong rule comments when the AI lane runs: rule types off, rule verifier, rule-post policy - #1838

Open
RaghwendraSingh wants to merge 32 commits into
feat/review-conventionsfrom
feat/review-rule-noise
Open

RaghwendraSingh wants to merge 32 commits into
feat/review-conventionsfrom
feat/review-rule-noise

Conversation

@RaghwendraSingh

@RaghwendraSingh RaghwendraSingh commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Part of #1792

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Stacked on feat/review-conventions. The last of three PRs. Once the AI lane got good, most of our wrong comments came from deterministic rule findings: on 46 public dbt PRs, 23% of rule comments were wrong against 4.3% of AI comments. This PR filters rule findings in three steps. All three run only when the AI lane ran and answered: with no model, a dry run, a provider error or a timeout every rule finding is posted as before.

What changed

  1. Rule types off. NOISY_RULES_OFF in rules-off.ts lists 36 rule types that were almost never real defects on public dbt PRs that the AI lane also reviewed. Their findings are not posted on files the AI lane reviewed (sent in a call that answered); on any other file they are posted. On those other files they go to the rule verifier like any other rule finding, and so does one on a sent file whose finder call failed.

    • It applies after the AI lane, so the finder's grounding is unchanged.
    • Critical findings of these types are still posted. classify-pii:exposes is on the list for its warnings; a new high-confidence PII column in a mart is critical and still posts and blocks.
    • ai.rulesOff: false or ALTIMATE_REVIEW_RULES_OFF=0 (off, false) keeps all 36 types.
    • ai.rulesOn: [ids] keeps single types. Rule ids match in either spelling (dbt_patterns:self_join or dbt-patterns:self-join).
    • ALTIMATE_REVIEW_RULES_OFF=<path> replaces the list with a JSON list of rule ids. Only a value that looks like a path is read as a file; it must be absolute and outside the reviewed repository and the current directory's work tree, refused when neither resolves (a PR could otherwise choose the list), and a missing or malformed file stops the review. yes/no work like for every other switch.
    • Drop counts are keyed by the normalized rule id.
  2. Rule verifier. After the finder and the AI verifier, the rule findings that would be posted go through the same dbt-grounded verifier, in a mode that records a verdict per finding and does no triage. Refuted rule findings are not posted.

    • It runs only when the finder lane answered (state: ok), and is on when the AI lane and the verifier are on; ai.verify: false turns it off too. A skipped run reports every rule finding as kept and unreviewed.
    • It verifies at most 40 rule findings per reviewed project (--all-projects runs it per project), warnings first and, within a severity, the policy's noisy types (ai.rulePolicy.noisyRules when set) (ALTIMATE_REVIEW_AI_VERIFY_RULES_MAX_FINDINGS); the rest get no verdict and are posted. An answer without a valid verdict counts as no verdict; a refutation without evidence counts as unverifiable. Critical rule findings and findings on credential-like paths are not sent.
    • ai.verifyRules: false or ALTIMATE_REVIEW_AI_VERIFY_RULES=off turns it off.
  3. Rule-post policy. rule-post-policy.ts holds the pure function dropByRulePolicy(findings, verdictById, policy). After steps 1 and 2, a rule finding is not posted if either holds:

    • its verdict is unverifiable and its severity is warning;
    • its type is one of 7 noisy types (NOISY_RULE_TYPES) and its verdict is not confirmed.

    Details:

    • A finding with no verdict (its batch failed, the answer omitted it, or it was over the ceiling) was not judged and is posted. On the default budget most rule batches are forced to answer at the budget without tools; those verdicts count (the policy was tuned on them). A verdict from a batch that timed out counts as no verdict.
    • It fails open: if the rule verifier did not run at all (skipped, failed, or stopped on budget with nothing reviewed), the policy is skipped and rule findings are posted as before.
    • ai.rulePolicy: false or ALTIMATE_REVIEW_RULE_POLICY=0 turns it off. ai.rulePolicy: { noisyRules: [...] } replaces the list.

AI findings are never dropped by any of the three steps, nor is a repeat-merged comment that includes an AI finding. Critical rule findings are never dropped by any of the three steps: they are posted and block as before. The three steps filter posting only: the verdict and the summary tally still count every rule finding, so a withheld engine warning keeps its blocking weight and neither the verifier nor author text it reads (the PR description) can unblock a gate. When withheld findings change the verdict, the summary lists them (file:line, title, why; the first 10) and the envelope records them as withheld: the engine warnings that count toward a REQUEST_CHANGES the posted findings alone would not reach, or every withheld finding when they alone keep the verdict from APPROVE. When the finder lane fails or times out, none of the three steps applies. The PR comment gives the number of rule findings not posted per step, counted per instance like the verdict, and review_run telemetry carries the rule verifier's state, tokens and cost plus the drop counts. With the AI lane off nothing changes; tests check the envelope is identical.

Envelope:

  • rulesOff: {rule: count}
  • rulesRefuted
  • rulePolicy: {applied, dropped: {unverifiable_high_sev, noisy_type_not_confirmed}}
  • withheld[] (only when withheld findings change the verdict): those findings, with the reason
  • ai.verifyRules and ai.ruleVerifier (state and spend)
  • ai.verifier.ruleVerdicts[] and ai.verifier.batches[]

All are summed across projects under --all-projects (withheld is the projects' lists merged, and the merged summary counts each project's withheld instances); rule verdicts' batch indexes are offset per project, ai.verifyRules is set when any project verified, and ai.ruleVerifier.model is kept.

Critical rule findings are exempt. Rules-off, the refuted filter and the rule-post policy all skip critical rule findings, so no step stops a critical rule finding from being posted or from blocking. They are not sent to the rule verifier. The docs say so next to "only the engine can block".

Results

  • On 46 public dbt PRs the full configuration from the three PRs raised 526 real bugs, against CodeRabbit's 437, with 10% wrong comments against 14%. The earlier configuration (wider input and the AI verifier, no conventions, no rule-noise work) had 37.5% wrong comments.
  • On 90 fresh public dbt PRs, counting distinct real bugs on the PRs each bot also reviewed:
    • us 125, CodeRabbit 93
    • us 227, Copilot 76
    • us 189, Cursor Bugbot 56
  • The rule-post policy was chosen on the 46 PRs, frozen, then applied once to the 90 fresh PRs. With critical rule findings exempt, it brought our wrong share there from 14.6% to 10.6% (the PRs CodeRabbit reviewed), from 15.3% to 11.5% (Copilot) and from 12.0% to 6.7% (Cursor Bugbot), each under that bot's own wrong share plus 3 points.

Caveats:

  • The measured build dropped rule findings with no verdict as unverifiable, acted on verdicts from timed-out batches, applied rule types off on every file (and skipped verifying them everywhere), verified every rule finding (critical ones included) and ran the rule verifier after a failed finder. These fail-open changes can only keep more rule findings than were measured; how many is not known without a rerun. The measured build also removed withheld findings from the verdict; now they still count, so verdicts can be stricter than measured (comment quality is unaffected).
  • A few default-on rule changes from other branches were in the measured build, so rule output differs slightly until those land.
  • The measured build dropped classify-pii:exposes findings of every severity. On the 46 PRs every such finding was a warning, so exempting critical ones changes nothing there. On the 90 fresh PRs rules-off dropped 16 of them on 7 PRs; the envelopes keep only the count, so whether any was critical (and would now be posted) is not known without a rerun.

How did you verify your code works?

  • bun test test/altimate/review (packages/opencode): 1167 pass, 0 fail.
  • bun run typecheck (packages/opencode, tsgo --noEmit): clean.
  • New tests:
    • review-rules-off.test.ts: list shape; resolver (default, config, rulesOn in either spelling, env spellings and file, bad files); critical findings kept; orchestrator drop and counts with the finder's input unchanged; a skipped, failed or timed-out lane leaves the list unapplied; a merged AI+rule comment survives; AI lane off unchanged.
    • review-ai-verify-rules.test.ts: switch spellings; rule-mode verdicts, batching and failure; skipped cases; call order finder → AI verifier → rule verifier; refuted findings dropped with the lane input otherwise unchanged; rule types off left out before verification.
    • review-rule-post-policy.test.ts: both conditions and severities; critical findings kept by the policy and the refuted filter; missing verdicts; AI findings never dropped; custom list; the fail-open states; config and env; orchestrator drops and envelope counts; switches off and AI lane off unchanged.

Cost side effects

Yes, one new model run per PR when the AI lane and the verifier are on: the rule verifier.

  • Its size grows with the number of rule findings the PR would post, in batches of 8.
  • It averaged about 11k input and 1k output tokens per PR on 46 public dbt PRs.
  • It is a second verifier run with its own token, tool-output and round budget (not shared with the AI verifier); its calls are bounded by the ceiling of 40 rule findings per reviewed project (at most 5 batches). Findings over the ceiling are posted unverified; warnings and the policy's noisy types are verified first.
  • It makes no call when there are no rule findings.
  • ai.verifyRules: false or ALTIMATE_REVIEW_AI_VERIFY_RULES=off turns it off.
  • Rule types off and the rule-post policy add no calls.
  • No warehouse queries or cloud resources.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR
  • I checked for cost side effects (model calls, queries or cloud resources that grow with user data) and described them, or wrote "none"

🤖 Generated with Claude Code

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants