feat(review): wider AI lane input, `ai:` switches in config, and the measured lane configuration on by default

RA
4d ago
+2341-106

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 #1773. The first of three PRs that bring the AI lane to the configuration we measured. The next two are feat/review-conventions (repo review instructions) and feat/review-rule-noise (fewer noisy rule comments).

What changed

  • One place for the switches. ai in .altimate/review.yml accepts true/false or an object (enabled plus coverage, contextCard, focused, otherFiles, pythonFiles, verify). resolveAiSwitches picks each switch from its env variable first (1/true/on/yes on, 0/false/off/no off; an empty value counts as unset; any other value is ignored with a stderr warning, once per value per process), then the config, then the default. run.ts resolves them once and passes them down. Code called without switches (direct callers, tests) keeps reading the env variables only, as today. Every key is optional, so the default policy hash does not change. An unknown key under ai: fails the config load, so a typo such as enable: false cannot leave the lane running.
  • Other project files reach the AI lane (otherFiles). Changed other/analysis files inside the project root (.sql, .yml, .yaml) get their own quota of 8. Python files are not among them: they go through pythonFiles only, so pythonFiles: false stops every Python file.
  • Changed Python files reach the AI lane (pythonFiles), inside or outside the project root, with their own quota of 6. Fixes for files outside the project:
    • A file the lane reviewed is no longer listed as "outside the dbt project" in scope.notReviewed. It counts as reviewed only when the call that carried it answered: a lane error or timeout, or a failed call in a partly failed run (ai.failedFiles), keeps it listed. The same rule now applies to other/analysis files inside the project.
    • The verifier sees their added lines, so their findings are not triaged as comments on unchanged code.
    • The stderr "were not reviewed" count leaves them out; a second line says they are offered to the AI lane when it runs and that the result lists any it did not review.
    • Under --all-projects each file is offered to project after project until a lane takes it (the lane reviewed it, or it is in the input of a lane that answered or of a dry run, and no failed call carried it); a project whose lane is off in its policy, has pythonFiles: false, is not in its tier, errored, timed out or had no model passes it on.
    • Their findings on unchanged context lines are marked pre-existing, as for in-project files.
    • A Python file renamed out of the project (scoped in as a deletion at its old path) is offered at its new path by the project it left. Its new path stays listed as "outside the dbt project" until the lane reviews it.
  • Coverage notes. ai.unsent lists only files the deterministic lanes also checked (including other YAML files a rule lane parsed); other/analysis and Python files over their quota that no rule lane read stay in the "Not reviewed" ledger instead.
  • ALTIMATE_REVIEW_AI_SYSTEM_PROMPT_FILE=<file> replaces the finder's system prompt. An empty or unreadable file is an error, never a quiet fallback. It is env only, because a config key would point at a file the PR itself can edit, and the path must be absolute, and neither its realpath nor the path as named (each directory on it resolved) may be inside the reviewed repository (--cwd's git root), the current directory's work tree, or any work tree enclosing them; the refusal names the work tree it found (a home directory kept in git counts as one); it is refused when none resolves to a work tree, so a PR cannot supply the file, or point an in-checkout symlink at one, either (trustedFilePath, shared with the rules-off list in #1838). The default prompt stays the one in altimate-core.
  • Verifier fix. When the verifier stops before giving a verdict, on its budget or on its timeout, the AI findings it never got to now go to the summary instead of inline. Errors are unchanged, and the closed fail mode still discards them. The stop is recorded (unreviewed_stopped) under either fail mode, and a timeout or error outside a batch records a decision per finding, so every outcome can be re-triaged offline.
  • Defaults (a separate commit that can be reverted alone). Coverage quotas, context cards, focused batches, other files, Python files and the AI verifier are on whenever the AI lane runs. Each can be turned off with ai: { <switch>: false } or its env variable set to 0.

How existing users are affected

  • AI lane off (--no-ai, ai: false, no model): no change. A test checks the envelope is identical.
  • AI lane on: more files reach the finder (quotas instead of a 20-file cap). Related files are reviewed together, which means about 3 finder calls per PR instead of 1. Every AI comment is checked by the verifier.
  • Telemetry: review_run.out_of_scope_files no longer counts outside-project Python files the AI lane reviewed; they are counted in the new ai_reviewed_outside_files. Dashboards that trend out_of_scope_files will show a step down (worth a release note).
  • A file of any type renamed out of the dbt project now counts as "outside the dbt project, not reviewed" (in scope.notReviewed, outOfScopeFiles and out_of_scope_files), because this review did not look at its new path. This includes a model moved to another project during a single-project review.
  • Env switches already set to 1 keep working. 0, false, off and no mean off. Before this PR any value other than 1 meant off; now a value that is none of these spellings is ignored with a warning and the config or default applies.
  • Issue #1792 says the AI features are opt-in. With this PR they are on by default whenever the AI lane runs (the lane itself was already on by default with a model configured); the docs now say so and name the opt-outs.

Results

Measured with this stack plus the conventions and rule-noise PRs that follow it, using the defect-focused finder prompt through ALTIMATE_REVIEW_AI_SYSTEM_PROMPT_FILE. AI and rule comments were counted together.

  • On 46 public dbt PRs the combined review raised 526 real bugs, against CodeRabbit's 437. 10% of our comments were wrong, against CodeRabbit's 14%.
  • 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 verifier matters for precision. Without it, the finder with the wider input alone had 6.7% wrong comments, which is why the verifier is on by default here.

Caveats:

  • The default finder prompt stays the core prompt until an altimate-core release ships the defect-focused one. Until then the env override gives the measured prompt.
  • A few default-on rule changes from other branches were part of the measured build, so rule output differs slightly until those land.
  • In the measured build, changed .py files inside the project went to the AI lane as other files, under the quota of 8. They now go as Python files under the quota of 6, so the finder's input differs on 7 of the 46 PRs and 7 of the 90 (on 3 of those PRs one or two .py files are no longer sent, and other files get the room they used). The measured envelopes have no outside-project Python files, so the outside-file fixes do not change the results.

How did you verify your code works?

  • bun test test/altimate/review (packages/opencode): 1038 pass, 0 fail.
  • bun run typecheck (packages/opencode, tsgo --noEmit): clean.
  • New tests cover: switch precedence and the env-only fallback; flags-off identity of the planner input, orchestrator input and envelope; --no-ai envelope identity; quotas, scope and stderr for outside Python files; files kept in the ledger when the lane or their call failed; the next project taking outside Python files when the first project's lane is off; the multi-project merge; unknown ai: keys; prompt override errors; and verifier budget and timeout demotion to the summary, with decisions recorded for re-triage.

Cost side effects

Yes, when the AI lane is on. The lane makes more model calls per PR, and their size grows with the number of changed files, up to fixed limits:

  • Finder: about 3 calls per PR instead of 1, about 62k input and 8k output tokens per PR on average over 46 public dbt PRs. Capped by the per-kind file quotas (models 12, macros 8, tests 4, yml 6, other 8, Python 6) and the existing per-call character budget.
  • AI verifier (now on by default): about 17k input and 2k output tokens per PR on average. Capped by its existing per-PR token, tool-output and round budgets.
  • No warehouse queries or cloud resources.
  • Every part can be turned off with ai: { <switch>: false } or its env variable set to 0. With the AI lane off, nothing changes.

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