From 71588b0a73485efc66f00d7abb72e0328547de53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Sun, 22 Nov 2026 10:57:59 +0000 Subject: [PATCH] fix(ci): a shard whose results never uploaded is re-run, and never read as an edit accuracy drop (#8477) * fix(ci): a shard whose results never uploaded is re-run, and never read as an edit accuracy drop * refactor(ci): the edit accuracy shard count lives in one place, and a test keeps the matrix on it --- .github/workflows/ci.yml | 18 ++++++++----- .../tests/e2e/edit-accuracy/ratchet.mjs | 12 ++++----- .../tests/e2e/edit-accuracy/ratchet.test.mjs | 16 +++++++++-- scripts/edit-accuracy-retry.test.mjs | 27 ++++++++++++++++--- 4 files changed, 55 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9faf8001d2..ebac9fb2bd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,6 +9,8 @@ permissions: # External users' CI continues to emit telemetry unless they set this themselves. env: HYPERFRAMES_NO_TELEMETRY: "1" + # The edit accuracy shard count; studio-edit-accuracy's matrix lists the same shards (its strategy cannot read env). + EDIT_ACCURACY_SHARDS: ${{ github.event_name == 'merge_group' && 30 || 15 }} on: merge_group: @@ -1337,11 +1339,16 @@ jobs: with: pattern: edit-accuracy-shard-* path: /tmp/edit-accuracy-shards + # A shard whose evidence never uploaded (its upload failed, or the job died first) has nothing to mark, so it + # is re-run too. - name: List the shards marked for a re-run id: plan run: | - shards=$(find /tmp/edit-accuracy-shards -path '*/edit-accuracy-shard-*/retry' | - sed -E 's#.*/edit-accuracy-shard-([0-9]+)/retry$#\1#' | sort -n | paste -sd, -) + shards=$( { + find /tmp/edit-accuracy-shards -path '*/edit-accuracy-shard-*/retry' | + sed -E 's#.*/edit-accuracy-shard-([0-9]+)/retry$#\1#' + for n in $(seq 1 "$EDIT_ACCURACY_SHARDS"); do [ -d "/tmp/edit-accuracy-shards/edit-accuracy-shard-$n" ] || echo "$n"; done + } | sort -n | paste -sd, -) echo "shards=[${shards}]" >> "$GITHUB_OUTPUT" # Each marked shard runs once more on a fresh runner and replaces its evidence before the gate reads it. @@ -1357,7 +1364,6 @@ jobs: shard: ${{ fromJSON(needs.studio-edit-accuracy-retry-plan.outputs.shards) }} env: EDIT_ACCURACY_GRID: ${{ github.event_name == 'merge_group' && 'full' || 'pr' }} - SHARDS: ${{ github.event_name == 'merge_group' && 30 || 15 }} steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2 @@ -1377,7 +1383,7 @@ jobs: bash scripts/ci/base-file.sh packages/studio/tests/e2e/edit-accuracy/baseline.json /tmp/base-edit-accuracy.json [ -f /tmp/base-edit-accuracy.json ] || echo '{"cases":{}}' > /tmp/base-edit-accuracy.json - name: Run the shard again - run: bash scripts/ci/edit-accuracy-shard.sh "${{ matrix.shard }}/${SHARDS}" + run: bash scripts/ci/edit-accuracy-shard.sh "${{ matrix.shard }}/${EDIT_ACCURACY_SHARDS}" - name: Replace the shard's evidence if: always() uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 @@ -1412,12 +1418,10 @@ jobs: - name: Compare every run with the base branch id: gate # Smoothness and newly passing cases are reported, not gated; a case fails only if it fails 2 of its 3 runs. - env: - SHARDS: ${{ github.event_name == 'merge_group' && 30 || 15 }} run: | set +e mapfile -t RESULTS < <(find /tmp/edit-accuracy-shards -name results.json | sort) - node packages/studio/tests/e2e/edit-accuracy/ratchet.mjs gate --shards "$SHARDS" /tmp/base-edit-accuracy.json \ + node packages/studio/tests/e2e/edit-accuracy/ratchet.mjs gate --shards "$EDIT_ACCURACY_SHARDS" /tmp/base-edit-accuracy.json \ packages/studio/tests/e2e/edit-accuracy/baseline.json /tmp/edit-accuracy-gate "${RESULTS[@]}" echo "exit_code=$?" >> "$GITHUB_OUTPUT" cat /tmp/edit-accuracy-gate/comment.md >> "$GITHUB_STEP_SUMMARY" || true diff --git a/packages/studio/tests/e2e/edit-accuracy/ratchet.mjs b/packages/studio/tests/e2e/edit-accuracy/ratchet.mjs index 99ab1efe6f..b0af1fd37f 100644 --- a/packages/studio/tests/e2e/edit-accuracy/ratchet.mjs +++ b/packages/studio/tests/e2e/edit-accuracy/ratchet.mjs @@ -197,18 +197,18 @@ function main(argv) { } const cases = runs.flatMap((r) => r.cases); const full = gridOf(runs) === "full"; + // A shard that died uploads nothing, so the count of first runs is what shows it. + const firstRuns = runs.filter((r) => !r.meta.rerun).length; + const shortfall = + shards !== null && firstRuns !== shards && `${firstRuns} of ${shards} shards reported results`; + // A case that ran and fell is a drop; a shard that did not report is not one, so only the cases that ran count. const g = gate( base, readJson(headPath), cases, QUARANTINED, - full ? null : new Set(cases.map((c) => c.id)), + full && !shortfall ? null : new Set(cases.map((c) => c.id)), ); - // A shard that died uploads nothing, so the count of first runs is what shows it. - const firstRuns = runs.filter((r) => !r.meta.rerun).length; - const shortfall = - shards !== null && firstRuns !== shards && `${firstRuns} of ${shards} shards reported results`; - // A case that ran and fell is a drop; a shard that did not report is not one. const code = g.ok ? (shortfall ? 2 : 0) : 1; if (shortfall) g.reasons.push(shortfall); g.ok = code === 0; diff --git a/packages/studio/tests/e2e/edit-accuracy/ratchet.test.mjs b/packages/studio/tests/e2e/edit-accuracy/ratchet.test.mjs index a8aecf024b..6b5ba40691 100644 --- a/packages/studio/tests/e2e/edit-accuracy/ratchet.test.mjs +++ b/packages/studio/tests/e2e/edit-accuracy/ratchet.test.mjs @@ -199,13 +199,16 @@ describe("teleport in the gate", () => { describe("gate command, as CI runs it", () => { const script = fileURLToPath(new URL("./ratchet.mjs", import.meta.url)); /** Runs `gate --shards ` over the given shard results; returns its exit code, comment and verdict. */ - function runGate(shards, shardCases) { + function runGate(shards, shardCases, grid = "pr") { const dir = mkdtempSync(join(tmpdir(), "edit-accuracy-gate-")); const base = join(dir, "base.json"); writeFileSync(base, JSON.stringify(baseline({ a: good, b: good }))); const results = shardCases.map((cases, i) => { const path = join(dir, `shard-${i}.json`); - writeFileSync(path, JSON.stringify({ meta: { grid: `pr shard ${i + 1}/${shards}` }, cases })); + writeFileSync( + path, + JSON.stringify({ meta: { grid: `${grid} shard ${i + 1}/${shards}` }, cases }), + ); return path; }); const out = join(dir, "out"); @@ -242,6 +245,15 @@ describe("gate command, as CI runs it", () => { ); }); + it("says a full grid with a shard missing did not run, not that the missing cases fell", () => { + const g = runGate(2, [[run("a")]], "full"); + expect(g.code).toBe(2); + expect(g.verdict).toBe( + "Edit accuracy did not run: 1 of 2 shards reported results; see the shard jobs.", + ); + expect(g.comment).not.toMatch(/fell/); + }); + it("still says accuracy fell when a case that ran regressed, even with a shard missing", () => { const g = runGate(2, [[run("a", 9), run("a", 9), run("a", 9)]]); expect(g.code).toBe(1); diff --git a/scripts/edit-accuracy-retry.test.mjs b/scripts/edit-accuracy-retry.test.mjs index ed7f23b28a..a9ca1122c4 100644 --- a/scripts/edit-accuracy-retry.test.mjs +++ b/scripts/edit-accuracy-retry.test.mjs @@ -59,17 +59,29 @@ test("a shard is marked for a re-run when it timed out or its bench stopped on a test("the retry plan lists exactly the marked shards", () => { const plan = step("studio-edit-accuracy-retry-plan", "List the shards marked for a re-run").run; withTree((root) => { - for (const shard of [7, 12, 3]) + for (let shard = 1; shard <= 12; shard++) mkdirSync(join(root, `edit-accuracy-shards/edit-accuracy-shard-${shard}`), { recursive: true, }); writeFileSync(join(root, "edit-accuracy-shards/edit-accuracy-shard-7/retry"), ""); writeFileSync(join(root, "edit-accuracy-shards/edit-accuracy-shard-12/retry"), ""); - assert.equal(runStep(plan, root), "shards=[7,12]\n"); + assert.equal(runStep(plan, root, { EDIT_ACCURACY_SHARDS: "12" }), "shards=[7,12]\n"); }); withTree((root) => { mkdirSync(join(root, "edit-accuracy-shards/edit-accuracy-shard-1"), { recursive: true }); - assert.equal(runStep(plan, root), "shards=[]\n"); + assert.equal(runStep(plan, root, { EDIT_ACCURACY_SHARDS: "1" }), "shards=[]\n"); + }); +}); + +test("the retry plan also re-runs a shard whose evidence never uploaded", () => { + const plan = step("studio-edit-accuracy-retry-plan", "List the shards marked for a re-run").run; + withTree((root) => { + for (const shard of [1, 2, 4]) + mkdirSync(join(root, `edit-accuracy-shards/edit-accuracy-shard-${shard}`), { + recursive: true, + }); + writeFileSync(join(root, "edit-accuracy-shards/edit-accuracy-shard-2/retry"), ""); + assert.equal(runStep(plan, root, { EDIT_ACCURACY_SHARDS: "5" }), "shards=[2,3,5]\n"); }); }); @@ -94,6 +106,15 @@ test("each marked shard re-runs once and replaces its evidence before the gate r assert.match(jobs["studio-edit-accuracy-gate"].if, /!cancelled\(\)/); }); +test("the shard matrix runs exactly the shards the count names, for the merge queue and for pull requests", () => { + const [, queue, pr] = ci.env.EDIT_ACCURACY_SHARDS.match(/&& (\d+) \|\| (\d+)/); + const lists = [...jobs["studio-edit-accuracy"].strategy.matrix.shard.matchAll(/'(\[[^']*\])'/g)]; + assert.deepEqual( + lists.map((m) => JSON.parse(m[1])), + [Number(queue), Number(pr)].map((n) => Array.from({ length: n }, (_, k) => k + 1)), + ); +}); + test("a cancelled shard and its re-run both fit in the merge queue's 60 minute check wait", () => { const shard = jobs["studio-edit-accuracy"]["timeout-minutes"]; const plan = jobs["studio-edit-accuracy-retry-plan"]["timeout-minutes"];