Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
0c4e2c6
fix(review): a readable PR comment: diff-anchored inline comments, no…
RaghwendraSingh Nov 12, 2026
147c38d
fix(review): portability advice is an explicit tag, kept when it fail…
RaghwendraSingh Nov 13, 2026
cfb0aa4
fix(review): address review comments: PII without a compiled base, sa…
RaghwendraSingh Nov 20, 2026
6143055
fix(review): grouping keeps distinct messages, base-exposed PII stays…
RaghwendraSingh Nov 23, 2026
aca1e85
fix(review): reconcile both regex PII twins with the base, keep inlin…
RaghwendraSingh Nov 23, 2026
932cf6f
fix(review): reconcile PII twins by output alias and every token, kee…
RaghwendraSingh Nov 23, 2026
3f7ae53
fix(review): count a PII column as base-exposed only when the base ex…
RaghwendraSingh Nov 24, 2026
18613b9
fix(review): ignore string-literal contents when collecting PII selec…
RaghwendraSingh Nov 24, 2026
56a227e
fix(review): count a base PII output as exposing a column only when i…
RaghwendraSingh Nov 24, 2026
29778be
fix(review): read base PII exposures from the final projection, acros…
RaghwendraSingh Nov 25, 2026
4e25546
fix(review): suppress a broad-fallback PII column only when the base …
RaghwendraSingh Nov 25, 2026
bc71523
fix(review): exempt a PII line as a reindent only when its select ite…
RaghwendraSingh Nov 25, 2026
1765b8d
fix(review): dedup inline findings only against this bot's own review…
RaghwendraSingh Nov 25, 2026
1b4ffd1
fix(review): keep PIVOT and string-interval advice on engines that la…
RaghwendraSingh Nov 25, 2026
2aa4fd1
fix(review): stop the summary at the first finding that does not fit,…
RaghwendraSingh Nov 25, 2026
18eb89d
test(review): cover deleted and patchless renamed files for inline an…
RaghwendraSingh Nov 25, 2026
f25ae0a
fix(review): resolve PII exposure by source table, qualifier, subquer…
RaghwendraSingh Nov 25, 2026
55f1f91
fix(review): stop flagging the ANSI `interval '30' day` as a string i…
RaghwendraSingh Nov 25, 2026
075fcee
fix(review): clip summary bullet bodies so a long finding cannot hide…
RaghwendraSingh Nov 25, 2026
d272b58
fix(review): report PII outputs the parser cannot resolve instead of …
RaghwendraSingh Nov 25, 2026
619331a
fix(review): give the root query a scope no CTE can share, so a CTE n…
RaghwendraSingh Nov 27, 2026
81259a4
fix(review): judge a computed head output by the source columns it re…
RaghwendraSingh Nov 27, 2026
fa570f8
fix(review): credit columns a base `select *` passed through, and mat…
RaghwendraSingh Nov 27, 2026
12aea2d
fix(review): parse `select distinct on (…)` as a prefix, not part of …
RaghwendraSingh Nov 27, 2026
2ad0660
fix(review): key a nested query by its alias, else number it within i…
RaghwendraSingh Nov 27, 2026
2e674a7
fix(review): keep database and schema in a source table's identity
RaghwendraSingh Nov 27, 2026
44c7ee0
fix(review): read a regex twin's alias like the select-list parser, a…
RaghwendraSingh Nov 27, 2026
6f1682b
fix(review): keep local diagnostics whole, trust only the trailing fi…
RaghwendraSingh Nov 27, 2026
5d80f3d
fix(review): show each member's own values in a grouped bullet, and g…
RaghwendraSingh Nov 27, 2026
bfb900c
fix(review): report a partial inline post, record a failed retry, and…
RaghwendraSingh Nov 27, 2026
f804832
test(review): make the PII classifier stub column-specific, and drive…
RaghwendraSingh Nov 27, 2026
db76ec1
fix(review): drop FETCH FIRST portability advice on DuckDB
RaghwendraSingh Nov 27, 2026
c9e33bd
fix(review): resolve raw and computed refs in one memoised walk, with…
RaghwendraSingh Nov 27, 2026
e7ac0a6
fix(review): keep `starRaw` off the per-scope output type
RaghwendraSingh Nov 27, 2026
fa21744
fix(review): cover a combined join ref by a single-table base ref, ne…
RaghwendraSingh Nov 27, 2026
dd9f9ff
fix(review): never reuse a numbered nested-scope key
RaghwendraSingh Nov 27, 2026
1d91982
fix(review): never treat a computed output as reading nothing unless …
RaghwendraSingh Nov 27, 2026
366abe9
fix(review): say which inline comments a partial post dropped
RaghwendraSingh Nov 27, 2026
0d575b3
fix(review): compare a table's database/schema only when both sides w…
RaghwendraSingh Nov 27, 2026
3692322
fix(review): compare two combined join refs member by member
RaghwendraSingh Nov 27, 2026
e34e5ef
fix(review): treat a move to a schema the base already read as a diff…
RaghwendraSingh Nov 27, 2026
7c13b48
fix(review): read `null` items as constants and keep `within group (……
RaghwendraSingh Nov 27, 2026
c6c73c0
fix(review): resolve a base `*` over a join to each source on its own
RaghwendraSingh Nov 27, 2026
bb81d27
fix(review): find `within group (…)` across any run of whitespace
RaghwendraSingh Nov 27, 2026
b3d64e2
fix(review): read typed literals as constants
RaghwendraSingh Nov 27, 2026
0aca7d9
fix(review): keep whole entries in a grouped bullet's per-model detail
RaghwendraSingh Nov 27, 2026
36159a8
fix(review): drop the unused head side of `RelationPrefixes`
RaghwendraSingh Nov 27, 2026
8e859b0
fix(review): drop a no-op `detectPii` override in a reindent test
RaghwendraSingh Nov 27, 2026
374b92e
fix(review): say grouped findings share a severity in the PR review docs
RaghwendraSingh Nov 27, 2026
3382f41
fix(review): memoise `starRefs`
RaghwendraSingh Nov 27, 2026
1552676
fix(review): read an unquoted `interval 1 day` as a constant
RaghwendraSingh Nov 27, 2026
219f3e8
fix(review): judge a base-exposed PII output by its source columns
RaghwendraSingh Nov 27, 2026
eb54e51
fix(review): keep string-literal case in output signatures
RaghwendraSingh Nov 27, 2026
e0e3ba0
fix(review): keep a regex PII twin's severity when the raw base canno…
RaghwendraSingh Nov 27, 2026
0212e2e
fix(review): update only a summary comment this token's account posted
RaghwendraSingh Nov 27, 2026
139da8a
fix(review): clip a budgeted bullet's title so the first critical alw…
RaghwendraSingh Nov 27, 2026
b637b11
fix(review): retry a transient `/user` failure instead of guessing th…
RaghwendraSingh Nov 27, 2026
48f53c8
fix(review): compare output signatures by source, not table alias
RaghwendraSingh Nov 27, 2026
9f5954a
fix(review): drop the `rawColumnExposures` wrapper
RaghwendraSingh Nov 27, 2026
668d076
fix(review): test a qualified `c.ssn` without a compiled base and a s…
RaghwendraSingh Nov 27, 2026
b6e15e5
fix(review): keep a proven-new regex PII twin past the undecided PII …
RaghwendraSingh Nov 27, 2026
67a9bb1
fix(review): tighten the raw-base proof for Jinja tags, comments and …
RaghwendraSingh Nov 27, 2026
3f6665b
fix(review): keep string-literal spacing in output signatures
RaghwendraSingh Nov 27, 2026
fdf1480
fix(review): skip a summary marker this token cannot edit, and read `…
RaghwendraSingh Nov 27, 2026
e8e509e
fix(review): cap a grouped bullet's model list, body and detail together
RaghwendraSingh Nov 27, 2026
cd547e6
fix(review): decide the posting account before adopting a summary com…
RaghwendraSingh Nov 27, 2026
a5f79d7
fix(review): leave more raw bases undecided in the PII proof
RaghwendraSingh Nov 27, 2026
17d9001
fix(review): never cut a grouped bullet's shortened body inside a cod…
RaghwendraSingh Nov 27, 2026
8f2e301
fix(review): accept a raw PII column selected in a CTE or subquery as…
RaghwendraSingh Nov 27, 2026
a0a3310
docs(review): say what an App token inside Actions does without `ALTI…
RaghwendraSingh Nov 27, 2026
05795d4
fix(review): never split or half-close a multi-backtick code span whe…
RaghwendraSingh Nov 27, 2026
f992c07
fix(review): list the shorter model names after one longer than the l…
RaghwendraSingh Nov 27, 2026
f4d5ce6
fix(review): withhold the raw-base PII proof only on evidence the col…
RaghwendraSingh Nov 27, 2026
601f1a7
docs(review): say when PII blocks without a compiled base, and what a…
RaghwendraSingh Nov 27, 2026
79308b8
fix(review): count every shape the PII reach analysis does not model …
RaghwendraSingh Nov 27, 2026
c7a3d3d
fix(review): follow a PII column only through SQL recognised as plain…
RaghwendraSingh Nov 27, 2026
5533949
fix(review): treat SQL that Jinja or the warehouse may lex differentl…
RaghwendraSingh Nov 27, 2026
7548ddf
docs(review): PII in SQL the review cannot follow blocks without a co…
RaghwendraSingh Nov 27, 2026
72f9abc
fix(review): block a proven-new PII column that reaches the output fr…
RaghwendraSingh Nov 28, 2026
d8895dc
fix(review): read `with offset` across any comment, and a typed liter…
RaghwendraSingh Nov 29, 2026
2cf3250
fix(review): a reindent does not hide a changed source, and a `USING`…
RaghwendraSingh Dec 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions docs/docs/usage/dbt-pr-review.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,18 @@ dropped on the next run. `--post` targets **GitHub** PRs (it reads `GITHUB_TOKEN
run with `--json`/`--output` and post the verdict using that platform's own API —
native GitLab posting is not yet built in.

