feat(review): the dbt PR review stack: trustworthy verdicts, readable comments, AI finder and verifier

RA
8h ago
+38029-666

Issue for this PR

Closes #1792

Type of change

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

What does this PR do?

This is the dbt PR review stack folded into one PR. It carries the 17 stacked PRs below, each already reviewed and approved on its own, so they can land on main as one squash and nothing ships half-way.

PRWhat it adds
#1720An honest PR comment: real lint-only banner, AI lane status, PR intent, project_dir
#1721A readable PR comment: diff-anchored inline comments, no reposts, grouping, size budget, new-only PII
#1722Verdict trust: only the engine blocks, policy read from the base branch, allowForceTier
#1723Failures are never clean: engine errors reported, per-file isolation, PII abstention, gate dismissal
#1724Consumers outside dbt, engine-aware integer division, opt-in contract and column-list checks
#1725Incremental and snapshot semantics
#1726dbt_prepare in the action, data-test adequacy, parse-only column changes
#1739Precision fixes and new rules from a replay of human-caught defects
#1758Posting policy: rule tiers, inline budget, pre-existing tags, coverage ledger
#1769AI verifier
#177011 deterministic rules for macro, test and yml defects
#1771AI input coverage, hunk excerpts, dbt context card
#1772Test-gap check and focused AI batches
#1773--all-projects
#1836Wider AI input, ai: switches in config, the measured configuration on by default
#1837Repo review instructions from the base branch
#1838Fewer wrong rule comments when the AI lane runs

Why a fold. #1721 received 74 more review-fix commits after the PRs above it were based on it, and they conflict with the later PRs in format.ts, orchestrate.ts, post-github.ts, dbt-patterns.ts, review-noise.test.ts and the docs. main takes squash merges only, so merging the stack one by one would repeat those conflicts at every level. The fold resolves them once.

What is new in this PR. Everything else is in the PRs above. Please review these:

  • Conflict resolution (commit a8aececd8d). Both sides are kept:
    • Posting: only this token's own summary and inline comments count, inside the stack's read, render, post order. A partly failed inline post is reported as partial, and earlier blocking reviews are still dismissed.
    • Rendering: the stack's grouping (two or more models, repeats within a file), inline budget and ledger, with #1721's same-severity rule, per-model names, size caps and code-span-safe clipping.
  • One documented exception to "only the engine blocks". #1721 blocks a highly sensitive PII column (an SSN, a card number) that is proven new when the base cannot be compiled. #1722 lets only engine findings block, so after the merge that finding became a comment. It now carries a provenNew mark and verdictEligible accepts it (provenNewPii). No other pattern finding can use the mark. A pattern-only PII finding against a base the engine could read stays a comment, as #1722 intended; eight of #1721's tests are updated for that.
  • postedFindingIds reads the trailing run of finding markers, not only the last one. #1721 trusted only the last marker, which dropped the findings folded into a lead comment (#1837).
  • Portability advice. #1721 keeps advice that has no support list. An engine-gated rule reporting its portability body is now tagged with the project's engine, so integer-division advice is still dropped on a single-engine Snowflake project (#1724).
  • Notes budget. A failed engine check or a failed AI lane is listed before the other notes and its list is capped, so #1721's notes budget cannot cut it from the posted comment (#1723 promises it is named).
  • Tests.
    • review-ai-test-gap and review-ai-verify re-register the core handlers. connections.test.ts calls Dispatcher.reset(), which left the AI lane without its system prompt, so three tests failed whenever the files ran in one process. The stacked PRs' CI did not run the test suite, so this had not shown up.
    • The v0.12.3 ordering test follows the review alias that #1773 introduced.
    • #1721's posting tests use inline-eligible findings under the stack's posting policy.

Known limits, unchanged by the fold.

  • A model whose base the PII check could not analyse is listed as not fully verified and does not block.
  • The default finder prompt is the current core prompt until an @altimateai/altimate-core release ships the defect-focused one; the pin bump is a separate PR.

How did you verify your code works?

  • Typecheck clean. Review tests: 1,326 pass. The whole test/altimate directory: 13,605 pass, 3 fail. The 3 (a shallow-checkout test, a fork-agent registration timeout, a DuckDB daemon test) also fail on the unfolded stack on my machine and are outside the review code.
  • 1,122 stored adversarial PII cases, run on #1721's head and on this branch: the PII findings are identical in every case. The verdict differs in 4 cases, none from PII: 2 were blocked on #1721 by the cross-join pattern rule, which later PRs narrowed and stopped from blocking; 2 go from APPROVE to COMMENT because the stack never approves a model it could not fully verify.
  • DuckDB-executed fuzz of the PII reach analysis, 40,000 generated models: 0 cases where the engine outputs the value and the block is withheld.
  • A dry run (no model calls) of the top of the stack and of this branch on 90 public dbt PRs: same verdict and same findings on 89. On the other, this branch names one more PII column in a finding that was already critical; #1721's own head does the same.
  • The posted comment rendered by both builds from the same 90 results: identical on 58. On 32 the text differs because #1721's size caps now apply; the same number of findings is shown in total and no comment exceeds the budget.

