mandrel 2.84.0 → 2.86.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,242 @@
1
+ /**
2
+ * review-providers/claude-verdict.js — reads `code-review`'s claude result
3
+ * envelope and auth-status payload into findings or a no-verdict reason.
4
+ *
5
+ * @typedef {import('./types.js').Finding} Finding
6
+ */
7
+
8
+ import { buildFinding, unwrapEnvelope } from './parse-findings.js';
9
+
10
+ export const FINDINGS_SCHEMA_JSON = JSON.stringify({
11
+ type: 'object',
12
+ properties: {
13
+ findings: {
14
+ type: 'array',
15
+ items: {
16
+ type: 'object',
17
+ properties: {
18
+ title: { type: 'string' },
19
+ body: { type: 'string' },
20
+ file: { type: 'string' },
21
+ line: { type: 'integer' },
22
+ category: { type: 'string' },
23
+ },
24
+ required: ['title', 'body'],
25
+ },
26
+ },
27
+ },
28
+ required: ['findings'],
29
+ });
30
+
31
+ const MAX_DETAIL_CHARS = 300;
32
+ const USAGE_LIMIT_RE = /hit your .*limit|usage limit|rate limit/i;
33
+
34
+ export function clip(text) {
35
+ const flat = String(text ?? '')
36
+ .replace(/\s+/g, ' ')
37
+ .trim();
38
+ return flat.length > MAX_DETAIL_CHARS
39
+ ? `${flat.slice(0, MAX_DETAIL_CHARS)}…`
40
+ : flat;
41
+ }
42
+
43
+ function tryParseJson(text) {
44
+ try {
45
+ return JSON.parse(text);
46
+ } catch {
47
+ return undefined;
48
+ }
49
+ }
50
+
51
+ /**
52
+ * `claude auth status --json`. Only `authMethod` and `subscriptionType`
53
+ * are ever named: the payload also carries the account email, org name
54
+ * and ids, which no reason or log line may repeat.
55
+ *
56
+ * @param {{ status: number, stdout: string }} result
57
+ * @returns {{ ok: true, detail: string } | { ok: false, reason: string }}
58
+ */
59
+ export function readAuthStatus(result) {
60
+ if (result.status !== 0) {
61
+ return {
62
+ ok: false,
63
+ reason: `claude auth status exited ${result.status}: the CLI is not logged in or unusable`,
64
+ };
65
+ }
66
+ const parsed = tryParseJson(result.stdout);
67
+ if (!parsed || typeof parsed !== 'object') {
68
+ return {
69
+ ok: false,
70
+ reason: 'claude auth status returned unparseable output',
71
+ };
72
+ }
73
+ const method =
74
+ typeof parsed.authMethod === 'string' ? parsed.authMethod : null;
75
+ if (parsed.loggedIn !== true) {
76
+ return {
77
+ ok: false,
78
+ reason: `claude CLI is not logged in${method ? ` (authMethod: ${method})` : ''}`,
79
+ };
80
+ }
81
+ const plan =
82
+ typeof parsed.subscriptionType === 'string'
83
+ ? `, subscriptionType: ${parsed.subscriptionType}`
84
+ : '';
85
+ return { ok: true, detail: `authMethod: ${method ?? 'unknown'}${plan}` };
86
+ }
87
+
88
+ /**
89
+ * The end index of the balanced JSON array opening at `start`, string-aware.
90
+ *
91
+ * @param {string} text
92
+ * @param {number} start - index of a `[`.
93
+ * @returns {number} index of the closing `]`, or -1.
94
+ */
95
+ function matchArrayEnd(text, start) {
96
+ let depth = 0;
97
+ let inString = false;
98
+ for (let i = start; i < text.length; i += 1) {
99
+ const ch = text[i];
100
+ if (inString) {
101
+ if (ch === '\\') i += 1;
102
+ else if (ch === '"') inString = false;
103
+ } else if (ch === '"') inString = true;
104
+ else if (ch === '[') depth += 1;
105
+ else if (ch === ']') {
106
+ depth -= 1;
107
+ if (depth === 0) return i;
108
+ }
109
+ }
110
+ return -1;
111
+ }
112
+
113
+ /**
114
+ * The last top-level JSON array in free text.
115
+ *
116
+ * @param {string} text
117
+ * @returns {unknown[] | undefined}
118
+ */
119
+ function lastBareArray(text) {
120
+ let found;
121
+ let i = text.indexOf('[');
122
+ while (i !== -1) {
123
+ const end = matchArrayEnd(text, i);
124
+ const parsed =
125
+ end === -1 ? undefined : tryParseJson(text.slice(i, end + 1));
126
+ if (Array.isArray(parsed)) {
127
+ found = parsed;
128
+ i = text.indexOf('[', end + 1);
129
+ } else {
130
+ i = text.indexOf('[', i + 1);
131
+ }
132
+ }
133
+ return found;
134
+ }
135
+
136
+ /**
137
+ * The findings list from a JSON value: a bare array or `{ findings }`.
138
+ *
139
+ * @param {unknown} value
140
+ * @returns {unknown[] | undefined}
141
+ */
142
+ function asFindingList(value) {
143
+ if (value === undefined) return undefined;
144
+ const unwrapped = unwrapEnvelope(value);
145
+ return Array.isArray(unwrapped) ? unwrapped : undefined;
146
+ }
147
+
148
+ /**
149
+ * Fallback over the envelope's `result` text: the last fenced block, else
150
+ * the last top-level JSON array — so a prose preamble is still a verdict.
151
+ *
152
+ * @param {string} text
153
+ * @returns {unknown[] | undefined}
154
+ */
155
+ function parseVerdictText(text) {
156
+ const fences = [...text.matchAll(/```[a-z]*[^\S\n]*\n([\s\S]*?)```/gi)];
157
+ const lastFence = fences.at(-1);
158
+ const fenced = lastFence
159
+ ? asFindingList(tryParseJson(lastFence[1].trim()))
160
+ : undefined;
161
+ return fenced ?? lastBareArray(text);
162
+ }
163
+
164
+ function toFindings(entries) {
165
+ return entries
166
+ .map((entry) =>
167
+ buildFinding(entry, {
168
+ mapSeverity: () => 'critical',
169
+ defaultCategory: 'bug',
170
+ }),
171
+ )
172
+ .filter(Boolean);
173
+ }
174
+
175
+ function failureReason(result, envelope) {
176
+ const resultText =
177
+ typeof envelope?.result === 'string' ? envelope.result : '';
178
+ const text = [result.stderr, resultText, result.stdout].join('\n');
179
+ if (USAGE_LIMIT_RE.test(text)) {
180
+ return 'the claude CLI account is out of quota (usage limit reached)';
181
+ }
182
+ if (result.status !== 0) {
183
+ return `claude --print exited with status ${result.status}: ${
184
+ clip(result.stderr || resultText || result.stdout) || '<no output>'
185
+ }`;
186
+ }
187
+ if (envelope?.is_error === true) {
188
+ return `the reviewer returned an error result: ${clip(resultText) || '<no output>'}`;
189
+ }
190
+ return `the reviewer run ended with subtype ${clip(envelope?.subtype)}`;
191
+ }
192
+
193
+ function parseEnvelope(stdout) {
194
+ const parsed = tryParseJson(stdout);
195
+ return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
196
+ ? parsed
197
+ : null;
198
+ }
199
+
200
+ function isSuccess(result, envelope) {
201
+ return (
202
+ result.status === 0 &&
203
+ envelope !== null &&
204
+ envelope.is_error !== true &&
205
+ envelope.subtype === 'success'
206
+ );
207
+ }
208
+
209
+ function noVerdictReason(result, envelope) {
210
+ if (result.status === 0 && envelope === null) {
211
+ return 'the reviewer output was not a JSON result envelope';
212
+ }
213
+ return failureReason(result, envelope);
214
+ }
215
+
216
+ function structuredFindings(structured) {
217
+ return Array.isArray(structured?.findings) ? structured.findings : undefined;
218
+ }
219
+
220
+ function resultTextFindings(text) {
221
+ return typeof text === 'string' ? parseVerdictText(text) : undefined;
222
+ }
223
+
224
+ /**
225
+ * Verdict resolution: (a) a successful envelope's `structured_output`,
226
+ * (b) the fallback parser over its `result` text, (c) no verdict.
227
+ *
228
+ * @param {{ status: number, stdout: string, stderr: string }} result
229
+ * @returns {{ findings: Finding[] } | { reason: string }}
230
+ */
231
+ export function resolveVerdict(result) {
232
+ const envelope = parseEnvelope(result.stdout);
233
+ if (!isSuccess(result, envelope)) {
234
+ return { reason: noVerdictReason(result, envelope) };
235
+ }
236
+ const entries =
237
+ structuredFindings(envelope.structured_output) ??
238
+ resultTextFindings(envelope.result);
239
+ return entries
240
+ ? { findings: toFindings(entries) }
241
+ : { reason: 'the reviewer output did not parse as a findings verdict' };
242
+ }
@@ -6,26 +6,58 @@
6
6
  * id and the diff text — never `acceptance[]` or the self-eval verdict: this