The summary comment is updated in place only if the token's own account posted it.
For a personal access token, the account is the `/user` login. For Actions' own
`GITHUB_TOKEN`, it is `github-actions[bot]`. A GitHub App installation token cannot
read `/user`, so set `ALTIMATE_REVIEW_BOT_LOGIN` to the app's bot login (for example
`my-app[bot]`). Without it, outside Actions, each run posts a new summary comment
rather than risk editing another bot's comment. Inside Actions, an App token without
the variable is treated as `github-actions[bot]`: it never finds the summary it
posted earlier and adds a new one on every run, and if the PR already has a
`github-actions[bot]` summary it updates that one and no longer recognises its own
inline comments, so they are posted again. Set `ALTIMATE_REVIEW_BOT_LOGIN` whenever
the review posts with an App token.

## Configuration — `.altimate/review.yml`

Per-repo configuration, the analogue of an `AGENTS.md`. Tune the rubric, choose
Expand All @@ -264,6 +276,9 @@ mode: comment # comment | gate
severityThreshold: suggestion
manifestPath: target/manifest.json
dialect: snowflake
# portability: true # cross-engine advice. Unset: off once the engine is known
# (configured or detected). An explicit value applies even when
# the engine is unknown. Set true for multi-adapter packages.
reviewers: [] # empty = risk-tier defaults; or pin lanes
dataDiff: # OFF by default — see "Data-diff in CI" below
enabled: false
Expand All @@ -283,6 +298,39 @@ rubric:
skipNonProdModels: true
```

### What the PR comment shows

- **One summary comment**, updated in place on every push, capped at about
5,000 characters. Critical findings come first; anything that does not fit is
counted, and the full list is always in the job log and the verdict envelope
(`altimate review --json --output <file>`). Local CLI output is never truncated.
- **Repeated findings are grouped:** the same rule and message (ignoring model
and column names) at the same severity on three or more models is one bullet
listing the models, with each model's own names when they differ. Local CLI output lists every
finding with its location.
- **Inline comments only on lines of the PR's diff.** Findings computed on
compiled SQL, or on unchanged lines, stay in the summary.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: commentableLines deliberately includes unchanged context lines inside diff hunks, so this sentence incorrectly promises those findings remain in the summary. Say “outside the PR’s diff hunks” instead.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At docs/docs/usage/dbt-pr-review.md, line 312:

<comment>`commentableLines` deliberately includes unchanged context lines inside diff hunks, so this sentence incorrectly promises those findings remain in the summary. Say “outside the PR’s diff hunks” instead.</comment>

<file context>
@@ -283,6 +298,39 @@ rubric:
+  listing the models, with each model's own names when they differ. Local CLI output lists every
+  finding with its location.
+- **Inline comments only on lines of the PR's diff.** Findings computed on
+  compiled SQL, or on unchanged lines, stay in the summary.
+- **No re-posting on reruns:** each inline comment carries the finding's
+  fingerprint, so a push does not repeat findings already on the PR, and a
</file context>
Suggested change
compiled SQL, or on unchanged lines, stay in the summary.
compiled SQL, or on lines outside the PR's diff hunks, stay in the summary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this PR a finding on an unchanged context line inside a hunk can get an inline comment. A later PR in this stack marks such findings pre-existing and keeps them out of the inline set, which makes the sentence true.

- **No re-posting on reruns:** each inline comment carries the finding's
fingerprint, so a push does not repeat findings already on the PR, and a
non-blocking rerun with nothing new and the same headline as the bot's last
review only updates the summary.
- **PII:** flagged only for PII columns the change newly exposes, not for
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
columns the base already surfaced. That comparison needs the base version's
SQL; when it can't be compiled, PII columns are reported as non-blocking
warnings that may predate the PR. One case still blocks without a compiled
base: the diff adds a highly sensitive column (an SSN, a passport or card
number, a date of birth) to a `marts/` or `reporting/` model, the base file's
own SQL cannot expose it (it does not name the column, select `*`, or call a
macro), and the column reaches the model's output unmasked, directly or
through CTEs and subqueries, from the added line or from anywhere else in the
model. A column that is hashed, masked or dropped everywhere it is read

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[WARNING]: hashed, masked or dropped everywhere it is read stays a warning does not hold when the hash keeps the column's own name

A model ending in final as (select customer_id, sha2(ssn) as ssn from src) plus select customer_id, ssn from final is still critical, while the same model ending in select * from final is not (test/altimate/review.test.ts:3315-3319 vs :3348-3352; the test comment at :3314 calls it a limit of reading names). The raw ssn is read only inside sha2, so by this bullet it should stay a warning. The bullet needs the caveat: a hash is followed only when the reader goes through * or keeps an output the reach analysis can trace, not when the masked value is later selected by the column's own name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed: a CTE's sha2(ssn) as ssn selected by name is read as raw, so that sentence overstates. The follow-up corrects the docs line; following the masking through the CTE is tracked with it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Qualify this warning: when a masked value is later selected by its original column name, the reach analysis can still classify the finding as critical.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At docs/docs/usage/dbt-pr-review.md, line 326:

<comment>Qualify this warning: when a masked value is later selected by its original column name, the reach analysis can still classify the finding as critical.</comment>

<file context>
@@ -283,6 +298,39 @@ rubric:
+  own SQL cannot expose it (it does not name the column, select `*`, or call a
+  macro), and the column reaches the model's output unmasked, directly or
+  through CTEs and subqueries, from the added line or from anywhere else in the
+  model. A column that is hashed, masked or dropped everywhere it is read
+  (`sha2(ssn)`, `right(ssn, 4)`, `* exclude (ssn)`) stays a warning; one that
+  only passes through a value-preserving expression (`coalesce(ssn, '')`,
</file context>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the docs comment above on a hashed column that keeps its name. The follow-up corrects that line.

(`sha2(ssn)`, `right(ssn, 4)`, `* exclude (ssn)`) stays a warning; one that
only passes through a value-preserving expression (`coalesce(ssn, '')`,
`max(ssn)`) still blocks. So does one the review cannot rule out: in SQL it
cannot follow (Jinja that builds the select list, lateral or scalar
subqueries, unusual syntax), or in a model whose output also takes a `*` or a
Jinja column list over a table, whose columns the SQL does not show.

### Risk-tier path tokens

Named categories under `riskTierPathTokens` promote any diff touching a matching
Expand Down
8 changes: 8 additions & 0 deletions packages/opencode/src/altimate/review/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ export const ReviewConfig = z.object({
dialect: z.string().default(""),
/** Enable the advisory LLM reviewer lane (needs a configured model). */
ai: z.boolean().default(true),
/**
* Report cross-engine portability advice ("isn't portable across
* warehouses"). Off by default once the engine is known (from the manifest's
* adapter or `dialect`), because a project that runs on one engine gains
* nothing from it. Turn on for packages that support several adapters.
* Functions missing on the project's own engine are always reported.
*/
portability: z.boolean().optional(),
/**
* Data-diff: actually run base-vs-head against the warehouse (core DataParity)
* and report row/value deltas. OPT-IN — it costs warehouse compute and needs a
Expand Down
62 changes: 28 additions & 34 deletions packages/opencode/src/altimate/review/dbt-patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Log } from "@/altimate/util/log"
import { type Finding, type Severity, type ReviewCategory, makeFinding } from "./finding"
import { type ChangedFile, fileKind } from "./diff-filter"
import { type Rubric, clampSeverity, exclusionReason } from "./rubric"
import { evaluateCatalog } from "./rule-catalog"
import { evaluateCatalog, selectItemColumns, stripLiterals } from "./rule-catalog"

/** Local copy to avoid a cycle with orchestrate.ts. */
function modelNameFromPath(p: string): string {
Expand Down Expand Up @@ -53,17 +53,6 @@ function stripComments(s: string): string {
.replace(/\{#[\s\S]*?#\}/g, " ")
}

/**
* Blank out single-quoted SQL string-literal CONTENTS (keeping the quotes) so a
* regex detector can't be tripped by punctuation inside a literal — e.g. the
* `/` in `'n/a'` must not read as division, a `,` in `'a,b'` must not read as a
* comma join. Detectors that legitimately inspect literal content (leading
* wildcard, hardcoded date) must NOT use this. Handles doubled-quote escapes.
*/
function stripLiterals(s: string): string {
return s.replace(/'(?:[^']|'')*'/g, "''")
}

/**
* True when a line's FROM clause lists two relations separated by a comma at
* paren-depth 0 — i.e. `FROM a, b` (an implicit cross join). Scans only after
Expand Down Expand Up @@ -109,7 +98,7 @@ interface Ctx {
inMartOrReporting: boolean
}

type Detector = (c: Ctx) => Finding | null
type Detector = (c: Ctx) => Finding | Finding[] | null

// A line that is dbt Jinja / config rather than SQL — e.g. the microbatch
// `begin=(modules.datetime.datetime.now() - ...)` config kwarg, which is NOT a
Expand Down Expand Up @@ -304,7 +293,7 @@ const PII_RE =
/\b(email|ssn|social_security|phone_number|first_name|last_name|full_name|street_address|date_of_birth|dob|passport|credit_card)\b/i
const detectPiiIntoMart: Detector = (c) => {
if (!c.inMartOrReporting) return null
const hit = c.added.find((l) => {
const hits = c.added.filter((l) => {
const s = stripComments(l)
return (
PII_RE.test(s) &&
Expand All @@ -313,24 +302,29 @@ const detectPiiIntoMart: Detector = (c) => {
)
)
})
if (!hit) return null
// Highly-sensitive identifiers (SSN/financial/passport/DOB) into a broadly-read
// marts layer are critical; softer PII (email/phone/name) is a warning.
const sev: Severity = /\b(ssn|social_security|credit_card|passport|date_of_birth|dob)\b/i.test(hit)
? "critical"
: "warning"
return makeFinding({
severity: sev,
category: "pii_exposure",
title: `${c.model}: PII column added to a marts/reporting model`,
body:
"A PII-named column was added to a model in `marts/`/`reporting/`, widening PII exposure into a broadly-read " +
"layer. Confirm the column is needed here, that masking/access policy applies, and that the downstream grant is appropriate.",
file: c.file.path,
model: c.model,
confidence: "high",
evidence: { tool: "dbt-patterns", result: { rule: "pii_into_mart", line: hit.trim() } },
ruleKey: "pii_exposure:into-mart",
// One finding per PII column token on each added line (`ssn, passport` is two):
// each carries its column, `AS` alias and line in `result` so the orchestrator
// can suppress a base-exposed column without hiding a new one beside it. They
// share a fingerprint, so dedupe keeps the most severe survivor.
return hits.flatMap((hit) => selectItemColumns(hit, PII_RE)).map(({ column, alias, line }) => {
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
// Highly-sensitive identifiers (SSN/financial/passport/DOB) into a broadly-read
// marts layer are critical; softer PII (email/phone/name) is a warning.
const sev: Severity = /^(ssn|social_security|credit_card|passport|date_of_birth|dob)$/i.test(column)
? "critical"
: "warning"
return makeFinding({
severity: sev,
category: "pii_exposure",
title: `${c.model}: PII column added to a marts/reporting model`,
body:
"A PII-named column was added to a model in `marts/`/`reporting/`, widening PII exposure into a broadly-read " +
"layer. Confirm the column is needed here, that masking/access policy applies, and that the downstream grant is appropriate.",
file: c.file.path,
model: c.model,
confidence: "high",
evidence: { tool: "dbt-patterns", result: { rule: "pii_into_mart", line, column, alias } },
ruleKey: "pii_exposure:into-mart",
})
})
}

Expand Down Expand Up @@ -780,8 +774,8 @@ export function detectModelPatterns(file: ChangedFile, newSql: string | undefine
}
const out: Finding[] = []
for (const d of MODEL_DETECTORS) {
const f = d(ctx)
if (f) out.push({ ...f, severity: clampSeverity(f.category, f.severity, f.confidence) })
for (const f of [d(ctx) ?? []].flat())
out.push({ ...f, severity: clampSeverity(f.category, f.severity, f.confidence) })
}
// Declarative rule catalog (data-driven checks) complements the programmatic detectors.
out.push(...evaluateCatalog(file, newSql, added, removed, rubric))
Expand Down
Loading
Loading