Skip to content

Commit 9435bc6

Browse files
committed
fix(review): [R20 S4] catch riskTierPathTokens config error in orchestrate — don't crash the run (cubic P2)
Follow-up to `919bcc17f`. That commit made `compilePathTokenResolver` throw on an unknown `preset:<name>` — the right safety fix — but nothing between the resolver and the CLI handler caught the throw, so a single typo in `.altimate/review.yml` (e.g. `preset:finop` instead of `preset:finops`) would crash every review run for the project's CI (cubic-review P2 on PR #1028 risk-tier.ts:134). Fix: wrap the `compilePathTokenResolver` call in `orchestrate.ts` in a try/catch. On throw: 1. Log a prominent warning to stderr with the config-error message and a fallback banner ("Review continuing without path-token promotion") so the CI log tells the operator what happened. 2. Fall back to `pathTokenCategoryOf = undefined` so `classifyPR` still runs — no promotion fires, but the rest of the review proceeds normally. 3. Prepend the config error to `tierResult.reasons` so it surfaces in `envelope.tierReasons` when `explainTier` is set. A reader of the envelope (or a PR-comment renderer) sees WHY their opt-in didn't fire without having to dig through CI logs. The trade-off is deliberate: the user's opt-in is dead until they fix the typo (conservative safe fallback — no silent auto-approve on billing/PCI/etc. paths), but the review itself doesn't die. Test: `runReview does NOT crash on an unknown-preset config typo — degrades gracefully` builds a minimal fake ReviewRunner + config with `preset:finop` typo, captures stderr, asserts (a) envelope is produced (no crash), (b) stderr contains both the config-error message and the fallback banner, (c) `env.tierReasons` carries the same error so envelope readers see it too. 112/112 tests in review.test.ts pass.
1 parent 919bcc1 commit 9435bc6

2 files changed

Lines changed: 72 additions & 1 deletion

File tree