7
7
  * is a bug review, not a second acceptance scoring.
8
8
  *
9
- * A missing CLI throws at construction (the default chain entry is
10
- * `optional: true`, so hosts without it skip). A review that cannot run or
11
- * whose output does not parse degrades to one non-halting `suggestion`.
9
+ * Cost is bounded by stripping context, not by pinning a model: an empty
10
+ * OS temp cwd (no CLAUDE.md discovery), user-only settings, no MCP, no tools.
11
+ *
12
+ * A missing CLI throws at construction (the chain entry is optional). A
13
+ * review with no verdict records one degraded gate via `getDegradations()`
14
+ * and returns no findings, so "never ran" cannot read as "found nothing".
12
15
  *
13
16
  * @typedef {import('./types.js').Finding} Finding
14
17
  * @typedef {import('./types.js').ReviewInput} ReviewInput
15
18
  * @typedef {import('./types.js').ReviewProvider} ReviewProvider
19
+ * @typedef {import('./degraded-gates.js').GateDegradation} GateDegradation
16
20
  */
17
21
 
22
+ import fs from 'node:fs';
23
+ import os from 'node:os';
24
+ import path from 'node:path';
18
25
  import { spawnCaptureAsync } from '../../child-exec.js';
19
26
  import { gitSpawn } from '../../git-utils.js';
