The Open Framework for Building Agents
Shard self-modification evals across CI jobs (#3652)
prha162a489cd869
diff --git a/.github/scripts/discover-e2e-fixtures.mjs b/.github/scripts/discover-e2e-fixtures.mjsindex 465d797d1..31c98af3c 100644--- a/.github/scripts/discover-e2e-fixtures.mjs+++ b/.github/scripts/discover-e2e-fixtures.mjs@@ -6,7 +6,9 @@// fixture roots. Emits one GitHub Actions output per matrix://// model_matrix `{ name, dir, model_name, model_id, optional }`-// entries for the model suite (e2e-local). Fixtures+// entries for the model suite (e2e-local). Sharded+// fixtures expand each selected model into one entry+// per exact eval partition. Fixtures// marked `"e2e": { "modelMatrix": "full" }` in// package.json run on every registry model; all other// fixtures run once on the default (first) model. A@@ -30,7 +32,7 @@ export function discoverE2eFixtures({ registry, fixtures }) {}const modelMatrix = normalizedFixtures.flatMap(- ({ name, dir, modelMatrix, additionalModels, optionalModels }) => {+ ({ name, dir, modelMatrix, additionalModels, optionalModels, modelShards }) => {const fixtureModels = uniqueModels([...(modelMatrix === "full" ? models : models.slice(0, 1)),...additionalModels,@@ -43,13 +45,18 @@ export function discoverE2eFixtures({ registry, fixtures }) {);}}- return fixtureModels.map((model) => ({- name,- dir,- model_name: model.name,- model_id: model.id,- optional: optionalModels.includes(model.name),- }));+ return fixtureModels.flatMap((model) => {+ const entry = {+ name,+ dir,+ model_name: model.name,+ model_id: model.id,+ optional: optionalModels.includes(model.name),+ };+ return modelShards === undefined+ ? [entry]+ : modelShards.map((shard) => ({ ...entry, shard: shard.name, eval_ids: shard.evals }));+ });},);@@ -68,7 +75,7 @@ export function discoverE2eFixtures({ registry, fixtures }) {return { lines: `${outputs.join("\n")}\n`, modelMatrix, worlds, fixtures: normalizedFixtures };}-function normalizeFixture({ name, dir, packageJson }, worlds) {+function normalizeFixture({ name, dir, packageJson, evals = [] }, worlds) {const pkg = packageJson ?? {};const packageJsonPath = join(dir, "package.json");const selectedWorlds = validateNames(@@ -84,10 +91,15 @@ function normalizeFixture({ name, dir, packageJson }, worlds) {if (modelMatrix !== "default" && modelMatrix !== "full") {throw new Error(`${packageJsonPath}: e2e.modelMatrix must be "default" or "full".`);}+ const modelShards =+ pkg.e2e?.modelShards === undefined+ ? undefined+ : validateModelShards(pkg.e2e.modelShards, `${packageJsonPath}: e2e.modelShards`, evals);return {name,dir,modelMatrix,+ modelShards,additionalModels: validateNamedEntries(pkg.e2e?.additionalModels ?? [],`${packageJsonPath}: e2e.additionalModels`,@@ -115,6 +127,7 @@ function discoverFromDisk() {fixtures.push({name,dir,+ evals: discoverEvalIds(join(dir, "evals")),packageJson: existsSync(packageJsonPath)? JSON.parse(readFileSync(packageJsonPath, "utf8")): undefined,@@ -133,6 +146,58 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) {else process.stdout.write(result.lines);}+function discoverEvalIds(root) {+ const evalIds = [];+ const visit = (directory) => {+ for (const entry of readdirSync(directory, { withFileTypes: true }).sort((a, b) =>+ a.name.localeCompare(b.name),+ )) {+ const path = join(directory, entry.name);+ if (entry.isDirectory()) visit(path);+ else if (entry.isFile() && entry.name.endsWith(".eval.ts")) {+ evalIds.push(path.slice(root.length + 1, -".eval.ts".length).replaceAll("\\", "/"));+ }+ }+ };+ visit(root);+ return evalIds;+}++function validateModelShards(shards, key, discoveredEvalIds) {+ if (!Array.isArray(shards) || shards.length === 0) {+ throw new Error(`${key} must be a non-empty array.`);+ }+ const discovered = new Set(discoveredEvalIds);+ const assigned = new Set();+ const names = new Set();+ for (const shard of shards) {+ if (typeof shard?.name !== "string" || !/^[a-z0-9-]+$/.test(shard.name)) {+ throw new Error(`${key} shard names must be non-empty lowercase alphanumerics and dashes.`);+ }+ if (names.has(shard.name))+ throw new Error(`${key} contains duplicate shard name "${shard.name}".`);+ names.add(shard.name);+ if (!Array.isArray(shard.evals) || shard.evals.length === 0) {+ throw new Error(`${key} shard "${shard.name}" must have a non-empty eval list.`);+ }+ for (const evalId of shard.evals) {+ if (typeof evalId !== "string" || evalId.length === 0) {+ throw new Error(`${key} shard "${shard.name}" eval IDs must be non-empty strings.`);+ }+ if (assigned.has(evalId)) throw new Error(`${key} assigns eval "${evalId}" more than once.`);+ assigned.add(evalId);+ if (!discovered.has(evalId)) throw new Error(`${key} references unknown eval "${evalId}".`);+ }+ }+ const unassigned = discoveredEvalIds.filter((evalId) => !assigned.has(evalId));+ if (unassigned.length > 0) {+ throw new Error(+ `${key} does not assign discovered eval${unassigned.length === 1 ? "" : "s"}: ${unassigned.join(", ")}.`,+ );+ }+ return shards;+}+function validateNamedEntries(entries, key, requiredFields, options = {}) {if (!Array.isArray(entries) || (entries.length === 0 && options.allowEmpty !== true)) {throw new Error(`e2e/matrix.json: "${key}" must be a non-empty array.`);diff --git a/.github/scripts/discover-e2e-fixtures.test.mjs b/.github/scripts/discover-e2e-fixtures.test.mjsindex 975cb3c37..6fe2d6a20 100644--- a/.github/scripts/discover-e2e-fixtures.test.mjs+++ b/.github/scripts/discover-e2e-fixtures.test.mjs@@ -8,10 +8,13 @@ const registry = {worlds: [{ name: "vercel" }, { name: "postgres", package: "world-postgres" }],};-function discover(packageJson, additionalFixtures = []) {+function discover(packageJson, additionalFixtures = [], evals = [], selectedRegistry = registry) {return discoverE2eFixtures({- registry,- fixtures: [{ name: "fixture", dir: "fixtures/fixture", packageJson }, ...additionalFixtures],+ registry: selectedRegistry,+ fixtures: [+ { name: "fixture", dir: "fixtures/fixture", packageJson, evals },+ ...additionalFixtures,+ ],});}@@ -55,3 +58,113 @@ test("a valid e2e.worlds subset selects only that world", () => {test("an unknown e2e.worlds entry is rejected", () => {assert.throws(() => discover({ e2e: { worlds: ["missing"] } }), /unknown e2e world "missing"/u);});++test("model shards expand across selected models without multiplying world legs", () => {+ const evals = ["nested/one", "nested/two", "three"];+ const result = discover(+ {+ e2e: {+ worlds: ["postgres"],+ modelMatrix: "full",+ modelShards: [+ { name: "shard-1", evals: ["nested/one", "nested/two"] },+ { name: "shard-2", evals: ["three"] },+ ],+ },+ },+ [+ {+ name: "vercel-fixture",+ dir: "fixtures/vercel-fixture",+ packageJson: { e2e: { worlds: ["vercel"] } },+ evals: [],+ },+ ],+ evals,+ {+ ...registry,+ models: [...registry.models, { name: "model-b", id: "provider/model-b" }],+ },+ );++ assert.deepEqual(+ result.modelMatrix+ .filter(({ name }) => name === "fixture")+ .map(({ model_name, shard, eval_ids }) => ({ model_name, shard, eval_ids })),+ [+ { model_name: "model-a", shard: "shard-1", eval_ids: ["nested/one", "nested/two"] },+ { model_name: "model-a", shard: "shard-2", eval_ids: ["three"] },+ { model_name: "model-b", shard: "shard-1", eval_ids: ["nested/one", "nested/two"] },+ { model_name: "model-b", shard: "shard-2", eval_ids: ["three"] },+ ],+ );+ assert.deepEqual(worldMatrix(result, "vercel"), [+ { name: "vercel-fixture", dir: "fixtures/vercel-fixture" },+ ]);+ assert.deepEqual(worldMatrix(result, "postgres"), [+ { name: "fixture", dir: "fixtures/fixture", world_package: "world-postgres" },+ ]);+});++test("unsharded fixtures keep one model entry with all evals implicit", () => {+ const result = discover({}, [], ["nested/one", "two"]);+ assert.deepEqual(result.modelMatrix, [+ {+ name: "fixture",+ dir: "fixtures/fixture",+ model_name: "model-a",+ model_id: "provider/model-a",+ optional: false,+ },+ ]);+});++test("model shards reject empty shard lists, names, and eval lists", () => {+ for (const modelShards of [+ [],+ [{ name: "", evals: ["one"] }],+ [{ name: "shard-1", evals: [] }],+ ]) {+ assert.throws(() => discover({ e2e: { modelShards } }, [], ["one"]), /e2e.modelShards/u);+ }+});++test("model shards reject duplicate shard names", () => {+ assert.throws(+ () =>+ discover(+ {+ e2e: {+ modelShards: [+ { name: "same", evals: ["one"] },+ { name: "same", evals: ["two"] },+ ],+ },+ },+ [],+ ["one", "two"],+ ),+ /duplicate shard name "same"/u,+ );+});++test("model shards reject duplicate and unknown eval assignments", () => {+ assert.throws(+ () =>+ discover({ e2e: { modelShards: [{ name: "shard-1", evals: ["one", "one"] }] } }, [], ["one"]),+ /assigns eval "one" more than once/u,+ );+ assert.throws(+ () =>+ discover({ e2e: { modelShards: [{ name: "shard-1", evals: ["missing"] }] } }, [], ["one"]),+ /references unknown eval "missing"/u,+ );+});++test("model shards reject discovered evals that are unassigned", () => {+ assert.throws(+ () =>+ discover({ e2e: { modelShards: [{ name: "shard-1", evals: ["one"] }] } }, [], ["one", "two"]),+ /does not assign discovered eval: two/u,+ );+});diff --git a/.github/workflows/e2e-local.yml b/.github/workflows/e2e-local.ymlindex 235ac9723..384f8d711 100644--- a/.github/workflows/e2e-local.yml+++ b/.github/workflows/e2e-local.yml@@ -63,7 +63,7 @@ jobs:# on the default model. The world suites (e2e-vercel, e2e-postgres) cover# the other workflow worlds with deterministic mock models.e2e:- name: e2e-local (${{ matrix.name }}, ${{ matrix.model_name }})+ name: e2e-local (${{ matrix.name }}, ${{ matrix.model_name }})${{ matrix.shard && format(' [{0}]', matrix.shard) || '' }}runs-on: ubuntu-latestneeds: [changes, discover-fixtures]continue-on-error: ${{ matrix.optional }}@@ -78,6 +78,7 @@ jobs:env:AI_GATEWAY_API_KEY: ${{ secrets.AI_GATEWAY_API_KEY }}EVE_E2E_MODEL: ${{ matrix.model_id }}+ EVE_EVAL_IDS_JSON: ${{ toJSON(matrix.eval_ids) }}EVE_EVAL_JUNIT_DIR: ${{ github.workspace }}/.junitEVE_SANDBOX_IMAGE_TAG: latest@@ -144,8 +145,11 @@ jobs:mkdir -p "$EVE_EVAL_JUNIT_DIR"cd "${{ matrix.dir }}"pnpm run --if-present e2e:prepare- pnpm exec eve eval --strict --verbose \- --junit "$EVE_EVAL_JUNIT_DIR/${{ matrix.name }}-${{ matrix.model_name }}.xml"+ mapfile -d '' -t eval_ids < <(node -e 'for (const id of JSON.parse(process.env.EVE_EVAL_IDS_JSON || "null") || []) process.stdout.write(`${id}\0`)')+ shard_suffix="${{ matrix.shard || '' }}"+ junit_suffix="${shard_suffix:+-$shard_suffix}"+ pnpm exec eve eval "${eval_ids[@]}" --strict --verbose \+ --junit "$EVE_EVAL_JUNIT_DIR/${{ matrix.name }}-${{ matrix.model_name }}${junit_suffix}.xml"- name: Capture failed workflow event orderingif: failure() && needs.changes.outputs.relevant == 'true'@@ -155,7 +159,7 @@ jobs:if: (failure()) && needs.changes.outputs.relevant == 'true'uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1with:- name: eval-artifacts-${{ matrix.name }}-${{ matrix.model_name }}+ name: eval-artifacts-${{ matrix.name }}-${{ matrix.model_name }}${{ matrix.shard && format('-{0}', matrix.shard) || '' }}path: |.junit.artifacts/workflow-events.jsondiff --git a/e2e/README.md b/e2e/README.mdindex d21e0f8f4..5c3dbfb60 100644--- a/e2e/README.md+++ b/e2e/README.md@@ -178,7 +178,11 @@ matrices from the registry:narrowly scoped leg with `e2e.additionalModels` entriesshaped as `{ "name": "short-check-name", "id": "provider/model" }`.`e2e.optionalModels` can name selected model legs that should still run and- report failures without blocking the aggregate check.+ report failures without blocking the aggregate check. Fixtures can define+ `e2e.modelShards` as named, non-empty eval-ID partitions; discovery requires+ the partitions to assign every discovered eval exactly once and expands each+ selected model into one job per shard. This partitions only the local model+ suite; world matrices remain one leg per fixture.- `world_matrix_<world>` — one leg per fixture for that world's suiteworkflow. A fixture can set `e2e.worlds` to a subset of registered worldnames, or to `[]` when its evals require local dev behavior; omitting it@@ -205,6 +209,10 @@ pnpm run --if-present e2e:prepareEVE_E2E_MODEL="$MODEL" pnpm exec eve eval --strict --junit "$JUNIT_PATH"```+For a sharded fixture, the workflow passes that shard's eval IDs as positional+arguments to `eve eval`. Each matrix leg has its own checkout, server, JUnit+file, and failure-artifact name.+Fixtures with generated source can define an `e2e:prepare` script. The localmodel suite runs it before starting the eval server; the self-modificationfixture uses it to copy the checkout's standard registry scaffold.diff --git a/e2e/fixtures/agent-self-modification/package.json b/e2e/fixtures/agent-self-modification/package.jsonindex 459a0dce8..88f842047 100644--- a/e2e/fixtures/agent-self-modification/package.json+++ b/e2e/fixtures/agent-self-modification/package.json@@ -25,6 +25,23 @@"typescript": "catalog:"},"e2e": {- "worlds": []+ "worlds": [],+ "modelShards": [+ {+ "name": "repair",+ "evals": [+ "self-modification/offer-repair",+ "self-modification/repair-order-total"+ ]+ },+ {+ "name": "create",+ "evals": [+ "self-modification/create-background-replication-check",+ "self-modification/create-shipping-quote",+ "self-modification/create-incident-triage"+ ]+ }+ ]}}