‎packages/opencode/src/altimate/review/orchestrate.ts‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,25 @@ export async function runReview(input: OrchestrateInput): Promise<VerdictEnvelop
10961096
// the reviewer core carries no default list. `undefined` when no
10971097
// categories are configured, which keeps `highRiskPathTokenCategory`
10981098
// undefined per file and no promotion fires.
1099-
const pathTokenCategoryOf = compilePathTokenResolver(input.config.riskTierPathTokens)
1099+
//
1100+
// `compilePathTokenResolver` throws on an unknown `preset:<name>` (typo
1101+
// guard, cubic + harness-bot P2). Catch that here so a single config
1102+
// typo in `.altimate/review.yml` doesn't crash every review run in the
1103+
// project's CI — surface the error to stderr AND propagate a
1104+
// `configError` reason into the envelope so the reader can see what
1105+
// broke. The review continues with no path-token promotion (the
1106+
// conservative safe fallback), so users notice their opt-in is dead
1107+
// rather than getting silent auto-approve on billing/PCI/etc. paths
1108+
// (cubic-review P2 on PR #1028 risk-tier.ts:134).
1109+
let pathTokenCategoryOf: ((p: string) => string | undefined) | undefined
1110+
let pathTokenConfigError: string | undefined
1111+
try {
1112+
pathTokenCategoryOf = compilePathTokenResolver(input.config.riskTierPathTokens)
1113+
} catch (e: any) {
1114+
pathTokenConfigError = `riskTierPathTokens config invalid: ${e?.message ?? String(e)}`
1115+
process.stderr.write(`⚠️ ${pathTokenConfigError}\n Review continuing without path-token promotion.\n`)
1116+
pathTokenCategoryOf = undefined
1117+
}
11001118
const tierResult = classifyPR(reviewable, {
11011119
blastRadiusOf: (p) => {
11021120
const c = ctxByPath.get(p)
@@ -1106,6 +1124,9 @@ export async function runReview(input: OrchestrateInput): Promise<VerdictEnvelop
11061124
isComplexOf: (f) => ctxByPath.get(f.path)?.complex ?? false,
11071125
pathTokenCategoryOf,
11081126
})
1127+
// Surface config errors in the tier-reasons stream so a reader of the
1128+
// envelope (or PR comment) sees WHY their opt-in didn't fire.
1129+
if (pathTokenConfigError) tierResult.reasons.unshift(pathTokenConfigError)
11091130
const classifiedTier = tierResult.tier
11101131
// G2 — --force-tier overrides the classifier. Envelope records both the
11111132
// forced tier and the original classification whenever the flag is passed

‎packages/opencode/test/altimate/review.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,56 @@ describe("risk-tier", () => {
835835
expect(ok!("models/marts/mrt_cost_daily.sql")).toBe("finops")
836836
})
837837

838+
test("R20 S4: runReview does NOT crash on an unknown-preset config typo — degrades gracefully (cubic P2)", async () => {
839+
// cubic-review P2 on PR #1028 — a typo like `preset:finop` in
840+
// `.altimate/review.yml` would make `compilePathTokenResolver` throw
841+
// and, previously, take the entire review run down with it. Catch
842+
// in orchestrate.ts, log to stderr, and continue with no path-token
843+
// promotion; surface the error in `tierReasons` so a reader of the
844+
// envelope (or PR comment) sees why their opt-in didn't fire.
845+
const files: ChangedFile[] = [{ path: "models/marts/m.sql", status: "modified", diff: "+select 1\n" }]
846+
// Minimal runner — this test only needs runReview to reach the
847+
// resolver-build path and back out with an envelope.
848+
const runner: ReviewRunner = {
849+
async check() { return { issues: [], ran: false } },
850+
async detectPii() { return { columns: [] } },
851+
async impact() { return { hasManifest: false, severity: "SAFE", directCount: 0, transitiveCount: 0, testCount: 0 } },
852+
async equivalence() { return { decided: true, equivalent: true } as EquivalenceResult },
853+
async grade() { return { grade: "A", decided: true } },
854+
}
855+
// Silence stderr for the expected warning during the test run.
856+
const origWrite = process.stderr.write.bind(process.stderr)
857+
let stderrCaptured = ""
858+
process.stderr.write = ((s: string) => {
859+
stderrCaptured += String(s)
860+
return true
861+
}) as typeof process.stderr.write
862+
try {
863+
const env = await runReview({
864+
changedFiles: files,
865+
config: { ...DEFAULT_REVIEW_CONFIG, riskTierPathTokens: { finops: ["preset:finop"] } } as any,
866+
rubric: DEFAULT_RUBRIC,
867+
mode: "comment",
868+
runner,
869+
getContent: async () => "select 1",
870+
generatedAt: "2026-05-29T00:00:00Z",
871+
explainTier: true,
872+
})
873+
// Envelope was still produced — no crash.
874+
expect(env.verdict).toBeDefined()
875+
// stderr got the diagnostic + the fallback banner.
876+
expect(stderrCaptured).toContain("riskTierPathTokens config invalid")
877+
expect(stderrCaptured).toContain("Review continuing without path-token promotion")
878+
// Envelope's tier-reasons stream carries the config error so a
879+
// reader who never sees stderr still knows why promotion didn't fire.
880+
const reasons = (env.tierReasons ?? []).join(" ")
881+
expect(reasons).toContain("riskTierPathTokens config invalid")
882+
expect(reasons).toContain("unknown preset 'finop'")
883+
} finally {
884+
process.stderr.write = origWrite
885+
}
886+
})
887+
838888
test("R20 S4: high-risk token — no promotion when no resolver is configured (core is neutral)", () => {
839889
// Same paths that fire above must stay lite when the caller doesn't
840890
// supply a resolver — the reviewer core has zero opinion about which

0 commit comments

Comments
 (0)