Skip to content

feat(review): [R20 S4] triage promotion — never auto-approve risk-bearing dbt metadata#1028

Open
sahrizvi wants to merge 1 commit into
feat/review-r18-observability-recallfrom
feat/review-r20-s4-triage-promotion
Open

feat(review): [R20 S4] triage promotion — never auto-approve risk-bearing dbt metadata#1028
sahrizvi wants to merge 1 commit into
feat/review-r18-observability-recallfrom
feat/review-r20-s4-triage-promotion

Conversation

@sahrizvi

@sahrizvi sahrizvi commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds triage-tier promotion rules to risk-tier.ts so the reviewer never auto-approves the two failure modes surfaced by the R20 corpus study:

  • PR D shape: test-only YAML under models/marts/ adding data_tests: / constraints: / unique_combination_of_columns on a contracted mart → previously classified trivial → auto-approved → missed 8 substantive human findings including 5 dbt-trino adapter-semantic bugs.
  • PR E shape: SQL change under a mrt_jobs_cost_savings.sql path → previously classified lite → approved → missed 11 findings including 3 critical FinOps corrections.

Three new FileChangeClass signals wire into fullTierReasons():

Signal Promotes on its own? Fires when
dbtRiskYmlChanges Yes schema.yml diff at YAML key position (not comments / description strings) adds/edits data_tests: / constraints: / contract: / unique_combination_of_columns list item
martLayerChange No — enrichment only File under models/marts/ or models/mart/. Description-only edits under marts stay trivial (matches existing behavior).
finopsPathToken Yes Path/filename contains `cost

Test plan

  • 11 new regression tests in packages/opencode/test/altimate/review.test.ts — all green.
  • Existing 85 tests unchanged.
  • Full altimate review suite: 3781 pass / 640 skip / 0 fail (132 files).
  • Codex-reviewed diff — two highs addressed (regex tightening + FileChangeClass consumer audit).

Ship criteria (from plan v2)

  • PRs D and E from the internal corpus study must no longer auto-approve.
  • Composite Baseline B recall must not regress from 14/64 on the 13-scenario corpus.

Depends on

Stacks on top of #1027 (feat/review-r18-observability-recall). This branch uses the tierReasons[] wiring landed there so promotion reasons surface in the signed envelope. Merge #1027 first, then rebase this onto main.

🤖 Generated with Claude Code

https://claude.ai/code/session_017zXDXMiNFh4qDPxPCfa2of


Summary by cubic

Promotes risk-bearing dbt schema changes and FinOps-related paths to full review so they never auto-approve. Adds precise signals in risk-tier classification to catch the R20 D/E PR shapes and surface clear reasons.

  • New Features
    • dbtRiskYmlChanges: triggers on schema.yml diffs touching data_tests:, constraints:, contract:, or a unique_combination_of_columns item; ignores comments/description; promotes to full.
    • finopsPathToken: triggers when the path/filename contains cost|saving|billing|credit|dbu|spend|revenue|price|rate|pricing|invoice at segment boundaries; promotes to full.
    • martLayerChange: flags files under models/marts?/; enriches the reason when combined with dbtRiskYmlChanges; does not promote on its own so docs-only edits stay trivial.
    • Wired into fullTierReasons() to explain promotions; 11 new tests cover D/E shapes and FP guards; existing tests unchanged.

Written for commit 8eac0d9. Summary will update on new commits.

Review in cubic

…adata

Grounded in the 5-PR internal corpus study
(data-engineering-skills/docs/pr-review-corpus-findings-r20.md) where
historical altimate-code recall was 2/84 = 2.4%. Two of five PRs
auto-approved despite each having 8+ substantive human findings:
- PR D: test-only YAML under `models/marts/` adding
  `data_tests:` / `constraints:` on a contracted mart → 8 misses,
  including 5 dbt-trino adapter-semantic bugs.
- PR E: cost-anchor redesign under `mrt_jobs_cost_savings.sql` →
  11 misses, including 3 critical FinOps corrections.

Adds three FileChangeClass signals + wires them into `fullTierReasons()`:

- **`dbtRiskYmlChanges`** — schema.yml diff introduces or edits
  `data_tests:`, `constraints:`, `contract:`, or a
  `unique_combination_of_columns` list-item. Regex anchors to YAML
  key position after optional diff marker, optional indent, and
  optional list marker; explicitly excludes comment lines. This
  catches PR D.

- **`martLayerChange`** — file lives under `models/marts/` or
  `models/mart/`. Does NOT promote on its own (description-only
  edits stay trivial, matching the existing test), but ENRICHES
  the `dbtRiskYmlChanges` reason string so the customer sees
  "under models/marts/ (mart-API surface)".

- **`finopsPathToken`** — path/filename contains a FinOps keyword
  (`cost|saving|billing|credit|dbu|spend|revenue|price|rate|pricing|
  invoice`) at a word / segment / extension boundary. Catches PR E.
  Word-boundary regex prevents false positives on incidental
  substrings (`broadcaster` ≠ `caste`, `precast` ≠ `cast`).

Regression tests (11 new, all green):
- PR D shapes (data_tests, constraints, unique_combination_of_columns)
  all promote to full with `mart-API surface` context.
- PR E shape (mrt_jobs_cost_savings.sql) + 7 other FinOps keyword
  variants all promote to full.
- FinOps false-positive guard: `broadcaster` / `precast` stay lite.
- Description-only edits under models/marts/ still trivial
  (pre-existing behavior preserved).
- Comment lines and description strings mentioning
  `data_tests:` / `constraints:` do NOT promote (regex tightness).
- Nested-indent YAML key position (production shape) still fires.

Codex-reviewed diff. Two highs addressed:
- Regex tightening to avoid comment / description-string false positives
- FileChangeClass consumer audit (no external constructions; safe)

Ship criteria (from plan v2): PRs D and E from the corpus must no
longer auto-approve. Baseline recall on the existing 13-scenario
corpus must not regress. Both hold: 96/96 tests pass (85 pre-existing
+ 11 new); full altimate review suite 3781/3781 green.

Depends on PR #1027 (feat/review-r18-observability-recall) — this branch
stacks on top so tierReasons[] wiring is in place.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017zXDXMiNFh4qDPxPCfa2of

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 66ffd5cb-7c57-4010-a4ed-d61013730951

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/review-r20-s4-triage-promotion

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

// dbtRiskYmlChanges hit but doesn't fire on its own.
if (c.dbtRiskYmlChanges) {
const loc = c.martLayerChange ? " under models/marts/ (mart-API surface)" : ""
reasons.push(`schema.yml diff touches data_tests/constraints/contract${loc}`)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: Reason string omits unique_combination_of_columns

DBT_UNIQUE_COMBO_RE (line 78) matches unique_combination_of_columns and feeds into dbtRiskYmlChanges, but the surfaced reason only lists data_tests/constraints/contract. A customer who adds only a unique_combination_of_columns test (covered by the test at review.test.ts:466) would see a reason naming keys they didn't touch — inconsistent with both the field doc (lines 43-45) and the cubic summary in the PR description, which both list all four signals.

Suggested change
reasons.push(`schema.yml diff touches data_tests/constraints/contract${loc}`)
reasons.push(`schema.yml diff touches data_tests/constraints/contract/unique_combination_of_columns${loc}`)

Reply with @kilocode-bot fix it to have Kilo Code address this issue.

@kilo-code-bot

kilo-code-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
packages/opencode/src/altimate/review/risk-tier.ts 144 dbtRiskYmlChanges reason string omits unique_combination_of_columns, which DBT_UNIQUE_COMBO_RE (line 78) matches — inconsistent with the field doc and PR summary.
Files Reviewed (2 files)
  • packages/opencode/src/altimate/review/risk-tier.ts - 1 issue
  • packages/opencode/test/altimate/review.test.ts - 0 issues

Fix these issues in Kilo Cloud


Reviewed by glm-5.2 · Input: 64.6K · Output: 23.6K · Cached: 414K

Review guidance: REVIEW.md from base branch feat/review-r18-observability-recall

@sahrizvi

Copy link
Copy Markdown
Contributor Author

Validation report against 5-PR internal corpus

Ran the S4-branch CLI against the 5 real internal dbt PRs from the R20 study (both A1 pure-deterministic and A2 with LLM lane). Baseline is the PR-#1027-tip CLI on the same corpus.

Recall delta

Variant Baseline findings (5 PRs) S4 findings (5 PRs) Delta
A1 (--pure --no-ai=true) 118 118 +0
A2 (--pure, LLM lane on) 141 143 +2 (LLM run-to-run noise)

Tier changes

PR Baseline tier S4 tier Note
#781 (Snowflake per-account cost) full full already full (blast radius)
#1111 (Databricks auto-tune) full full already full (blast radius)
#862 (per-(run,day) job cost) full full already full (blast radius)
#975 (grain/uniqueness tests) full full pre-existing touchesContract already promotes
#1091 (anchor to billed DBU) lite full S4 fired via FinOps path token

Interpretation

S4 is a routing change, not a detector change. On this corpus:

  • ✅ PR #1091 now correctly runs at full tier (was under-tiered as lite)
  • ✅ tierReasons[] surfaces explicit grounded reasons (mart-API surface, FinOps keyword, data_tests/constraints)
  • ⚠️ Zero deterministic (A1) finding count improvement — the extra full-tier lanes (contract_violation, pii_exposure, materialization, warehouse_cost, idempotency) didn't have anything to fire on for PR #1091's specific diff shape
  • ⚠️ A2 +2 delta is LLM run-to-run noise (7 new / 6 removed on the same diff), not attributable to S4

S4's value is foundational: it unblocks subsequent detector PRs (S1 grain-key not_null completeness, S6-lite Trino contract→constraint, S3-specific SQL correctness pack) from being neutered by miscalibrated triage. Real recall wins will show up when those detector PRs stack on top of this one.

Recommend keeping this PR open as the routing floor, but expect the benchmark movement to come from the detector-work PRs stacked above it.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3 issues found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/opencode/src/altimate/review/risk-tier.ts">

<violation number="1" location="packages/opencode/src/altimate/review/risk-tier.ts:77">
P2: Multiline description-only YAML edits can be promoted to full tier when their block-scalar text contains a line such as `constraints:` or `data_tests:`. Because this regex has no YAML scalar context, the claimed description precision guard does not hold; a YAML-aware or hunk/context-aware detector would avoid treating documentation content as metadata keys.</violation>

<violation number="2" location="packages/opencode/src/altimate/review/risk-tier.ts:77">
P1: Edits to an existing `data_tests:` or `constraints:` block can still be classified as `trivial`: the detector scans only changed lines, so an added list item such as `+      - not_null` has no risk key on the changed line and is missed. A hunk-aware YAML/context check (or parsing the resulting YAML and intersecting changed nodes) would keep these metadata edits from being auto-approved.</violation>

<violation number="3" location="packages/opencode/src/altimate/review/risk-tier.ts:144">
P2: The reason string `"schema.yml diff touches data_tests/constraints/contract"` doesn't account for the `unique_combination_of_columns` case. Since `dbtRiskYmlChanges` is true when *either* `DBT_RISK_KEY_RE` or `DBT_UNIQUE_COMBO_RE` matches, a customer who only adds a `unique_combination_of_columns` test will see a tier-promotion reason referencing keys they never touched. Consider including `unique_combination_of_columns` in the reason string (e.g., `data_tests/constraints/contract/unique_combination_of_columns`) to stay consistent with the field documentation and actual detection logic.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

// forms because `data_tests`/`constraints`/`contract` are ALWAYS keys, whereas
// `unique_combination_of_columns` is a TEST NAME that shows up as a list item
// (`- dbt_utils.unique_combination_of_columns:`).
const DBT_RISK_KEY_RE = /^[+-]?[ \t]*(?!#)(?:-[ \t]+)?(?:data_tests|constraints|contract)[ \t]*:/im

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1: Edits to an existing data_tests: or constraints: block can still be classified as trivial: the detector scans only changed lines, so an added list item such as + - not_null has no risk key on the changed line and is missed. A hunk-aware YAML/context check (or parsing the resulting YAML and intersecting changed nodes) would keep these metadata edits from being auto-approved.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/opencode/src/altimate/review/risk-tier.ts, line 77:

<comment>Edits to an existing `data_tests:` or `constraints:` block can still be classified as `trivial`: the detector scans only changed lines, so an added list item such as `+      - not_null` has no risk key on the changed line and is missed. A hunk-aware YAML/context check (or parsing the resulting YAML and intersecting changed nodes) would keep these metadata edits from being auto-approved.</comment>

<file context>
@@ -50,6 +66,23 @@ export interface ClassifyOptions {
+// forms because `data_tests`/`constraints`/`contract` are ALWAYS keys, whereas
+// `unique_combination_of_columns` is a TEST NAME that shows up as a list item
+// (`- dbt_utils.unique_combination_of_columns:`).
+const DBT_RISK_KEY_RE = /^[+-]?[ \t]*(?!#)(?:-[ \t]+)?(?:data_tests|constraints|contract)[ \t]*:/im
+const DBT_UNIQUE_COMBO_RE = /^[+-]?[ \t]*(?!#)-[ \t]+(?:[\w.]+\.)?unique_combination_of_columns[ \t]*:/im
+const MARTS_DIR_RE = /(?:^|\/)models\/marts?\//i
</file context>

// forms because `data_tests`/`constraints`/`contract` are ALWAYS keys, whereas
// `unique_combination_of_columns` is a TEST NAME that shows up as a list item
// (`- dbt_utils.unique_combination_of_columns:`).
const DBT_RISK_KEY_RE = /^[+-]?[ \t]*(?!#)(?:-[ \t]+)?(?:data_tests|constraints|contract)[ \t]*:/im

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: Multiline description-only YAML edits can be promoted to full tier when their block-scalar text contains a line such as constraints: or data_tests:. Because this regex has no YAML scalar context, the claimed description precision guard does not hold; a YAML-aware or hunk/context-aware detector would avoid treating documentation content as metadata keys.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/opencode/src/altimate/review/risk-tier.ts, line 77:

<comment>Multiline description-only YAML edits can be promoted to full tier when their block-scalar text contains a line such as `constraints:` or `data_tests:`. Because this regex has no YAML scalar context, the claimed description precision guard does not hold; a YAML-aware or hunk/context-aware detector would avoid treating documentation content as metadata keys.</comment>

<file context>
@@ -50,6 +66,23 @@ export interface ClassifyOptions {
+// forms because `data_tests`/`constraints`/`contract` are ALWAYS keys, whereas
+// `unique_combination_of_columns` is a TEST NAME that shows up as a list item
+// (`- dbt_utils.unique_combination_of_columns:`).
+const DBT_RISK_KEY_RE = /^[+-]?[ \t]*(?!#)(?:-[ \t]+)?(?:data_tests|constraints|contract)[ \t]*:/im
+const DBT_UNIQUE_COMBO_RE = /^[+-]?[ \t]*(?!#)-[ \t]+(?:[\w.]+\.)?unique_combination_of_columns[ \t]*:/im
+const MARTS_DIR_RE = /(?:^|\/)models\/marts?\//i
</file context>

// dbtRiskYmlChanges hit but doesn't fire on its own.
if (c.dbtRiskYmlChanges) {
const loc = c.martLayerChange ? " under models/marts/ (mart-API surface)" : ""
reasons.push(`schema.yml diff touches data_tests/constraints/contract${loc}`)

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: The reason string "schema.yml diff touches data_tests/constraints/contract" doesn't account for the unique_combination_of_columns case. Since dbtRiskYmlChanges is true when either DBT_RISK_KEY_RE or DBT_UNIQUE_COMBO_RE matches, a customer who only adds a unique_combination_of_columns test will see a tier-promotion reason referencing keys they never touched. Consider including unique_combination_of_columns in the reason string (e.g., data_tests/constraints/contract/unique_combination_of_columns) to stay consistent with the field documentation and actual detection logic.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/opencode/src/altimate/review/risk-tier.ts, line 144:

<comment>The reason string `"schema.yml diff touches data_tests/constraints/contract"` doesn't account for the `unique_combination_of_columns` case. Since `dbtRiskYmlChanges` is true when *either* `DBT_RISK_KEY_RE` or `DBT_UNIQUE_COMBO_RE` matches, a customer who only adds a `unique_combination_of_columns` test will see a tier-promotion reason referencing keys they never touched. Consider including `unique_combination_of_columns` in the reason string (e.g., `data_tests/constraints/contract/unique_combination_of_columns`) to stay consistent with the field documentation and actual detection logic.</comment>

<file context>
@@ -91,6 +128,22 @@ export function fullTierReasons(c: FileChangeClass): string[] {
+  // dbtRiskYmlChanges hit but doesn't fire on its own.
+  if (c.dbtRiskYmlChanges) {
+    const loc = c.martLayerChange ? " under models/marts/ (mart-API surface)" : ""
+    reasons.push(`schema.yml diff touches data_tests/constraints/contract${loc}`)
+  }
+  if (c.finopsPathToken) reasons.push("path contains FinOps keyword (cost/saving/billing/dbu/etc.)")
</file context>
Suggested change
reasons.push(`schema.yml diff touches data_tests/constraints/contract${loc}`)
reasons.push(`schema.yml diff touches data_tests/constraints/contract/unique_combination_of_columns${loc}`)

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.

1 participant