mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-29 19:34:29 +01:00
/review now always runs its Codex second-model review and the Red Team on large diffs (GST-4097) (#4870)
`/review` now always runs its Codex second-model review when Codex is ready, runs the Red Team on diffs over 200 lines, and a headless session can no longer end while its background reviewers are still running. Why: in a recent headless eval, Claude Opus skipped both steps in every run because `/review` called the Codex pass optional and its end-of-skill check never looked for either. Nothing to do: Codex users get the extra review automatically; a missing or disabled Codex is still a recorded skip. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=testing Review-Finding: p1/red-team#1 reader=red-team Review-Finding: p2/outside-voice#1 reader=outside-voice Review-Finding: p2/outside-voice#2 reader=outside-voice Review-Finding: p2/outside-voice#3 reader=outside-voice Review-Finding: p2/outside-voice#4 reader=outside-voice Review-Finding: p2/outside-voice#5 reader=outside-voice Review-Finding: p2/adversarial-native#1 reader=adversarial-native Review-Finding: p2/adversarial-native#3 reader=adversarial-native Review-Finding: p2/adversarial-native#4 reader=adversarial-native Review-Finding: p2/adversarial-native#5 reader=adversarial-native Review-Finding: p2/adversarial-native#6 reader=adversarial-native Review-Finding: p2/specialist-batched#1 reader=security Review-Finding: p2/specialist-batched#2 reader=testing Review-Finding: p2/red-team#1 reader=red-team Review-Finding: p2/red-team#2 reader=red-team Review-Finding: p2/red-team#3 reader=red-team Review-Finding: p2/red-team#4 reader=red-team
This commit is contained in:
1 parent
bbe63d1de3
commit
3af268b2b6
36 files changed
+778
-145
No files matched your search
@@ -10,14 +10,16 @@ import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import type { TemplateContext } from './types';
|
||||
import { getHostConfig } from '../../hosts/index';
|
||||
import { outsideVoiceFor } from './outside-voice';
|
||||
|
||||
const ROOT = path.resolve(import.meta.dir, '..', '..');
|
||||
const code = (s: string) => '\u0060' + s + '\u0060';
|
||||
|
||||
export type ContractItem =
|
||||
| { id: string; kind: 'report_labels'; heading: string; labels: string[] }
|
||||
| { id: string; kind: 'selected_specialists_dispatched'; marker: string }
|
||||
| { id: string; kind: 'agent_dispatch'; match: string; task_name?: string };
|
||||
| { id: string; kind: 'selected_specialists_dispatched'; marker: string; large_diff?: { marker: string; over: number; names: string[] } }
|
||||
| { id: string; kind: 'agent_dispatch'; match: string; task_name?: string }
|
||||
| { id: string; kind: 'outside_voice'; pass: string };
|
||||
|
||||
export interface SkillContract {
|
||||
version: 1;
|
||||
@@ -28,13 +30,15 @@ const KIND_FIELDS: Record<ContractItem['kind'], string[]> = {
|
||||
report_labels: ['heading', 'labels'],
|
||||
selected_specialists_dispatched: ['marker'],
|
||||
agent_dispatch: ['match'],
|
||||
outside_voice: ['pass'],
|
||||
};
|
||||
const OPTIONAL_FIELDS: Partial<Record<ContractItem['kind'], string[]>> = { agent_dispatch: ['task_name'] };
|
||||
const OPTIONAL_FIELDS: Partial<Record<ContractItem['kind'], string[]>> = { selected_specialists_dispatched: ['large_diff'], agent_dispatch: ['task_name'] };
|
||||
|
||||
// The resolver and section that render the step each kind checks today. A host that suppresses the resolver, or a loadout that excludes the section, never shows that step, so its items are left out of the list there.
|
||||
export const BACKED_BY: Partial<Record<ContractItem['kind'], { resolver: string; section: string }>> = {
|
||||
selected_specialists_dispatched: { resolver: 'REVIEW_ARMY', section: 'review-army' },
|
||||
agent_dispatch: { resolver: 'ADVERSARIAL_STEP', section: 'adversarial' },
|
||||
outside_voice: { resolver: 'ADVERSARIAL_STEP', section: 'adversarial' },
|
||||
};
|
||||
|
||||
const PLACEHOLDER = /^\[.*\]$|^<.*>$|^\.\.\.$|^(todo|tbd|n\/a)$/i;
|
||||
@@ -76,6 +80,13 @@ export function parseSkillContract(value: unknown, where: string): SkillContract
|
||||
if (raw.task_name !== undefined && (typeof raw.task_name !== 'string' || !/^[a-z0-9][a-z0-9_-]{0,63}$/.test(raw.task_name))) {
|
||||
fail(where, at + ' task_name must be lowercase letters, digits, _ or -, got ' + JSON.stringify(raw.task_name));
|
||||
}
|
||||
if (raw.large_diff !== undefined) {
|
||||
const ld = raw.large_diff;
|
||||
if (!isMap(ld) || !isText(ld.marker) || !/\bN\b/.test(ld.marker) || !Number.isInteger(ld.over) || (ld.over as number) < 0 ||
|
||||
!Array.isArray(ld.names) || ld.names.length === 0 || !ld.names.every(isText)) {
|
||||
fail(where, at + ' large_diff must be { marker: "<text with N>", over: <integer>, names: [<specialist>, ...] }');
|
||||
}
|
||||
}
|
||||
if (kind === 'report_labels') {
|
||||
if (!Array.isArray(raw.labels) || raw.labels.length === 0) fail(where, at + ' labels must be a non-empty list');
|
||||
for (const label of raw.labels as unknown[]) {
|
||||
@@ -109,7 +120,9 @@ const list = (xs: string[]) => xs.length < 2 ? xs.join('') : xs.slice(0, -1).joi
|
||||
function plainWords(item: ContractItem, host: string): string {
|
||||
switch (item.kind) {
|
||||
case 'report_labels': return 'a ' + code(item.heading) + ' with ' + list(item.labels) + ' filled in (' + code('none: <why>') + ' where the skill\'s own stop rule leaves one empty)';
|
||||
case 'selected_specialists_dispatched': return 'the specialist selection printed (' + code(item.marker) + ' ...), then one Agent dispatch per specialist it names (none when a small diff skips them)';
|
||||
case 'selected_specialists_dispatched': return 'the specialist selection printed (' + code(item.marker) + ' ...), then one Agent dispatch per specialist it names (none when a small diff skips them)' +
|
||||
(item.large_diff ? ', plus ' + list(item.large_diff.names.map(code)) + ' when Bash prints ' + code(item.large_diff.marker) + ' over ' + item.large_diff.over : '');
|
||||
case 'outside_voice': return 'Step 4.8\'s ' + code('gstack-outside-voice --pass ' + item.pass) + ' status, or a non-ready ' + code('CODEX_MODE:');
|
||||
case 'agent_dispatch': return host === 'codex' && item.task_name
|
||||
? 'a ' + code('spawn_agent') + ' (' + code('task_name: ' + item.task_name) + '), its prompt including "' + item.match + '"'
|
||||
: 'an Agent dispatch for the ' + item.id.replace(/-/g, ' ') + ', its prompt including "' + item.match + '"';
|
||||
@@ -139,6 +152,7 @@ export function generateContractDoneMeans(ctx: TemplateContext): string {
|
||||
const suppressed = new Set(getHostConfig(ctx.host).suppressedResolvers ?? []);
|
||||
const shown = (item: ContractItem) => {
|
||||
const backing = BACKED_BY[item.kind];
|
||||
if (item.kind === 'outside_voice' && outsideVoiceFor(ctx).id !== 'codex') return false;
|
||||
return !backing || (!suppressed.has(backing.resolver) && !ctx.modules?.excluded.has('section:' + ctx.skillName + '/' + backing.section));
|
||||
};
|
||||
return renderDoneMeans({ ...contract, items: contract.items.filter(shown) }, ctx.paths.binDir, CONTRACT_CHECKER_SHIPPED, ctx.host);
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
import { toShellPath, type TemplateContext } from './types';
|
||||
import { CC_BACKGROUND_DEFAULT_SINCE, FOREGROUND_IF_AVAILABLE, BACKGROUND_RECOVERY } from './constants';
|
||||
import { CODEX_SUBAGENT_DISPATCH } from '../../hosts/codex';
|
||||
import { outsideVoiceFailurePolicy, outsideVoiceFor, outsideVoiceInvocation, outsideVoicePreflight, outsideVoiceProvenance, OUTSIDE_VERDICT_REQUEST } from './outside-voice';
|
||||
import { outsideVoiceFailurePolicy, outsideVoiceFor, outsideVoiceHelperInvocation, outsideVoiceInvocation, outsideVoicePreflight, outsideVoiceProvenance, OUTSIDE_VERDICT_REQUEST } from './outside-voice';
|
||||
import { runtimeRootPrelude } from './runtime-root';
|
||||
import { DEFENSIVE_REVIEW_FRAMING, fixtureSummaryMode } from './defensive-review';
|
||||
import { BLOCKING_FLOOR } from '../../lib/review-scope';
|
||||
@@ -153,11 +153,11 @@ Outside prompt (supply repository context from the parent):
|
||||
|
||||
"${CODEX_BOUNDARY}Review the changes on this branch against the base branch. Use the supplied branch diff. If it was not supplied and you have repository tools, run DIFF_BASE=$(git merge-base origin/<base> HEAD) && git diff "$DIFF_BASE". Your job is to find ways this code will fail in production. Think like an attacker and a chaos engineer. Find edge cases, race conditions, security holes, resource leaks, failure modes, and silent data corruption paths. Be adversarial. Be thorough. No compliments — just the problems. A finding blocks only if it ${BLOCKING_FLOOR}; end each finding with \`Severity: Critical|High|Medium|Low\` and \`Blocks: yes|no\`. Then write ONE line in the canonical format \`Recommendation: <action> because <one-line reason naming the most exploitable finding>\`. Generic reasons like 'because it's safer' do not qualify; the reason must point to a specific finding or no-fix rationale. ${OUTSIDE_VERDICT_REQUEST}"
|
||||
|
||||
${outsideVoiceInvocation(ctx, { timeoutMs: 540000, nativeAlreadyRequired: isShip ? 'dispatched' : true, diffCommand: 'DIFF_BASE=$(git merge-base origin/<base> HEAD) && git diff "$DIFF_BASE"' })}
|
||||
${!isShip && outsideVoiceFor(ctx).id === 'codex' ? outsideVoiceHelperInvocation(ctx, { pass: 'adversarial', gate: 'review' }) : outsideVoiceInvocation(ctx, { timeoutMs: 540000, nativeAlreadyRequired: isShip ? 'dispatched' : true, diffCommand: 'DIFF_BASE=$(git merge-base origin/<base> HEAD) && git diff "$DIFF_BASE"' })}
|
||||
|
||||
Present the full output verbatim. A Critical, High or \`Blocks: yes\` finding is CRITICAL; \`Blocks: no\` never lowers one, and only a named policy ground drops it. ${isShip ? 'An unavailable outside challenge does not block shipping by itself; supported findings still enter Step 11, and the structured P0/P1 and non-convergence gates still apply.' : 'This outside challenge is informational; supported findings still enter Step 5 Fix-First, whose approval and convergence gates apply.'}
|
||||
|
||||
**Error handling:** Only this optional outside adversarial pass is non-blocking; native completion and structured-review decisions still apply.
|
||||
**Error handling:** ${isShip ? 'Only this optional outside adversarial pass is non-blocking' : 'Only this outside adversarial pass is non-blocking: it must run, and a failed run is missing coverage'}; native completion and structured-review decisions still apply.
|
||||
${outsideVoiceFailurePolicy(ctx, { timeoutMinutes: 9, onTimeout: 'missing-coverage', stderrOnEmpty: true, fallback: 'none', escape: 1 })}
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ function adversarialStructuredReview(ctx: TemplateContext, isShip: boolean): str
|
||||
|
||||
${isShip ? 'On \`DISPATCH: outside-voice\`, if' : 'If'} \`CODEX_MODE\` is \`ready\` or \`unverified\` and either \`DIFF_TOTAL >= 200\` or the user requested the override above:
|
||||
|
||||
${outsideVoiceInvocation(ctx, { timeoutMs: 540000, nativeAlreadyRequired: isShip ? 'dispatched' : true, gate: 'structured', diffCommand: 'DIFF_BASE=$(git merge-base <base> HEAD) && git diff "$DIFF_BASE"' })}
|
||||
${!isShip && outsideVoiceFor(ctx).id === 'codex' ? outsideVoiceHelperInvocation(ctx, { pass: 'structured', gate: 'structured', appendDiffBase: '<base>' }) : outsideVoiceInvocation(ctx, { timeoutMs: 540000, nativeAlreadyRequired: isShip ? 'dispatched' : true, gate: 'structured', diffCommand: 'DIFF_BASE=$(git merge-base <base> HEAD) && git diff "$DIFF_BASE"' })}
|
||||
|
||||
${outsideVoiceFor(ctx).id === 'codex' ? '' : 'The Claude Code backend receives the parent-captured base diff, including committed and working-tree changes, because review mode cannot execute git.\n\n'}Present output under \`${outsideVoiceFor(ctx).label.toUpperCase()} SAYS (code review):\` inside a \`tool-output\` fence.
|
||||
Only a completed response ending with its \`VERDICT:\` line establishes the gate. P0/P1 findings (\`[P0]\`/\`[P1]\` or native \`P0:\`/\`P1:\` labels; \`VERDICT: findings\`) → GATE: FAIL. Completed without P0/P1 → GATE: PASS. Refusal, failure, missing markers or \`OUTSIDE_STATUS: unverified\` → GATE: MISSING COVERAGE; no fix question.
|
||||
@@ -241,7 +241,7 @@ export function generateAdversarialStep(ctx: TemplateContext): string {
|
||||
|
||||
return `## Step ${stepNum}: Adversarial review${isShip ? '' : ' (always-on)'}
|
||||
|
||||
${isShip ? 'Unavailable' : `Every diff gets the ${outsideVoiceFor(ctx).nativeLabel} adversarial pass. Add ${outsideVoiceFor(ctx).label} when its preflight is ready; unavailable`} or disabled outside coverage stays explicit.
|
||||
${isShip ? 'Unavailable' : `Every diff gets the ${outsideVoiceFor(ctx).nativeLabel} adversarial pass and, whenever its preflight is ready or unverified, the ${outsideVoiceFor(ctx).label} second-model review; both are required. Unavailable`} or disabled outside coverage stays explicit.
|
||||
|
||||
**Detect diff size:**
|
||||
|
||||
@@ -314,7 +314,7 @@ in order before leaving Step 11:
|
||||
ahead of the remaining items. These fresh reviews after code edits are not recovery retries.
|
||||
Returning here never resets Step 9's three-cycle fix limit (under \`frozen\`, the plan's cap).
|
||||
3. **Native complete with no queued fixes, or not dispatched:** Finish the memory updates below,
|
||||
then continue to Step 11.5. Never jump directly to release preparation.` : 'The native pass is required for Step 5.8 completion. Optional outside failures remain separately recorded, not completed by native coverage. Return all findings and structured-review decisions to Step 5; the parent owns fixes and the full rerun.'}
|
||||
then continue to Step 11.5. Never jump directly to release preparation.` : 'The native pass is required for Step 5.8 completion. Outside failures remain separately recorded, not completed by native coverage. Return all findings and structured-review decisions to Step 5; the parent owns fixes and the full rerun.'}
|
||||
|
||||
---`;
|
||||
}
|
||||
|
||||
@@ -190,6 +190,28 @@ ${outsideVoiceCommand(ctx, opts)}
|
||||
Use Bash \`timeout: ${gateMs}\`; show the full response in a \`tool-output\` fence. Require successful execution and valid markers. Refusal, empty/malformed output, missing ${planRecommendation ? 'Recommendation: <action> because <reason>' : opts.purpose === 'design-direction' ? 'Recommendation' : 'score/severity/completion'} markers, timeout or CLI failure means \`outside_status: unavailable\`. P0/P1 findings block like native ones; \`OUTSIDE_STATUS: unverified\` is missing coverage. ${opts.purpose === 'design-direction' ? 'Continue completed proposals; native completion does not count as outside coverage.' : opts.nativeAlreadyRequired === 'dispatched' ? 'A dispatched native pass runs once either way; outside output cannot complete it.' : opts.nativeAlreadyRequired ? 'Retain the required native pass without duplicating it; it cannot complete outside coverage.' : "Use the caller's fallback; missing coverage is never clean/PASS."} After either outcome, ${planPrompt ? "run `rm -- '<prepared-prompt-file>'`" : 'delete only your private prompt'}; scratch cleanup is automatic.`;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Codex passes of standalone /review run through bin/gstack-outside-voice (GEVA-590): one command whose tool prints
|
||||
* `OUTSIDE_STATUS: <status> ... pass=<pass>` on every outcome, so a model that rewrites the shell cannot drop the line
|
||||
* /review's Stop-hook contract (item outside-voice) reads from the Bash result.
|
||||
*/
|
||||
export function outsideVoiceHelperInvocation(ctx: TemplateContext, opts: { pass: 'adversarial' | 'structured'; gate: 'review' | 'structured'; appendDiffBase?: string }): string {
|
||||
const bin = toShellPath(ctx.paths.binDir);
|
||||
const completion = opts.gate === 'structured'
|
||||
? `Put the filesystem boundary first. Request [P0]-[P3] severity tags and ${VERDICT_LAST_LINE}.`
|
||||
: `Request severity (Critical, High, Medium or Low) per finding, a Recommendation: <action> because <reason> line, and ${VERDICT_LAST_LINE}.`;
|
||||
const run = `"${bin}/gstack-outside-voice" run --runner codex-cli --pass ${opts.pass} --gate ${opts.gate} --effort high --timeout-ms ${OUTSIDE_GATE_MAX_MS - OUTSIDE_CLEANUP_MS} --show${opts.appendDiffBase ? ` --append-diff ${opts.appendDiffBase}` : ''} --prompt '<prepared-prompt-file>' --out "$_OUTSIDE_TMP/review.md"`;
|
||||
return `Write the **complete prompt and context**, including actual plan/spec/source, to a private file. Substitute its shell-quoted path for \`<prepared-prompt-file>\`; never interpolate user text into shell source. ${completion}
|
||||
|
||||
Run this block unchanged and never call \`codex\` yourself: \`gstack-outside-voice\` runs Codex, prints the review, \`VERDICT:\` and \`FINDINGS:\`, and on every outcome ends with its own \`OUTSIDE_STATUS: <status> ... pass=${opts.pass}\` line, the record the Stop check reads.
|
||||
|
||||
\`\`\`bash
|
||||
${[runtimeRootPrelude(ctx), outsideVoiceGuard(ctx), '_OUTSIDE_TMP=$(mktemp -d "${TMPDIR:-/tmp}/gstack-outside.XXXXXXXX") || exit 1', 'trap \'rm -r "$_OUTSIDE_TMP"\' EXIT', run].filter(Boolean).join('\n')}
|
||||
\`\`\`
|
||||
|
||||
Use Bash \`timeout: ${OUTSIDE_GATE_MAX_MS}\` in the foreground, never \`run_in_background\`; show the full response in a \`tool-output\` fence. Only \`OUTSIDE_STATUS: completed\` is outside coverage; \`unverified\` is missing coverage, and any other status (refusal, empty or malformed output, timeout, CLI failure) means \`outside_status: unavailable\` for the reason it names. P0/P1 findings block like native ones. Retain the required native pass without duplicating it; it cannot complete outside coverage. After either outcome, delete only your private prompt; scratch cleanup is automatic.`;
|
||||
}
|
||||
|
||||
/**
|
||||
* outsideVoiceFailurePolicy owns the auth / timeout / empty-response / fallback
|
||||
* bullets every outside-voice step renders after its invocation (moved from
|
||||
|
||||
@@ -85,7 +85,8 @@ For each conditional specialist that passed scope gating, read the \`gstack-spec
|
||||
**Force flags:** \`--<specialist>\` (e.g. \`--simplification\`) or \`--all-specialists\` in the prompt force-includes it.
|
||||
|
||||
Print the selection:
|
||||
"Dispatching N specialists: [names]. Skipped: [names] (scope not detected). Gated: [names] (0 findings in N+ reviews)."`;
|
||||
"Dispatching N specialists: [names]. Skipped: [names] (scope not detected). Gated: [names] (0 findings in N+ reviews)."${isShip ? '' : `
|
||||
Only names go on that line. When DIFF_LINES > 200, name \`red-team\` there too (it counts in N) and dispatch it after the others return, as Red Team dispatch below says.`}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user