Cost side effects

The AI lane makes model calls that grow with the number of changed files. With this PR the measured configuration is on whenever the AI lane runs: about 3 finder calls per PR in place of 1, plus the verifier.

  • Capped by per-kind file quotas, hunk excerpts and a fixed token budget per verifier batch.
  • Estimated with ALTIMATE_REVIEW_AI_DRYRUN=1, which builds the input and records its size without calling the model.
  • Reported per run in the envelope and in review_run telemetry (tokens, cost, calls).
  • Off with --no-ai or ai: false; each part has its own switch under ai: in .altimate/review.yml.

No warehouse queries or cloud resources are added.

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


Summary by cubic

Rebuilds the dbt PR review so it produces a trustworthy verdict, readable posted comments, and an advisory AI lane. The verdict, posting, and AI-lane changes were developed in a stack of PRs folded into this one; the deterministic rules are tuned against replayed public dbt PRs and a corpus of human-caught defects.

Verdict and posting changes

  • Only deterministic engine findings block; catalog and AI findings are advisory unless the rubric names a catalog rule. One exception: a high-confidence PII column proven new when the base can't be compiled blocks via the provenNewPii mark; no other pattern finding can use it.
  • Each finding carries a stable rule id and a posting tier (inline, summary, off). The verdict counts every repeated finding; presentational merging of same-rule repeats within a file and grouping across models in the summary never softens the gate. Inline budget and silent-when-clean are configurable, policy is read from the base branch so a PR cannot relax it, and findings on pre-existing lines are marked and don't count toward the verdict.
  • Every changed file the review skipped is listed with the reason; undecidable equivalence became a data-diff suggestion; bodies are capped and quoted with the matched line, and some findings post GitHub suggestion blocks. Inline dedup counts only this bot's own comments, so a copied marker can't suppress a finding.
  • New deterministic rules cover project files (packages.yml, dbt_project.yml, Jinja structure, model config), test adequacy, incremental and snapshot semantics, and PII reach. Later rules flag macro signatures that break existing callers (adapter.dispatch keywords no variant accepts, parameters added without defaults), singular-test lookbacks that silently shrank, unbounded BigQuery merges, repeated join predicates, and package-lock.yml commits in package repos. The noisiest rules were narrowed to shapes that are actually risky, the join-key rule reads declared uniqueness tests, portability accounts for a project's own adapter-variant macros and reads a per-engine capability table, and parse-breaking yml or doc() defects are reported wherever the file lives. Rules whose tier depends on the judging sample stay at summary.

AI lane and operating notes

  • The lane is on by default, sees every kind of changed dbt file plus changed Python and other project files, and runs the measured configuration: per-kind coverage quotas, manifest context cards, focused batches, repository conventions read from the base branch, and the verifier. Each piece can be switched off with --no-ai, ai: false, or the ai: object in .altimate/review.yml. The lane is grounded in the same cleaned, deduped findings the posted comment shows.
  • The dbt-grounded verifier refutes AI findings with evidence and reviews deterministic rule findings too; rule types that blind judging found mostly wrong are dropped before posting when the lane answers. Findings left unreviewed on budget or timeout go to the summary; verifier decisions are recorded for offline re-triage, and ALTIMATE_REVIEW_AI_DRYRUN=1 plus an envelope replay make no model calls.
  • Credential files are refused by path and content, across renames and symlinks, for the AI lane and the verifier; PII exposure counts as pre-existing only when the base's final projection exposed the same source column raw.
  • --all-projects reviews every dbt project a PR touches and merges the verdicts into one envelope, resolving policy along each project's own ancestors.
  • Cost side effects: about 3 finder calls per PR plus the verifier, capped by quotas and token budgets; telemetry reports tokens, cost, and calls.

Summary by CodeRabbit

  • New Features
    • Added multi-project dbt reviews, optional artifact preparation, and improved support for shallow CI checkouts.
    • Expanded configurable AI review and verification, including Python and other-file coverage, repository conventions, and replay of saved reviews.
    • Added dbt checks for incremental and snapshot changes, tests, project configuration, consumer and contract columns, and adapter-specific SQL behavior.
    • Added configurable finding policies and tiers, with richer review coverage, verification details, summaries, and inline comments.
  • Bug Fixes
    • Improved reporting for out-of-scope files, incomplete analysis, and findings that cannot be verified.
    • Reduced duplicate findings and improved handling of existing comments, clean runs, and completed reviews.
  • Documentation
    • Expanded setup guidance, configuration examples, review policies, and telemetry details.