20
27
  import { PROJECT_ROOT } from '../../project-root.js';
21
- import { parseProviderFindings } from './parse-findings.js';
28
+ import {
29
+ clip,
30
+ FINDINGS_SCHEMA_JSON,
31
+ readAuthStatus,
32
+ resolveVerdict,
33
+ } from './claude-verdict.js';
22
34
  import { renderDepthDirective } from './review-depth.js';
23
35
  import { probeClaudeCli } from './security-review.js';
24
36
 
25
- const CLAUDE_ARGS = Object.freeze(['--print', '--effort', 'low']);
37
+ const CLAUDE_ARGS = Object.freeze([
38
+ '--print',
39
+ '--effort',
40
+ 'low',
41
+ '--output-format',
42
+ 'json',
43
+ '--json-schema',
44
+ FINDINGS_SCHEMA_JSON,
45
+ '--setting-sources',
46
+ 'user',
47
+ '--strict-mcp-config',
48
+ '--tools',
49
+ '',
50
+ ]);
51
+ const AUTH_ARGS = Object.freeze(['auth', 'status', '--json']);
26
52
  const INVOKE_TIMEOUT_MS = 10 * 60 * 1000;
53
+ const AUTH_TIMEOUT_MS = 15 * 1000;
27
54
  /** Larger diffs are truncated; the reviewer is told so. */
28
55
  const MAX_DIFF_CHARS = 200_000;
56
+ const DEGRADATION_BASE = Object.freeze({
57
+ tool: 'code-review',
58
+ gate: 'codeReview',
59
+ surface: 'model-bug-review',
60
+ });
29
61
 
30
62
  const PROMPT_HEAD =
31
63
  'You are reviewing the diff `{baseRef}...{headRef}` for Story #{ticketId} ' +
@@ -37,11 +69,10 @@ const PROMPT_HEAD =
37
69
  'line in the new version, why it is wrong, and how to show it fails (an ' +
38
70
  'input, command or test that exposes it).\n\n' +
39
71
  'The diff below is authoritative — files on disk may not reflect it. ' +
40
- 'Emit ONLY a JSON array on stdout with this exact shape, no prose around ' +
41
- 'it:\n\n' +
42
- '[{"title":"...","body":"Why it is wrong: ... How to show it fails: ...",' +
43
- '"file":"...","line":1,"category":"bug"}]\n\n' +
44
- 'Emit [] if there is nothing you would block the merge for.\n\n';
72
+ 'Answer with a JSON object of this exact shape, no prose around it:\n\n' +
73
+ '{"findings":[{"title":"...","body":"Why it is wrong: ... How to show it ' +
74
+ 'fails: ...","file":"...","line":1,"category":"bug"}]}\n\n' +
75
+ 'Emit {"findings":[]} if there is nothing you would block the merge for.\n\n';
45
76
 
