From b8f36b62bd3067bf25b9e94fd2689b34d268bac2 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Sun, 15 Nov 2026 14:29:45 +0000 Subject: [PATCH] fix(ci): mark the retained-namespace control's designed failure in runtime_host logs (#2921) Every runtime_host run ends its native hosted admission with a deliberate negative control that must fail NATIVE_AUTOMATIC_INDEX_COMPLETED with an AbortError. Its lines were indistinguishable from a real failure and `pr-status --failures` listed them first, so six jobs that failed for other, separately owned reasons were recorded as automatic-index aborts. The control's output now stays in the log with every line marked `expected-failure control | `, and failingLines counts those lines instead of listing them. The parent's verdict stays plain. The README says how to read a failed runtime_host log. Co-Authored-By: Claude Opus 5.5 --- scripts/expected-failure-log.ts | 36 ++++++++++++++++++++ scripts/native-proof/README.md | 15 +++++++++ scripts/pr-status.ts | 13 ++++++-- scripts/prove-native-host.ts | 8 ++--- scripts/skill-tests/pr-status.test.ts | 16 +++++++++ tests/expected-failure-log.test.ts | 48 +++++++++++++++++++++++++++ 6 files changed, 129 insertions(+), 7 deletions(-) create mode 100644 scripts/expected-failure-log.ts create mode 100644 tests/expected-failure-log.test.ts diff --git a/scripts/expected-failure-log.ts b/scripts/expected-failure-log.ts new file mode 100644 index 0000000000..8b640f7b9b --- /dev/null +++ b/scripts/expected-failure-log.ts @@ -0,0 +1,36 @@ +/** + * Marks the output of a deliberate negative control in a job log. + * + * Some proofs run a control that must fail for one exact reason, then verify + * that failure. Its output is evidence and stays in the log, which outlives + * the job's artifacts. Every line it prints carries `EXPECTED_FAILURE_PREFIX`, + * so neither a reader nor `failingLines` (`scripts/pr-status.ts`) takes its + * designed failure for the job's. The verdict on the control is printed by + * the parent without the prefix: a control that fails for any other reason + * still fails the job in plain text (#2921). + */ +export const EXPECTED_FAILURE_PREFIX = "expected-failure control | "; + +/** Copies `stream` to `write`, prefixing every line, including a final line without a newline. */ +export async function relayExpectedFailure(stream: ReadableStream, write: (text: string) => void): Promise { + const decoder = new TextDecoder(); + let pending = ""; + for await (const chunk of stream) { + pending += decoder.decode(chunk, { stream: true }); + const lines = pending.split("\n"); + pending = lines.pop()!; + for (const line of lines) write(`${EXPECTED_FAILURE_PREFIX}${line}\n`); + } + pending += decoder.decode(); + if (pending) write(`${EXPECTED_FAILURE_PREFIX}${pending}\n`); +} + +/** Runs a negative control with every line it prints marked, and returns its exit code. */ +export async function runExpectedFailureControl(argv: string[]): Promise { + const child = Bun.spawn(argv, { stdin: "ignore", stdout: "pipe", stderr: "pipe" }); + await Promise.all([ + relayExpectedFailure(child.stdout, text => process.stdout.write(text)), + relayExpectedFailure(child.stderr, text => process.stderr.write(text)), + ]); + return await child.exited; +} diff --git a/scripts/native-proof/README.md b/scripts/native-proof/README.md index aeee4aa73d..bdf52e5d43 100644 --- a/scripts/native-proof/README.md +++ b/scripts/native-proof/README.md @@ -277,6 +277,21 @@ expected failure with `qualification: false`; it does not turn the failing invocation into a healthy fifth matrix cell. The selected hosted runtime job therefore exercises the reproduction under its enforced AppArmor profile too. +So every `runtime_host` log, green or red, holds a Pi UID 0 invocation that +fails `NATIVE_AUTOMATIC_INDEX_COMPLETED: NativeBrainManagerError: Native manager +outcome is unknown … AbortError` and then `Native hosted proof failed (1)`. +That is the control failing as designed. The parent prints each of its lines +behind `expected-failure control | ` (`scripts/expected-failure-log.ts`), and +`bun scripts/pr-status.ts --failures --logs ` counts them instead of +listing them. The plain lines after them are the verdict. +`Verified expected automatic-index failure …` means the control passed. A +thrown `NATIVE_INDEX_RELEASE_REPRO_` means it did not fail as designed: +it failed somewhere else, or its evidence is incomplete. Every other failure in +the job belongs to the phase that `BRAIN_RESOURCE_RECEIPT` records with +`"success":false`. #2921 traced six recorded "automatic-index aborts" to this +control. Each of those jobs had failed for a different, separately owned +reason. + ## Reference pool allocation `bun scripts/prove-reference-pool.ts` is the reference pool's required runtime diff --git a/scripts/pr-status.ts b/scripts/pr-status.ts index 4ec43746e8..341a0f3263 100644 --- a/scripts/pr-status.ts +++ b/scripts/pr-status.ts @@ -19,6 +19,7 @@ import { mkdirSync, writeFileSync } from "node:fs"; import { join } from "node:path"; import { DEFAULT_REPO, type Gh } from "./issue-queue"; import { RECEIPT_START } from "./check-receipt"; +import { EXPECTED_FAILURE_PREFIX } from "./expected-failure-log"; const realGh: Gh = args => { const result = Bun.spawnSync(["gh", ...args], { stdout: "pipe", stderr: "pipe" }); @@ -55,11 +56,17 @@ export function summarizeChecks(rollup: readonly Rollup[]): Checks & { total: nu const ANSI = /\u001b\[[0-9;]*[A-Za-z]/g; const FAILING = /\(fail\)|\berror\b[:\s]|\bError:|✗|\bFAIL\b|##\[error\]|Process completed with exit code [1-9]/; -/** The lines of a job log worth reading: failures, without timestamps or colour. */ +/** + * The lines of a job log worth reading: failures, without timestamps or colour. + * A deliberate negative control's lines are counted, not shown: it fails by + * design, and its parent reports in plain text whether it failed as designed. + */ export function failingLines(log: string, limit = 30): string[] { const lines = log.split("\n").map(line => line.replace(ANSI, "").replace(/^\d{4}-\d{2}-\d{2}T[\d:.]+Z /, "").trimEnd()); - const found = lines.filter(line => FAILING.test(line)); - return found.length > limit ? [...found.slice(0, limit), `(+${found.length - limit} more failing lines)`] : found; + const failing = lines.filter(line => FAILING.test(line)); + const found = failing.filter(line => !line.startsWith(EXPECTED_FAILURE_PREFIX)), control = failing.length - found.length; + const cut = found.length > limit ? [...found.slice(0, limit), `(+${found.length - limit} more failing lines)`] : found; + return control ? [...cut, `(${control} line${control === 1 ? "" : "s"} of a deliberate expected-failure control left out)`] : cut; } export interface StatusIo { gh?: Gh; out: (text: string) => void } diff --git a/scripts/prove-native-host.ts b/scripts/prove-native-host.ts index 9ad69e7fff..4e1aec2a78 100644 --- a/scripts/prove-native-host.ts +++ b/scripts/prove-native-host.ts @@ -2,6 +2,7 @@ import { chmodSync, mkdtempSync, mkdirSync, readFileSync, readdirSync, realpathSync, writeFileSync } from "node:fs"; import { basename, dirname, join, resolve } from "node:path"; import { verifyIndexReleaseReproduction } from "./native-proof/verify-index-release-repro.js"; +import { EXPECTED_FAILURE_PREFIX, runExpectedFailureControl } from "./expected-failure-log.js"; import { ownedCleanupComplete } from "./native-proof/verify-owned-remove.js"; @@ -90,10 +91,9 @@ if (import.meta.main) { // Four healthy cells qualify first. This separate negative control must // fail the original index-completion assertion for the measured reason. const before = new Set(readdirSync(output)); - console.log("Verifying the deliberately retained index namespace reproduces the expected failure."); - const reproduction = Bun.spawn([process.execPath, import.meta.filename, "--backend=pi", "--app-uid=0", "--retain-index-namespace"], - { stdin: "ignore", stdout: "inherit", stderr: "inherit" }); - const code = await reproduction.exited; + // #2921: its designed failure reads like the job's, so every line it prints is marked. + console.log(`Verifying the deliberately retained index namespace reproduces the expected failure. Its lines carry "${EXPECTED_FAILURE_PREFIX.trim()}"; the verdict follows.`); + const code = await runExpectedFailureControl([process.execPath, import.meta.filename, "--backend=pi", "--app-uid=0", "--retain-index-namespace"]); const created = readdirSync(output, { withFileTypes: true }).filter(entry => entry.isDirectory() && !before.has(entry.name)); if (created.length !== 1) throw Error("Native index-release reproduction did not retain exactly one owned invocation"); const receipt = verifyIndexReleaseReproduction(join(output, created[0]!.name), code); diff --git a/scripts/skill-tests/pr-status.test.ts b/scripts/skill-tests/pr-status.test.ts index 972270804f..86f83dbb33 100644 --- a/scripts/skill-tests/pr-status.test.ts +++ b/scripts/skill-tests/pr-status.test.ts @@ -5,6 +5,7 @@ import { join } from "node:path"; import type { Gh } from "../issue-queue"; import { failingLines, main, summarizeChecks } from "../pr-status"; import { RECEIPT_START } from "../check-receipt"; +import { EXPECTED_FAILURE_PREFIX } from "../expected-failure-log"; const REPO = "schlessera/brain-kit"; const HEAD = "a".repeat(40), BASE = "b".repeat(40), OLD_BASE = "c".repeat(40), MERGE = "d".repeat(40); @@ -47,6 +48,21 @@ describe("reading a job log", () => { expect(failingLines(log)).toEqual(["(fail) the ship > reefs the sail [4.01ms]", "error: expect(received).toBe(expected)", "##[error]Process completed with exit code 1."]); }); + test("a deliberate expected-failure control's lines are left out, and counted", () => { + // #2921: runtime_host's retained-namespace control fails by design in every + // run, green or red; its lines were read as the job's failure six times. + const control = [ + "2026-07-12T09:00:00.0000000Z Verifying the deliberately retained index namespace reproduces the expected failure.", + `2026-07-12T09:00:01.0000000Z ${EXPECTED_FAILURE_PREFIX}{"kind": "command", "code": 1, "stderr": "error: NATIVE_AUTOMATIC_INDEX_COMPLETED: AbortError"}`, + `2026-07-12T09:00:01.1000000Z ${EXPECTED_FAILURE_PREFIX}\u001b[31merror\u001b[0m: Native hosted proof failed (1); inspect run-pi-uid0-Ithaca.`, + "2026-07-12T09:00:02.0000000Z Verified expected automatic-index failure, namespace correlation and owned cleanup; all four healthy cells remain qualified.", + "2026-07-12T09:00:03.0000000Z error: Identity fixture mutation anchor changed", + "2026-07-12T09:00:03.1000000Z ##[error]Process completed with exit code 1.", + ].join("\n"); + expect(failingLines(control)).toEqual(["error: Identity fixture mutation anchor changed", "##[error]Process completed with exit code 1.", + "(2 lines of a deliberate expected-failure control left out)"]); + }); + test("a long failure is cut, and says by how much", () => { const many = Array.from({ length: 12 }, (_, index) => `(fail) case ${index}`).join("\n"); expect(failingLines(many, 10)).toEqual([...Array.from({ length: 10 }, (_, index) => `(fail) case ${index}`), "(+2 more failing lines)"]); diff --git a/tests/expected-failure-log.test.ts b/tests/expected-failure-log.test.ts new file mode 100644 index 0000000000..fa298524cd --- /dev/null +++ b/tests/expected-failure-log.test.ts @@ -0,0 +1,48 @@ +import { expect, test } from "bun:test"; +import { readFileSync } from "node:fs"; +import { join } from "node:path"; + +import { EXPECTED_FAILURE_PREFIX } from "../scripts/expected-failure-log"; +import { failingLines } from "../scripts/pr-status"; + +const ROOT = join(import.meta.dir, ".."); + +// A control that fails the way runtime_host's retained-namespace control does: +// both streams, chunks split mid-line, a last line without a newline, exit 1. +const CONTROL = [ + 'process.stdout.write(\'{"kind": "command", "code": 1, "stderr": "error: NATIVE_AUTOMATIC_INDEX_COMPLETED: \');', + "await Bun.sleep(20);", + 'process.stdout.write(\'AbortError [ABORT_ERR]"}\\nNative pi uid 0 hosted proof artifacts: run-pi-uid0-Ithaca\\n\');', + 'process.stderr.write("error: Native hosted proof failed (1); inspect run-pi-uid0-Ithaca.\\nat Ogygia");', + "process.exit(1);", +].join("\n"); + +test("a negative control's every line is marked on both streams, and its exit code is returned", async () => { + const parent = Bun.spawn([process.execPath, "-e", [ + `import { runExpectedFailureControl } from ${JSON.stringify(join(ROOT, "scripts/expected-failure-log.ts"))};`, + `const code = await runExpectedFailureControl([process.execPath, "-e", ${JSON.stringify(CONTROL)}]);`, + 'console.log(`error: the control exited ${code}`);', + ].join("\n")], { stdin: "ignore", stdout: "pipe", stderr: "pipe" }); + const [stdout, stderr, code] = await Promise.all([new Response(parent.stdout).text(), new Response(parent.stderr).text(), parent.exited]); + expect(code, stderr).toBe(0); + expect(stdout.split("\n")).toEqual([ + `${EXPECTED_FAILURE_PREFIX}{"kind": "command", "code": 1, "stderr": "error: NATIVE_AUTOMATIC_INDEX_COMPLETED: AbortError [ABORT_ERR]"}`, + `${EXPECTED_FAILURE_PREFIX}Native pi uid 0 hosted proof artifacts: run-pi-uid0-Ithaca`, + // The parent's own verdict stays plain. + "error: the control exited 1", + "", + ]); + expect(stderr.split("\n")).toEqual([ + `${EXPECTED_FAILURE_PREFIX}error: Native hosted proof failed (1); inspect run-pi-uid0-Ithaca.`, + `${EXPECTED_FAILURE_PREFIX}at Ogygia`, + "", + ]); + // What `pr-status --failures` prints from that log: the verdict, not the control. + expect(failingLines(`${stdout}${stderr}`)).toEqual(["error: the control exited 1", "(2 lines of a deliberate expected-failure control left out)"]); +}); + +test("the hosted native proof runs its retained-namespace control through the marked relay", () => { + const source = readFileSync(join(ROOT, "scripts/prove-native-host.ts"), "utf8"); + expect(source).toContain('await runExpectedFailureControl([process.execPath, import.meta.filename, "--backend=pi", "--app-uid=0", "--retain-index-namespace"])'); + expect(source).not.toMatch(/Bun\.spawn\(\[process\.execPath, import\.meta\.filename, "--backend=pi", "--app-uid=0", "--retain-index-namespace"\]/); +});