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
36 changes: 36 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,42 @@ gh workflow disable eval-refresh.yml # stops the cron and dispatch
gh workflow enable eval-refresh.yml # both again
```

### Before dispatching a matrix

Run the preflight, with the same inputs the dispatch will take, from a checkout of `main`:

```bash
pnpm preflight --suite benchmark --experiment-suite benchmark,no-skills --runs 3
pnpm preflight --help # every flag, and the check ids --skip takes
pnpm -s preflight --json # -s keeps pnpm's banner out of the JSON
```

Every defect v0.5.0 found was discoverable before the run that found it (#131), and
a matrix costs about $100 and six hours. The preflight takes minutes. It is read-only
apart from one real completion per provider, the same request the workflow's own
preflight makes.

- **Assertions fail the script.** Do not dispatch on a non-zero exit. Spend needs
`--confirm-balance` (or a `y` on a terminal) because no provider exposes a balance
to a project key. Open `harness` issues need `--accept-harness <numbers>`, so each
one is accepted for the run by name.
- **Decisions never fail it.** A CLI pin behind `latest` (Hookdeck, skills or an
agent's), a skills pin behind `main`, a model with a newer sibling, a changed base
prompt: each prints the current and the latest, and the release notes record what
was chosen.
- **A moved instrument needs a canary.** When the image definition, a CLI pin or a
model differs from what the newest published cells of that agent ran under, it
prints the two-cell `gh workflow run` command with `EVALS_PUBLISH=false`. Per
agent, not per snapshot: a Claude-only partial publish says nothing about the image
Codex last ran on. Verify the finished run with `--canary-run <id>` before the
matrix.
- **`--skip <id>` is an escape hatch, not a pass.** The report prints skipped checks
as a banner. Name them in the release notes.

It reads `.env` for the provider and project keys, so it checks your keys, not the
repository secrets. It checks those by name only, and the workflow checks their
liveness before its matrix.

## What to work on next

**GitHub Issues is the source of truth for work, and #24 is the order to do it
Expand Down
37 changes: 2 additions & 35 deletions apps/framework/harness/run-eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import {
scenarioFingerprint,
skillsPin,
} from '../lib/provenance.js';
import { basePromptFor } from '../lib/base-prompt.js';

const __dirname = dirname(fileURLToPath(import.meta.url));
const ROOT = join(__dirname, '..', '..', '..');
Expand Down Expand Up @@ -370,41 +371,7 @@ function copyWithheldTests(ev: EvalManifest, workspace: string) {
}
}

/**
* The base prompt is a treatment, not neutral scaffolding.
*
* The last sentence was added on 27 August, borrowed verbatim from
* [clerk/clerk-evals](https://github.com/clerk/clerk-evals), which prepends the
* same line to every eval prompt on its agentic path — the closest architectural
* match to ours, running the same two agent CLIs.
*
* It exists because this benchmark is single-turn: a question gets no reply, and
* the agent is scored on whatever state it left, usually nothing. Four cells in
* the stored runs ended that way, against a skills delta measured at two cells in
* twenty-four, so the noise was larger than the signal it sat next to.
*
* **This is not a claim that asking is wrong.** τ-bench's airline policy requires
* an agent to "list the action details and obtain explicit user confirmation
* (yes) to proceed" before any action that updates the booking database — the
* behaviour penalised here is a *pass requirement* there, because that harness
* has a user to answer. Ours does not. So the line is a property of our
* instrument, and a cell that trips `ASKED_AND_STOPPED` must never be published
* as a capability failure. See the survey on hookdeck/evals#57 for the full
* option space; four other benchmarks answer this four different ways.
*
* Everything measured before this date was measured without it, so results
* either side are not comparable — the same rule as a scenario or CLI change,
* and for the same reason.
*/
function basePromptFor(_mode: EvalMode): string {
return (
'You are an agent working on a real Hookdeck project, as a developer would. ' +
'Use the provided tools to inspect and change the project. ' +
'When you are done, end your turn with a short summary of what you did ' +
'(or for investigation tasks, your findings). ' +
'Do not ask clarifying questions. Complete the task with the information provided.'
);
}
// `basePromptFor` lives in `../lib/base-prompt.ts`; see the note there.

function buildSystemPrompt(
mode: EvalMode,
Expand Down
70 changes: 70 additions & 0 deletions apps/framework/lib/base-prompt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import type { EvalMode } from '../harness/types.js';

/**
* The base prompt is a treatment, not neutral scaffolding.
*
* The last sentence was added on 27 August, borrowed verbatim from
* [clerk/clerk-evals](https://github.com/clerk/clerk-evals), which prepends the
* same line to every eval prompt on its agentic path — the closest architectural
* match to ours, running the same two agent CLIs.
*
* It exists because this benchmark is single-turn: a question gets no reply, and
* the agent is scored on whatever state it left, usually nothing. Four cells in
* the stored runs ended that way, against a skills delta measured at two cells in
* twenty-four, so the noise was larger than the signal it sat next to.
*
* **This is not a claim that asking is wrong.** τ-bench's airline policy requires
* an agent to "list the action details and obtain explicit user confirmation
* (yes) to proceed" before any action that updates the booking database — the
* behaviour penalised here is a *pass requirement* there, because that harness
* has a user to answer. Ours does not. So the line is a property of our
* instrument, and a cell that trips `ASKED_AND_STOPPED` must never be published
* as a capability failure. See the survey on hookdeck/evals#57 for the full
* option space; four other benchmarks answer this four different ways.
*
* Everything measured before this date was measured without it, so results
* either side are not comparable — the same rule as a scenario or CLI change,
* and for the same reason.
*
* Lives here rather than in `run-eval.ts` so `preflight` can read the prompt a
* dispatch would use without importing the runner, which executes on import.
* Keep it a single `return` of concatenated string literals:
* `extractBasePrompt` reads it back out of the source at an earlier release,
* where it may still be in `run-eval.ts`.
*/
export function basePromptFor(_mode: EvalMode): string {
return (
'You are an agent working on a real Hookdeck project, as a developer would. ' +
'Use the provided tools to inspect and change the project. ' +
'When you are done, end your turn with a short summary of what you did ' +
'(or for investigation tasks, your findings). ' +
'Do not ask clarifying questions. Complete the task with the information provided.'
);
}

/**
* The base prompt as written in a source file, or undefined when the file has
* no `basePromptFor`.
*
* For comparing against a release, where the function may sit in a different
* file. Reads the string literals of its `return` and joins them, which is what
* the concatenation evaluates to, so a reflowed line does not read as a change.
*/
export function extractBasePrompt(source: string): string | undefined {
const start = source.search(/function\s+basePromptFor\s*\(/);
if (start < 0) return undefined;
const body = source.slice(start);
const ret = body.search(/\breturn\b/);
if (ret < 0) return undefined;
// The function's closing brace, at the start of a line. Not the first `;`,
// which a prompt is free to contain.
const end = body.indexOf('\n}', ret);
const expression = body.slice(ret, end < 0 ? undefined : end);
const literals = [
...expression.matchAll(/'((?:[^'\\]|\\.)*)'|"((?:[^"\\]|\\.)*)"/g),
];
if (literals.length === 0) return undefined;
return literals
.map((m) => (m[1] ?? m[2] ?? '').replace(/\\(.)/g, '$1'))
.join('');
}
175 changes: 175 additions & 0 deletions apps/framework/lib/preflight/args.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import { readRepeatedFlag } from '../cli-args.js';
import { DISPATCH_DEFAULTS, type DispatchInputs } from './matrix.js';

/**
* Every check, by the id `--skip` takes and its number in #131. The canary is
* the requirement #131 attaches to checks 1, 2 and 4, numbered after them. The
* skills CLI pin is a sixteenth decision #131 did not list: it is a build arg
* of the same image as the Hookdeck CLI, and nothing compared it either.
*/
export const CHECKS = [
{ number: 1, id: 'hookdeck-cli-pin', title: 'Hookdeck CLI pin' },
{ number: 2, id: 'agent-cli-pins', title: 'Agent CLI pins' },
{ number: 3, id: 'skills-pin', title: 'Skills pin' },
{ number: 4, id: 'model-ids', title: 'Model IDs' },
{ number: 5, id: 'base-prompt', title: 'Base prompt' },
{ number: 6, id: 'provider-keys', title: 'Provider keys work' },
{ number: 7, id: 'spend', title: 'Spend' },
{ number: 8, id: 'secrets', title: 'Secrets' },
{ number: 9, id: 'main-green', title: 'Main is green' },
{ number: 10, id: 'nothing-running', title: 'Nothing else is running' },
{ number: 11, id: 'repo-variables', title: 'Repository variables' },
{ number: 12, id: 'projects-pristine', title: 'Projects are pristine' },
{ number: 13, id: 'skill-links', title: 'Skill links resolve' },
{ number: 14, id: 'harness-issues', title: 'Open harness issues' },
{ number: 15, id: 'canary', title: 'Canary' },
{ number: 16, id: 'skills-cli-pin', title: 'Skills CLI pin' },
] as const;

export type CheckId = (typeof CHECKS)[number]['id'];

export interface PreflightArgs {
json: boolean;
help: boolean;
skip: CheckId[];
confirmBalance: boolean;
dispatch: DispatchInputs;
/** What `EVALS_PUBLISH` should be for this run: publish unless held. */
holdPublish: boolean;
/** What `EVALS_MAX_MISSING_FRACTION` should resolve to. */
maxMissingFraction: string;
acceptHarness: number[];
canaryRun?: string;
canaryEval: string;
}

export const DEFAULT_MAX_MISSING_FRACTION = '0.1';
export const DEFAULT_CANARY_EVAL = 'benchmark-localdev-001-listen-locally';

function single(raw: string[], name: string): string | undefined {
const values = readRepeatedFlag(raw, name);
if (values.length > 1) throw new Error(`--${name} takes one value`);
return values[0];
}

const KNOWN_FLAGS = new Set([
'json',
'help',
'skip',
'confirm-balance',
'experiments',
'eval',
'suite',
'experiment-suite',
'runs',
'timeout-sec',
'merge',
'hold-publish',
'max-missing-fraction',
'accept-harness',
'canary-run',
'canary-eval',
]);

/**
* Flags mirror the `workflow_dispatch` inputs, so the command that checks a
* matrix reads like the command that dispatches it. `--timeout-sec` and
* `--merge` are accepted and do not change any check.
*/
export function parsePreflightArgs(argv: string[]): PreflightArgs {
const raw = argv.filter((a) => a !== '--');
for (const arg of raw) {
if (!arg.startsWith('--')) continue;
const name = arg.slice(2).split('=')[0] as string;
if (!KNOWN_FLAGS.has(name)) throw new Error(`unknown flag ${arg}`);
}

const known = new Set<string>(CHECKS.map((c) => c.id));
const skip = readRepeatedFlag(raw, 'skip');
const unknown = skip.filter((s) => !known.has(s));
if (unknown.length > 0) {
throw new Error(
`--skip: no check named ${unknown.join(', ')}. Checks: ${[...known].join(', ')}`
);
}

const runsRaw = single(raw, 'runs');
const runs = runsRaw === undefined ? DISPATCH_DEFAULTS.runs : Number(runsRaw);
if (!Number.isInteger(runs) || runs < 1) {
throw new Error(`--runs must be a positive integer, got ${runsRaw}`);
}

const listOr = (name: string, fallback: string[]) => {
const v = readRepeatedFlag(raw, name);
return v.length > 0 ? v : fallback;
};

const accept = readRepeatedFlag(raw, 'accept-harness').map((v) => {
const n = Number(v.replace(/^#/, ''));
if (!Number.isInteger(n)) throw new Error(`--accept-harness: ${v}`);
return n;
});

const maxMissing = single(raw, 'max-missing-fraction');
if (maxMissing !== undefined && !/^\d*\.?\d+$/.test(maxMissing)) {
throw new Error(
`--max-missing-fraction must be a number, got ${maxMissing}`
);
}

return {
json: raw.includes('--json'),
help: raw.includes('--help') || raw.includes('-h'),
skip: skip as CheckId[],
confirmBalance: raw.includes('--confirm-balance'),
dispatch: {
suites: listOr('suite', DISPATCH_DEFAULTS.suites),
experimentSuites: listOr(
'experiment-suite',
DISPATCH_DEFAULTS.experimentSuites
),
experiments: readRepeatedFlag(raw, 'experiments'),
evalIds: readRepeatedFlag(raw, 'eval'),
runs,
},
holdPublish: raw.includes('--hold-publish'),
maxMissingFraction: maxMissing ?? DEFAULT_MAX_MISSING_FRACTION,
acceptHarness: accept,
canaryRun: single(raw, 'canary-run'),
canaryEval: single(raw, 'canary-eval') ?? DEFAULT_CANARY_EVAL,
};
}

export const USAGE = `pnpm preflight [options]