46
77
  /**
47
78
  * @param {ReviewInput} input
@@ -62,64 +93,37 @@ function buildPrompt(input, diff) {
62
93
  }
63
94
 
64
95
  /**
65
- * The prompt rides stdin so no shell ever quotes it. Asynchronous: the
66
- * review overlaps close's gate children, whose output must keep draining.
96
+ * A Windows shell joins argv unquoted, which would drop `--tools ""` and
97
+ * split the schema; quote each arg for the MSVCRT argv parser.
67
98
  *
68
- * @param {string} prompt
69
- * @param {Function} [run] - `(file, args, options)` seam for tests.
70
- * @returns {Promise<{ status: number, stdout: string, stderr: string }>}
71
- */
72
- function invokeClaude(prompt, run) {
73
- return spawnCaptureAsync('claude', [...CLAUDE_ARGS], {
74
- cwd: PROJECT_ROOT,
75
- input: prompt,
76
- shell: process.platform === 'win32',
77
- timeout: INVOKE_TIMEOUT_MS,
78
- ...(run ? { run } : {}),
79
- });
80
- }
81
-
82
- /** A model often fences its JSON; strip one surrounding fence. */
83
- function stripFence(text) {
84
- const match = /^\s*```[a-z]*\s*\n([\s\S]*?)\n\s*```\s*$/i.exec(text ?? '');
85
- return match ? match[1] : (text ?? '');
86
- }
87
-
88
- /**
89
- * @param {string} title
90
- * @param {string} detail
91
- * @returns {Finding}
99
+ * @param {string} arg
100
+ * @returns {string}
92
101
  */
