Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/review on Codex with OpenAI models no longer holds back a review that ran its adversarial pass.** For OpenAI models, Codex encrypts the message it sends a new subagent, so the end-of-session check never saw the adversarial brief's text and blocked the session, then logged a miss. On Codex, a started subagent named `adversarial` whose message is encrypted now counts; a plaintext message still has to carry the brief, a differently named or failed subagent still doesn't count, and Claude Code's check is unchanged. The /review checklist on Codex now asks for that name.
4 changes: 2 additions & 2 deletions docs/skill-routing-and-contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ The hook reads `destructive_guard` every time it runs, so `gstack-config set des
**Contracts on Codex** use the same Stop hook, with the same one block per skill run, records and fail-open rules; Codex sends it the same `stop_hook_active` and `last_assistant_message` keys and takes the same block answer. The transcript is Codex's rollout file (`~/.codex/sessions/<yyyy>/<mm>/<dd>/rollout-*.jsonl`), and the checker tells it from a Claude Code transcript by what the file holds (a rollout starts with a `session_meta` record), never by its path. On Codex:

- A **load** is Codex injecting a `gstack-*` skill into the conversation as a `<skill>` message (the app server's skill input does this), or the model reading one with a shell command such as `cat ~/.codex/skills/gstack-review/SKILL.md`. `codex exec '$review ...'` also injects the skill as a `<skill>` message (codex-cli 0.170); a mention of the folder name instead of the listed name is plain text, so then the skill loads only when the model reads it.
- A **dispatch** is a call to Codex's own `spawn_agent` that started an agent: its result names an `agent_id` (the `multi_agent_v1` tools) or, when Codex serves the tool in its `collaboration` namespace (as it does for gpt-6.1-sol), a `task_name`. One that failed (its result names neither), or a tool of the same name from another namespace, doesn't count.
- A **dispatch** is a call to Codex's own `spawn_agent` that started an agent: its result names an `agent_id` (the `multi_agent_v1` tools) or, when Codex serves the tool in its `collaboration` namespace (as it does for gpt-6.1-sol), a `task_name`. One that failed (its result names neither), or a tool of the same name from another namespace, doesn't count. For OpenAI models Codex encrypts the message of a `collaboration` spawn (openai/codex#26210), so the brief's text is in neither rollout; an item with a `task_name` then counts a started spawn whose message is ciphertext and whose agent has that name (/review's adversarial pass is `adversarial`). A plaintext message is still held to `match`.
- **The contract** comes from gstack's own copy of the skill (`<gstack>/review/SKILL.md`), because Codex's installed `SKILL.md` keeps only its name and description.
- **/review's `specialists-dispatched` item is skipped**, because Codex doesn't run /review's specialist reviewers yet. The adversarial pass and the report are checked as on Claude Code, and the block text names `spawn_agent` and `wait_agent` where Claude Code's names an Agent dispatch.
- **A subagent's own rollout is never checked**: its first record names the parent thread.
Expand All @@ -121,7 +121,7 @@ Every item has an `id` (lowercase letters, digits, `.`, `_`, `-`) and a `kind`,
|---|---|---|
| `report_labels` | `heading`, `labels[]` | The last assistant message containing the heading has a `Label: value` line for every label, and no value is empty or a placeholder (`[...]`, `<...>`, TBD, TODO, `...`, or a template like `DONE \| BLOCKED`) |
| `selected_specialists_dispatched` | optional `marker`, `empty_marker` | The selection line was printed in an assistant message or a Bash result (never a fetched page or file), its names are plain (letters, digits, spaces, `_`, `.`, `-`, at most 40 characters), and each specialist it names has an Agent dispatch that mentions it. The marker is literal text in which a whole-word N stands for a number; the default is `Dispatching N specialists:`. N = 0 (`Dispatching 0 specialists: (small diff)`) or a "specialists skipped" line means zero specialists were selected, which passes. Text in parentheses is not a name (`Dispatching 1 specialists: State Machines (small diff)` selects State Machines) |
| `agent_dispatch` | `match` (regular expression, case-insensitive) | An Agent dispatch's description or prompt matches `match`. A `marker` is rejected until the checker can bind it to the dispatch it names (GST-1242) |
| `agent_dispatch` | `match` (regular expression, case-insensitive), optional `task_name` | An Agent dispatch's description or prompt matches `match`. On Codex only, a started `spawn_agent` whose message Codex encrypted counts when its agent is named `task_name` (lowercase letters, digits, `_`, `-`). A `marker` is rejected until the checker can bind it to the dispatch it names (GST-1242) |

There is no item for "run a test after your last edit". /verify asks for that in its text, and Opus 5.5 and GPT-6.1 Sol already did it in 96% and 89% of runs; a Stop-hook item for it added no measurable gain (gstack-evals#356), so it was removed. A contract that still lists `check_after_last_edit` keeps its other items. The checker skips that item and prints `SKILL_CONTRACT_SKIPPED <SKILL.md>: <item id>: ...` on stderr each time it reads the contract (the Stop hook and `check`). A contract whose only items use that kind is invalid.

Expand Down
29 changes: 21 additions & 8 deletions lib/codex-rollout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
* gpt-6.1-sol); a call with no namespace may carry either. One whose output
* names no id for its namespace (it failed, or it has no output), or a
* same-named tool in any other namespace, stays a plain spawn_agent call,
* so it is not a dispatch.
* so it is not a dispatch. The dispatch also carries the started agent's
* task name (the last part of its "/root/<name>" result, else the call's
* task_name), and sealed when its message is ciphertext: Codex encrypts the
* multi_agents_v2 message for OpenAI models (openai/codex#26210), so the
* brief's text is in neither rollout.
* - any other call: a tool_use under its own name. Call outputs are
* tool_results; a shell output that exited non-zero is an error.
* Records of other types (event_msg, turn_context, reasoning and the rest)
Expand All @@ -46,6 +50,7 @@ const READ_PROGRAM = /(?:^|[\s;|&(`'"])(?:cat|sed|head|tail|nl|less|more|bat|awk
const READ_FAILURE = /No such file|cannot open|can't read|cannot access|Permission denied|Is a directory|Cannot find path/i;
const SHELL_TOOLS = new Set(['exec_command', 'shell', 'shell_command', 'local_shell']);
const EXIT_CODE = /(?:^|\n)Process exited with code (\d+)/;
const CIPHERTEXT = /^gAAAAA[A-Za-z0-9_-]{20,}={0,2}$/;