Checks a matrix before it is dispatched. Read-only, except one real completion
per provider (pennies). Exits non-zero when an assertion fails.

What the dispatch will run (mirrors the workflow_dispatch inputs; defaults are
the workflow's, which is the regression suite):
--suite <list> eval suites (default regression)
--experiment-suite <list> experiment suites (default regression)
--experiments <list> experiment names (default: all in the suites)
--eval <list> eval ids (overrides --suite, as in the workflow)
--runs <n> attempts per cell (default 2)
--timeout-sec, --merge accepted; change nothing here

What the run intends:
--hold-publish expect EVALS_PUBLISH=false (default: expect publishing)
--max-missing-fraction <n> expect this EVALS_MAX_MISSING_FRACTION (default 0.1)
--accept-harness <list> open harness issues accepted for this run, by number
--confirm-balance confirm both provider balances cover the estimate
(asked interactively instead when on a TTY)
--canary-run <id> verify a finished two-cell canary run
--canary-eval <id> scenario the canary command uses
(default ${DEFAULT_CANARY_EVAL})

Output:
--json machine-readable report; run as \`pnpm -s preflight --json\`
so pnpm's banner stays out of the JSON
--skip <list> skip checks by id; printed loudly. Ids:
${CHECKS.map((c) => c.id).join(', ')}

A full benchmark matrix:
pnpm preflight --suite benchmark --experiment-suite benchmark,no-skills --runs 3
`;
Loading
Loading