93
- function advisory(title, detail) {
94
- return {
95
- severity: 'suggestion',
96
- title,
97
- body:
98
- `${detail} The model bug review did not produce a verdict — inspect ` +
99
- 'the diff manually before merging. Advisory only; the chain did not halt.',
100
- category: 'bug',
101
- };
102
+ function quoteWindowsArg(arg) {
103
+ const escaped = arg.replace(/(\\*)"/g, '$1$1\\"').replace(/(\\+)$/, '$1$1');
104
+ return `"${escaped}"`;
102
105
  }
103
106
 
104
107
  /**
105
- * @param {string} stdout
106
- * @returns {Finding[]}
108
+ * Async, so close's concurrent gate children keep draining.
109
+ *
110
+ * @param {ReadonlyArray<string>} args
111
+ * @param {{ cwd: string, input?: string, timeout: number, run?: Function, platform: string }} opts
112
+ * @returns {Promise<{ status: number, stdout: string, stderr: string }>}
107
113
  */
108
- function parseFindings(stdout) {
109
- try {
110
- return parseProviderFindings(stripFence(stdout), {
111
- errorPrefix: '[code-review] Failed to parse reviewer stdout as JSON',
112
- mapSeverity: () => 'critical',
113
- defaultCategory: 'bug',
114
- });
115
- } catch (err) {
116
- return [
117
- advisory(
118
- 'Code review output not parseable as JSON',
119
- `The reviewer returned text that did not parse as a JSON findings array (${err.message}).`,
120
- ),
121
- ];
122
- }
114
+ function runClaude(args, { cwd, input, timeout, run, platform }) {
115
+ const shell = platform === 'win32';
116
+ return spawnCaptureAsync(
117
+ 'claude',
118
+ shell ? args.map(quoteWindowsArg) : [...args],
119
+ {
120
+ cwd,
121
+ input: input ?? '',
122
+ shell,
123
+ timeout,
124
+ ...(run ? { run } : {}),
125
+ },
126
+ );
123
127
  }
124
128
 
125
129
  /**
@@ -139,69 +143,105 @@ function assertInput(input) {
139
143
  }
140
144
  }
141
145
 
146
+ function runAuthStatus(runDir, deps) {
147
+ return runClaude(AUTH_ARGS, {
148
+ cwd: runDir,
149
+ timeout: AUTH_TIMEOUT_MS,
150
+ run: deps.authSpawnFn,
151
+ platform: deps.platform,
152
+ });
153
+ }
154
+
155
+ function runReviewer(runDir, prompt, deps) {
156
+ return runClaude(CLAUDE_ARGS, {
157
+ cwd: runDir,
158
+ input: prompt,
159
+ timeout: INVOKE_TIMEOUT_MS,
160
+ run: deps.spawnFn,
161
+ platform: deps.platform,
162
+ });
163
+ }
164
+
165
+ /**
166
+ * Preflight, then the review, both from a fresh OS temp dir removed after.
167
+ *
168
+ * @returns {Promise<{ findings: Finding[] } | { reason: string }>}
169
+ */
170
+ async function reviewInTempDir(prompt, deps) {
171
+ const runDir = fs.mkdtempSync(path.join(os.tmpdir(), 'mandrel-code-review-'));
172
+ try {
173
+ const auth = readAuthStatus(await runAuthStatus(runDir, deps));
174
+ if (!auth.ok) return auth;
175
+ deps.logger?.info?.(
176
+ `[code-review] Invoking claude --print --effort low (${auth.detail})...`,
177
+ );
178
+ return resolveVerdict(await runReviewer(runDir, prompt, deps));
179
+ } finally {
180
+ fs.rmSync(runDir, { recursive: true, force: true });
181
+ }
182
+ }
183
+
184
+ /**
185
+ * @returns {{ reason: string } | { text: string }}
186
+ */
187
+ function readDiff(gitSpawnFn, { baseRef, headRef }) {
188
+ const range = `${baseRef}...${headRef}`;
189
+ const diff = gitSpawnFn(PROJECT_ROOT, 'diff', '--no-color', range);
190
+ if (diff.status === 0) return { text: diff.stdout };
191
+ return {
192
+ reason: `git diff ${range} failed: ${clip(diff.stderr) || '<no output>'}`,
193
+ };
194
+ }
195
+
196
+ function assertCliPresent(probeFn) {
197
+ if (probeFn()) return;
198
+ throw new Error(
199
+ '[ReviewProviderFactory] codeReview provider "code-review" requires ' +
200
+ 'the `claude` CLI on PATH but it was not detected. Install the ' +
201
+ 'Claude Code CLI, or keep the entry `optional: true` so hosts ' +
202
+ 'without it skip the model bug review.',
203
+ );
204
+ }
205
+
142
206
  /**
143
207
  * @param {{
144
208
  * probeFn?: () => boolean,
145
209
  * gitSpawnFn?: typeof gitSpawn,
146
210
  * spawnFn?: Function,
211
+ * authSpawnFn?: Function,
212
+ * platform?: string,
147
213
  * logger?: { info?: Function, warn?: Function },
148
- * }} [deps] - `spawnFn` replaces the async runner for the `claude` call.
149
- * @returns {ReviewProvider}
214
+ * }} [deps] - `spawnFn` / `authSpawnFn` replace the async runner for the
215
+ * review and the `claude auth status` preflight.
216
+ * @returns {ReviewProvider & { getDegradations: () => GateDegradation[] }}
150
217
  */
151
218
  export function createCodeReviewProviderForRegistry(deps = {}) {
152
- const probeFn = deps.probeFn ?? probeClaudeCli;
153
- if (!probeFn()) {
154
- throw new Error(
155
- '[ReviewProviderFactory] codeReview provider "code-review" requires ' +
156
- 'the `claude` CLI on PATH but it was not detected. Install the ' +
157
- 'Claude Code CLI, or keep the entry `optional: true` so hosts ' +
158
- 'without it skip the model bug review.',
159
- );
160
- }
219
+ assertCliPresent(deps.probeFn ?? probeClaudeCli);
161
220
  const gitSpawnFn = deps.gitSpawnFn ?? gitSpawn;
162
- const { spawnFn, logger } = deps;
221
+ const runDeps = { ...deps, platform: deps.platform ?? process.platform };
222
+ /** @type {GateDegradation[]} */
223
+ let degradations = [];
224
+
225
+ function settle(verdict) {
226
+ if (!('reason' in verdict)) return verdict.findings;
227
+ degradations.push({ ...DEGRADATION_BASE, reason: verdict.reason });
228
+ deps.logger?.warn?.(`[code-review] No verdict: ${verdict.reason}.`);
229
+ return [];
230
+ }
163
231
 
164
232
  return {
165
233
  async runReview(input) {
234
+ degradations = [];
166
235
  assertInput(input);
167
- const { baseRef, headRef, ticketId } = input;
168
- const diff = gitSpawnFn(
169
- PROJECT_ROOT,
170
- 'diff',
171
- '--no-color',
172
- `${baseRef}...${headRef}`,
173
- );
174
- if (diff.status !== 0) {
175
- return [
176
- advisory(
177
- 'Code review could not read the diff',
178
- `\`git diff ${baseRef}...${headRef}\` failed: ${diff.stderr || '<no output>'}.`,
179
- ),
180
- ];
181
- }
182
- if (diff.stdout.trim().length === 0) return [];
183
-
184
- logger?.info?.(
185
- `[code-review] Invoking claude --print --effort low for Story #${ticketId} (${baseRef}...${headRef})...`,
186
- );
187
- const result = await invokeClaude(
188
- buildPrompt(input, diff.stdout),
189
- spawnFn,
236
+ const diff = readDiff(gitSpawnFn, input);
237
+ if ('reason' in diff) return settle(diff);
238
+ if (diff.text.trim().length === 0) return [];
239
+ return settle(
240
+ await reviewInTempDir(buildPrompt(input, diff.text), runDeps),
190
241
  );
191
- if (result.status !== 0) {
192
- logger?.warn?.(
193
- `[code-review] claude exited ${result.status}; emitting advisory.`,
194
- );
195
- return [
196
- advisory(
197
- 'Code review did not complete',
198
- `\`claude --print\` exited with status ${result.status}: ${
199
- result.stderr || result.stdout || '<no output>'
200
- }.`,
201
- ),
202
- ];
203
- }
204
- return parseFindings(result.stdout);
242
+ },
243
+ getDegradations() {
244
+ return degradations.map((d) => ({ ...d }));
205
245
  },
206
246
  };
207
247
  }
@@ -257,19 +257,38 @@ function baselinesEnvelopeGates(validationGates) {
257
257
  return out;
258
258
  }
259
259
 
260
+ /**
261
+ * `overridden` > `degraded` > `passed`: an override records the human
262
+ * decision on a failed review; `degraded` says a review surface produced no
263
+ * verdict (reported, not blocking — a secondary review does not gate merge).
264
+ *
265
+ * @param {object|null} reviewOverride
266
+ * @param {boolean} [reviewDegraded]
267
+ * @returns {'overridden'|'degraded'|'passed'}
268
+ */
269
+ function codeReviewGate(reviewOverride, reviewDegraded) {
270
+ if (reviewOverride) return 'overridden';
271
+ return reviewDegraded ? 'degraded' : 'passed';
272
+ }
273
+
260
274
  /**
261
275
  * @param {{ skipValidation?: boolean, skipSync?: boolean }} options
262
276
  * @param {Record<string, string>|null} validationGates
263
277
  * @param {object|null} reviewOverride
278
+ * @param {boolean} [reviewDegraded]
264
279
  * @returns {Record<string, string>}
265
280
  */
266
- function closeEnvelopeGates(options, validationGates, reviewOverride) {
281
+ function closeEnvelopeGates(
282
+ options,
283
+ validationGates,
284
+ reviewOverride,
285
+ reviewDegraded,
286
+ ) {
267
287
  return {
268
288
  validation: options.skipValidation ? 'skipped' : 'passed',
269
289
  ...baselinesEnvelopeGates(validationGates),
270
290
  baseSync: options.skipSync ? 'skipped' : 'passed',
271
- // The review did fail; the envelope records the human override.
272
- codeReview: reviewOverride ? 'overridden' : 'passed',
291
+ codeReview: codeReviewGate(reviewOverride, reviewDegraded),
273
292
  };
274
293
  }
275
294
 
@@ -466,7 +485,13 @@ async function openAndReviewPr(ctx, deps) {
466
485
  const reviewOverride = reviewOutcome.halted
467
486
  ? await resolveReviewHalt(ctx, deps, { prUrl, prNumber, reviewOutcome })
468
487
  : null;
469
- return { prUrl, prNumber, alreadyMerged: false, reviewOverride };
488
+ return {
489
+ prUrl,
490
+ prNumber,
491
+ alreadyMerged: false,
492
+ reviewOverride,
493
+ reviewDegraded: reviewOutcome.degraded === true,
494
+ };
470
495
  }
471
496
 
472
497
  async function releaseLease({ storyId }, deps) {
@@ -1181,6 +1206,7 @@ async function finishPhase(ctx, deps) {
1181
1206
  options,
1182
1207
  ctx.prePush.validationGates,
1183
1208
  ctx.pr.reviewOverride,
1209
+ ctx.pr.reviewDegraded,
1184
1210
  ),
1185
1211
  };
1186
1212
  if (!waitForMerge) {