/** Whether text is a Codex rollout: its first JSON object line is a session_meta record. */
export function isCodexRollout(text: string): boolean {
Expand Down Expand Up @@ -156,17 +161,18 @@ const exitedNonZero = (output: string | undefined) => {
return !!code && code[1] !== '0';
};

const startedAgent = (output: string | undefined, namespace: unknown) => {
if (output === undefined) return false;
/** A spawn_agent output that names the agent it started, for the call's namespace, or null. */
const startedAgent = (output: string | undefined, namespace: unknown): Record<string, any> | null => {
if (output === undefined) return null;
try {
const parsed: unknown = JSON.parse(output);
if (!isObject(parsed)) return false;
if (!isObject(parsed)) return null;
const ids = namespace === 'multi_agent_v1' ? [parsed.agent_id]
: namespace === 'collaboration' ? [parsed.task_name]
: namespace === undefined ? [parsed.agent_id, parsed.task_name] : [];
return ids.some(id => typeof id === 'string' && id !== '');
return ids.some(id => typeof id === 'string' && id !== '') ? parsed : null;
} catch {
return false;
return null;
}
};

Expand Down Expand Up @@ -228,6 +234,7 @@ export function parseCodexRollout(text: string): Transcript {
const id = String(p.call_id ?? '');
const input = args(p.type === 'custom_tool_call' ? { input: p.input } : p.arguments, line);
const command = SHELL_TOOLS.has(p.name) ? shellLine(input) : null;
const started = p.name === 'spawn_agent' ? startedAgent(outputs.get(id), p.namespace ?? undefined) : null;
if (command !== null) {
events.push({ kind: 'tool_use', line, id, name: 'Bash', input: { command } });
const reads = shellSkillReads(command);
Expand All @@ -237,10 +244,16 @@ export function parseCodexRollout(text: string): Transcript {
events.push({ kind: 'load', line, skill: read.skill, via: 'read' });
lastLoad = read.skill;
}
} else if (p.name === 'spawn_agent' && startedAgent(outputs.get(id), p.namespace ?? undefined)) {
} else if (started) {
const prompt = [input.message, ...(Array.isArray(input.items) ? input.items.map((i: unknown) => (isObject(i) ? i.text : undefined)) : [])]
.filter(v => typeof v === 'string').join('\n');
events.push({ kind: 'tool_use', line, id, name: 'Agent', input: { prompt, ...(typeof input.agent_type === 'string' ? { subagent_type: input.agent_type } : {}) } });
const taskName = [started.task_name, input.task_name].find(v => typeof v === 'string' && v !== '')?.split('/').pop();
events.push({ kind: 'tool_use', line, id, name: 'Agent', input: {
prompt,
...(typeof input.agent_type === 'string' ? { subagent_type: input.agent_type } : {}),
...(taskName ? { task_name: taskName } : {}),
...(typeof input.message === 'string' && CIPHERTEXT.test(input.message) ? { sealed: true } : {}),
} });
} else {
events.push({ kind: 'tool_use', line, id, name: p.name, input });
}
Expand Down
18 changes: 14 additions & 4 deletions lib/skill-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export interface ContractItem {
heading?: string;
labels?: string[];
match?: string;
/** agent_dispatch on Codex: the task name that stands in for match when Codex encrypted the spawn message. */
task_name?: string;
marker?: string;
empty_marker?: string;
fix?: string;
Expand Down Expand Up @@ -89,7 +91,8 @@ export function parseContract(frontmatter: string): { contract: Contract } | { e
return validateContract(isObject(doc) ? doc.contract : undefined);
}

const STRING_FIELDS = ['heading', 'match', 'marker', 'empty_marker', 'fix', 'summary'] as const;
const STRING_FIELDS = ['heading', 'match', 'task_name', 'marker', 'empty_marker', 'fix', 'summary'] as const;
const TASK_NAME = /^[a-z0-9][a-z0-9_-]{0,63}$/;
const REGEX_FIELDS = ['match'] as const;

/**
Expand Down Expand Up @@ -153,6 +156,8 @@ export function validateContract(raw: unknown): { contract: Contract } | { error
out.labels = item.labels.map((l: string) => l.trim());
}
if (out.kind === 'agent_dispatch' && !out.match) return { error: `${id}: agent_dispatch needs match` };
if (out.task_name !== undefined && out.kind !== 'agent_dispatch') return { error: `${id}: task_name applies only to agent_dispatch` };
if (out.task_name !== undefined && !TASK_NAME.test(out.task_name)) return { error: `${id}: task_name must match ${TASK_NAME}` };
if (out.kind === 'agent_dispatch' && out.marker) return { error: `${id}: agent_dispatch takes no marker until the checker can bind a marker to the dispatch it names (GST-1242)` };
items.push(out);
}
Expand Down Expand Up @@ -370,9 +375,14 @@ function checkItem(item: ContractItem, run: TranscriptEvent[], codex: boolean):
case 'agent_dispatch': {
const re = new RegExp(item.match as string, 'i');
if (codex) {
return agents.some(a => re.test(agentText(a)))
? { met: true, detail: `a spawn_agent call matches /${item.match}/`, fix: '' }
: { met: false, detail: `no spawn_agent call matches /${item.match}/`, fix: item.fix ?? `start the subagent pass matching /${item.match}/ with spawn_agent, then wait_agent for its result` };
if (agents.some(a => re.test(agentText(a)))) return { met: true, detail: `a spawn_agent call matches /${item.match}/`, fix: '' };
if (item.task_name && agents.some(a => a.input.sealed === true && a.input.task_name === item.task_name)) {
return { met: true, detail: `spawn_agent started ${item.task_name} with an encrypted message`, fix: '' };
}
const fix = item.task_name
? `start the subagent pass with spawn_agent (task_name "${item.task_name}", its message matching /${item.match}/), then wait_agent for its result`
: `start the subagent pass matching /${item.match}/ with spawn_agent, then wait_agent for its result`;
return { met: false, detail: `no spawn_agent call matches /${item.match}/`, fix: item.fix ?? fix };
}
return agents.some(a => re.test(agentText(a)))
? { met: true, detail: `an Agent dispatch matches /${item.match}/`, fix: '' }
Expand Down
14 changes: 3 additions & 11 deletions review/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,9 @@ triggers:
contract:
version: 1
items:
- id: specialists-dispatched
kind: selected_specialists_dispatched
marker: "Dispatching N specialists:"
- id: adversarial-pass
kind: agent_dispatch
match: Think like an attacker and a chaos engineer
- id: review-report
kind: report_labels
heading: Pre-Landing Review
labels:
- Gate edits
- { id: specialists-dispatched, kind: selected_specialists_dispatched, marker: "Dispatching N specialists:" }
- { id: adversarial-pass, kind: agent_dispatch, match: Think like an attacker and a chaos engineer, task_name: adversarial }
- { id: review-report, kind: report_labels, heading: Pre-Landing Review, labels: [Gate edits] }
---
<!-- AUTO-GENERATED from SKILL.md.tmpl — do not edit directly -->
<!-- Regenerate: bun run gen:skill-docs -->
Expand Down
14 changes: 3 additions & 11 deletions review/SKILL.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,9 @@ triggers:
contract:
version: 1
items:
- id: specialists-dispatched
kind: selected_specialists_dispatched
marker: "Dispatching N specialists:"
- id: adversarial-pass
kind: agent_dispatch
match: Think like an attacker and a chaos engineer
- id: review-report
kind: report_labels
heading: Pre-Landing Review
labels:
- Gate edits
- { id: specialists-dispatched, kind: selected_specialists_dispatched, marker: "Dispatching N specialists:" }
- { id: adversarial-pass, kind: agent_dispatch, match: Think like an attacker and a chaos engineer, task_name: adversarial }
- { id: review-report, kind: report_labels, heading: Pre-Landing Review, labels: [Gate edits] }
---

{{CONTRACT_DONE_MEANS}}
Expand Down
20 changes: 13 additions & 7 deletions scripts/resolvers/contract-done-means.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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 };
| { id: string; kind: 'agent_dispatch'; match: string; task_name?: string };

export interface SkillContract {
version: 1;
Expand All @@ -29,6 +29,7 @@ const KIND_FIELDS: Record<ContractItem['kind'], string[]> = {
selected_specialists_dispatched: ['marker'],
agent_dispatch: ['match'],
};
const OPTIONAL_FIELDS: Partial<Record<ContractItem['kind'], string[]>> = { 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 }>> = {
Expand Down Expand Up @@ -67,11 +68,14 @@ export function parseSkillContract(value: unknown, where: string): SkillContract
if (seen.has(raw.id)) fail(where, at + ' duplicate id "' + raw.id + '"');
seen.add(raw.id);
for (const key of Object.keys(raw)) {
if (key !== 'id' && key !== 'kind' && !KIND_FIELDS[kind].includes(key)) fail(where, at + ' (' + kind + ') has unknown key "' + key + '"');
if (key !== 'id' && key !== 'kind' && !KIND_FIELDS[kind].includes(key) && !OPTIONAL_FIELDS[kind]?.includes(key)) fail(where, at + ' (' + kind + ') has unknown key "' + key + '"');
}
for (const field of KIND_FIELDS[kind]) {
if (field !== 'labels' && !isText(raw[field])) fail(where, at + ' ' + field + ' must be a non-empty string');
}
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 (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[]) {
Expand Down Expand Up @@ -102,26 +106,28 @@ export function contractFromTemplate(tmplContent: string, where: string, opts: {

const list = (xs: string[]) => xs.length < 2 ? xs.join('') : xs.slice(0, -1).join(', ') + ' and ' + xs[xs.length - 1];

function plainWords(item: ContractItem): string {
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 'agent_dispatch': return 'an Agent dispatch for the ' + item.id.replace(/-/g, ' ') + ', its prompt including "' + item.match + '"';
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 + '"';
}
}

/** Whether bin/gstack-skill-contract ships. The PR that adds it flips this, regenerates and re-pins; test/skill-descriptions.test.ts fails while the two disagree. */
export const CONTRACT_CHECKER_SHIPPED = true;

/** The list; checker adds the check and waive commands (run through the host's binDir), which only a tree that ships the checker may mention. */
export function renderDoneMeans(contract: SkillContract, binDir: string, checker = CONTRACT_CHECKER_SHIPPED): string {
export function renderDoneMeans(contract: SkillContract, binDir: string, checker = CONTRACT_CHECKER_SHIPPED, host = 'claude'): string {
if (contract.items.length === 0) return '';
return [
'## Done means',
'',
'Finish only when each of these exists (contract v1):',
'',
...contract.items.map(item => '- ' + code(item.id) + ': ' + plainWords(item) + '.'),
...contract.items.map(item => '- ' + code(item.id) + ': ' + plainWords(item, host) + '.'),
...(checker ? ['', code(binDir + '/gstack-skill-contract check') + ' reads them from the transcript (docs/skill-routing-and-contracts.md). ' +
'For an item that truly does not apply, run ' + code(binDir + '/gstack-skill-contract waive <item> --reason "<why>"') + ' (this session only; it counts as a miss).'] : []),
].join('\n');
Expand All @@ -135,5 +141,5 @@ export function generateContractDoneMeans(ctx: TemplateContext): string {
const backing = BACKED_BY[item.kind];
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);
return renderDoneMeans({ ...contract, items: contract.items.filter(shown) }, ctx.paths.binDir, CONTRACT_CHECKER_SHIPPED, ctx.host);
}
Loading
Loading