Repository navigation
fix(review): failures are never clean: engine errors reported, per-file isolation, PII abstention, gate dismissal #1723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: fix/review-verdict-trust
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -206,13 +206,19 @@ export function coverageNotes(env: VerdictEnvelope): string[] { | |||||||||||||||||
| const undecided = env.findings.filter((f) => f.degraded).length | ||||||||||||||||||
| if (undecided) notes.push(`${undecided} finding(s) could not be decided by the engine and are marked _unverified_.`) | ||||||||||||||||||
| const unverified = env.scope?.unverified ?? [] | ||||||||||||||||||
| if (unverified.length) { | ||||||||||||||||||
| const head = unverified.slice(0, 5).map((u) => `\`${u.path}\``).join(", ") | ||||||||||||||||||
| const more = unverified.length > 5 ? ` and ${unverified.length - 5} more` : "" | ||||||||||||||||||
| notes.push( | ||||||||||||||||||
| `${unverified.length} model(s) not verified by the engine — ${unverified[0].reason}: ${head}${more}. ` + | ||||||||||||||||||
| "Run `dbt compile` (and compile the base into `target-base/`) for equivalence and lineage checks.", | ||||||||||||||||||
| ) | ||||||||||||||||||
| const byReason = new Map<string, string[]>() | ||||||||||||||||||
| for (const u of unverified) byReason.set(u.reason, [...(byReason.get(u.reason) ?? []), u.path]) | ||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: Grouping by the full reason text fragments per-file error messages into one note each, so a widespread failure produces many notes. Group by a normalized reason category, or cap the number of distinct notes, so the comment stays compact. Prompt for AI agents
Comment on lines
+209
to
+210
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [🟠 MEDIUM] Using the array spread operator within a loop to accumulate items creates a new array on each iteration. This can lead to O(N²) time complexity and unnecessary memory allocations when there are many items. It is more efficient to mutate the existing array by pushing new elements. Suggested change:
Suggested change
|
||||||||||||||||||
| for (const [reason, paths] of byReason) { | ||||||||||||||||||
| const head = paths.slice(0, 5).map((p) => `\`${p}\``).join(", ") | ||||||||||||||||||
| const more = paths.length > 5 ? ` and ${paths.length - 5} more` : "" | ||||||||||||||||||
| const hint = /compiled SQL/.test(reason) | ||||||||||||||||||
| ? " Run `dbt compile` (and compile the base into `target-base/`) for equivalence and lineage checks." | ||||||||||||||||||
| : "" | ||||||||||||||||||
| notes.push(`${paths.length} model(s) not fully verified — ${reason}: ${head}${more}.${hint}`) | ||||||||||||||||||
| } | ||||||||||||||||||
| if (env.engineErrors?.length) { | ||||||||||||||||||
| const list = env.engineErrors.map((e) => `${e.method} ×${e.count} (${e.reason})`).join("; ") | ||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: Prompt for AI agents |
||||||||||||||||||
| notes.push(`Some engine checks failed and did not run: ${list}. This verdict is not a clean approval.`) | ||||||||||||||||||
| } | ||||||||||||||||||
| if (env.scope?.outOfScopeFiles) | ||||||||||||||||||
| notes.push(`${env.scope.outOfScopeFiles} changed file(s) outside the dbt project were not reviewed.`) | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -191,6 +191,33 @@ async function mergeBase(a: string, b: string, cwd: string): Promise<string | un | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * A default CI checkout is shallow (`actions/checkout` fetches one commit) and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * lacks the target branch. Fetch the branch, then deepen the history until a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * merge-base exists, so the review works without `fetch-depth: 0`. Returns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * true once `found` resolves; false when it never does (no remote, no access). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async function fetchTargetHistory(branch: string, cwd: string, found: () => Promise<unknown>): Promise<boolean> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (branch.startsWith("-")) return false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await git(["fetch", "--no-tags", "origin", `+refs/heads/${branch}:refs/remotes/origin/${branch}`], cwd) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (await found()) return true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const depth of [50, 200, 1000]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ((await git(["rev-parse", "--is-shallow-repository"], cwd)).trim() !== "true") return false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const headSha = (await git(["rev-parse", "HEAD"], cwd)).trim() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await git(["fetch", "--no-tags", `--deepen=${depth}`, "origin", `+refs/heads/${branch}:refs/remotes/origin/${branch}`, headSha], cwd) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The deepen fetch adds Prompt for AI agents
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (await found()) return true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+194
to
+219
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [🟠 MEDIUM] By making Suggested change:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** The PR's target branch from the CI provider, when the run is for a PR/MR. */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async function ciTargetBranch(env: NodeJS.ProcessEnv): Promise<{ branch: string; source: BaseSource } | undefined> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (env.GITHUB_EVENT_PATH) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -230,10 +257,15 @@ export async function resolveReviewBase(opts: ResolveBaseOptions): Promise<Resol | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const target = await ciTargetBranch(env) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (target) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const ref of [`origin/${target.branch}`, target.branch]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const sha = await mergeBase(ref, head, opts.cwd) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (sha) return { ref, sha, source: target.source } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const find = async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const ref of [`origin/${target.branch}`, target.branch]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const sha = await mergeBase(ref, head, opts.cwd) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (sha) return { ref, sha, source: target.source } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return undefined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const found = (await find()) ?? ((await fetchTargetHistory(target.branch, opts.cwd, find)) ? await find() : undefined) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: The result of Prompt for AI agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (found) return found | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+267
to
+268
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [🔵 LOW] Following the suggested refactoring of Suggested change:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Error( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `PR target branch '${target.branch}' (${target.source}) is not available locally. ` + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `Fetch it (actions/checkout with fetch-depth: 0, or git fetch origin ${target.branch}) or pass --base.`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -101,6 +101,8 @@ export interface GradeResult { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export interface CheckResult { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| issues?: Array<{ rule: string; message: string; line?: number; severity?: string; category?: string }> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| piiColumns?: string[] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** Core's PII pass could not parse the SQL: `piiColumns` is unknown, not empty. */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| piiAbstained?: boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * True when the native core lint actually ran (parsed the SQL via the AST), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * even if it found zero issues. Distinguishes "clean SQL" from "core | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -118,7 +120,10 @@ export interface ReviewRunner { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| grade(sql: string, dialect: string): Promise<GradeResult> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| check(sql: string, dialect: string, baseSql?: string): Promise<CheckResult> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| equivalence(oldSql: string, newSql: string, dialect?: string): Promise<EquivalenceResult> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| detectPii(sql: string, dialect: string): Promise<{ columns: string[] }> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** `abstained`: the PII pass could not analyse the SQL, so `columns` is unknown. */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| detectPii(sql: string, dialect: string): Promise<{ columns: string[]; abstained?: boolean }> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** Engine calls that threw during this review (method, first reason, count). */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| failures?(): Array<{ method: string; reason: string; count: number }> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Lexical scan (reserved-word aliases + dialect operators) — the curated lists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * and detection live in the compiled core; this passes raw added diff lines. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1147,35 +1152,55 @@ export async function runReview(input: OrchestrateInput): Promise<VerdictEnvelop | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (input.runner.manifestAvailable) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| anyManifest = await input.runner.manifestAvailable().catch(() => false) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // PR-level lanes (across files) that threw: reported with the engine errors. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const laneErrors: Array<{ method: string; reason: string; count: number }> = [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const prLevel = (method: string, lane: Promise<Finding[]>) => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lane.catch((err) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| laneErrors.push({ method, reason: (err instanceof Error ? err.message : String(err)).slice(0, 200), count: 1 }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [] as Finding[] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const failedFile = (file: { path: string }, err: unknown) => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unverified.push({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path: file.path, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| reason: `review failed for this file: ${(err instanceof Error ? err.message : String(err)).replace(/\s+/g, " ").slice(0, 160)}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1156
to
+1166
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [🔵 LOW] Low Severity: Error object stringification obscuring details & Duplication of unverified files
You can create a helper to format errors and ensure duplicate entries for the same file path are merged or ignored. Suggested change:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await Promise.all( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| modelFiles.map(async (file) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const model = modelNameFromPath(file.path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // For renames the previous content lives at oldPath, not the new path. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const oldRef = file.oldPath ?? file.path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const withOld = hasOldSide(file) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [newSql, oldSql, compiledNew, compiledOld] = await Promise.all([ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| file.status !== "deleted" ? getContent?.(file.path, "new") : Promise.resolve(undefined), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| withOld ? getContent?.(oldRef, "old") : Promise.resolve(undefined), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| file.status !== "deleted" ? getCompiled?.(file.path, "new") : Promise.resolve(undefined), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| withOld ? getCompiled?.(oldRef, "old") : Promise.resolve(undefined), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Engine lanes need dbt-compiled SQL. Raw SQL is used only when it holds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // no Jinja: the AST engine reads `{{ config() }}` as an injection attempt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // and a mixed raw-vs-compiled pair can never be proven equivalent, so a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Jinja model without compiled output is marked unverified instead of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // producing warnings about its template syntax. The dbt-patterns lane | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // always uses raw (it needs the Jinja). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const engineNewSql = compiledNew ?? (file.kind === "model_sql" && hasJinja(newSql) ? undefined : newSql) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const engineOldSql = compiledOld ?? (file.kind === "model_sql" && hasJinja(oldSql) ? undefined : oldSql) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (file.status !== "deleted" && newSql && !engineNewSql) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unverified.push({ path: file.path, reason: "no compiled SQL for the head (run dbt compile)" }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else if (withOld && oldSql && !engineOldSql) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unverified.push({ path: file.path, reason: "no compiled SQL for the base (compile the base into target-base)" }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const impact = await input.runner.impact(model) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (impact.hasManifest) anyManifest = true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const pii = engineNewSql ? (await input.runner.detectPii(engineNewSql, dialect)).columns : [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const complex = engineNewSql && input.runner.isComplex ? await input.runner.isComplex(engineNewSql) : false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ctxByPath.set(file.path, { file, impact, pii, newSql, oldSql, engineNewSql, engineOldSql, complex }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const model = modelNameFromPath(file.path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // For renames the previous content lives at oldPath, not the new path. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const oldRef = file.oldPath ?? file.path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const withOld = hasOldSide(file) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [newSql, oldSql, compiledNew, compiledOld] = await Promise.all([ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| file.status !== "deleted" ? getContent?.(file.path, "new") : Promise.resolve(undefined), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| withOld ? getContent?.(oldRef, "old") : Promise.resolve(undefined), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| file.status !== "deleted" ? getCompiled?.(file.path, "new") : Promise.resolve(undefined), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| withOld ? getCompiled?.(oldRef, "old") : Promise.resolve(undefined), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Engine lanes need dbt-compiled SQL. Raw SQL is used only when it holds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // no Jinja: the AST engine reads `{{ config() }}` as an injection attempt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // and a mixed raw-vs-compiled pair can never be proven equivalent, so a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Jinja model without compiled output is marked unverified instead of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // producing warnings about its template syntax. The dbt-patterns lane | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // always uses raw (it needs the Jinja). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const engineNewSql = compiledNew ?? (file.kind === "model_sql" && hasJinja(newSql) ? undefined : newSql) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const engineOldSql = compiledOld ?? (file.kind === "model_sql" && hasJinja(oldSql) ? undefined : oldSql) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (file.status !== "deleted" && newSql && !engineNewSql) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unverified.push({ path: file.path, reason: "no compiled SQL for the head (run dbt compile)" }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else if (withOld && oldSql && !engineOldSql) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unverified.push({ path: file.path, reason: "no compiled SQL for the base (compile the base into target-base)" }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const impact = await input.runner.impact(model) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (impact.hasManifest) anyManifest = true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const piiRes = engineNewSql ? await input.runner.detectPii(engineNewSql, dialect) : { columns: [] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (piiRes.abstained) unverified.push({ path: file.path, reason: "the PII check could not analyse this model" }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SUGGESTION: An abstained PII result is reported but then treated as "no PII" for tiering. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const pii = piiRes.columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const complex = engineNewSql && input.runner.isComplex ? await input.runner.isComplex(engineNewSql) : false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WARNING: The per-file
Consider per-call fallbacks ( |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ctxByPath.set(file.path, { file, impact, pii, newSql, oldSql, engineNewSql, engineOldSql, complex }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (err) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // One file's failure (unreadable content, an engine crash) degrades that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // file only; it must not abort the whole review. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| failedFile(file, err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1327,20 +1352,32 @@ export async function runReview(input: OrchestrateInput): Promise<VerdictEnvelop | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (lanes.has("semantic_change") || lanes.has("dbt_patterns")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tasks.push(structuralChangeLane(ctx, input.runner)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| all.push(...(await Promise.all(tasks))) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // A lane that throws drops only its own findings for this file, recorded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // as unverified — never the whole review. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let laneFailed = false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const settled = await Promise.all( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Per-file isolation is incomplete: the new Prompt for AI agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tasks.map((t) => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| t.catch((err) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!laneFailed) failedFile(ctx.file, err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| laneFailed = true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [] as Finding[] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| all.push(...settled) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // PR-level: cross-model sibling filter-consistency (divergent filters on a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // shared upstream across the changed models). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (lanes.has("semantic_change")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| all.push(await siblingConsistencyLane([...ctxByPath.values()], input.runner)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| all.push(await prLevel("sibling_consistency", siblingConsistencyLane([...ctxByPath.values()], input.runner))) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // PR-level: topology-aware equivalence for merge refactors (N models deleted + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 1 added that supersedes them). Per-model equivalence can't see these because | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // the new model has no 1:1 base. Advisory only (capped at warning). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (lanes.has("semantic_change")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| all.push(await topologyEquivalenceLane(modelFiles, input.runner, getCompiled, dialect)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| all.push(await prLevel("topology_equivalence", topologyEquivalenceLane(modelFiles, input.runner, getCompiled, dialect))) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // schema.yml-level detectors (test removal) — run on changed YAML files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1393,7 +1430,9 @@ export async function runReview(input: OrchestrateInput): Promise<VerdictEnvelop | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [...ctxByPath.values()].map(async (ctx) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!ctx.engineNewSql || ctx.file.status === "deleted") return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Cache hit: qualityLane already ran this exact check. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const cr = await input.runner.check(ctx.engineNewSql, dialect, ctx.engineOldSql) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const cr = await input.runner | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .check(ctx.engineNewSql, dialect, ctx.engineOldSql) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .catch(() => ({ ran: false }) as CheckResult) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (cr.ran) coreRanFiles.add(ctx.file.path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1433
to
1436
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [🔴 HIGH] High Severity: Risk of synchronous exceptions bypassing The fault-tolerance logic heavily relies on chaining To safely handle both synchronous exceptions and asynchronous rejections, it's recommended to wrap the await within a Suggested change:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1536,7 +1575,9 @@ export async function runReview(input: OrchestrateInput): Promise<VerdictEnvelop | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // undecidable finding does not make the whole run lint-only; those findings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // carry their own `degraded` flag and are counted separately in the summary. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const degraded = runDegraded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const engineErrors = [...(input.runner.failures?.() ?? []), ...laneErrors] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const envelope = buildEnvelope({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| engineErrors: engineErrors.length ? engineErrors : undefined, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ai: aiStatus, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| policy: input.policy, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| findings, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: The docs overstate the engine-error downgrade: a gate-mode run with an engine error and another blocking finding can still return
REQUEST_CHANGES. Limit this statement to otherwise empty reviews, which are downgraded from APPROVE to COMMENT.Prompt for AI agents