From 8e14d9f41c7d24838c6506cb18ff5a9aea0e63fa Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Sun, 15 Nov 2026 20:01:15 +0000 Subject: [PATCH 1/5] test(native-proof): compare the held worktree's own charge across its refused release (#2819) Case 17 compared the pool's aggregate allocation before and after the refused release of a held worktree. Earlier releases in the same proof still reclaim in the background, so the aggregate can drop between the two readings while nothing about the held worktree changed; loaded hosts failed 2 of 6 runs on that field alone. Compare the worktree's own simple-quota owner charge instead, read from the manager's live measurement through an idempotent retry of its create. Both readings precede the worker's read, and a refused retry reaches the named assertion rather than throwing. Co-Authored-By: Claude Opus 5.5 --- scripts/native-proof/reference-pool.native.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/native-proof/reference-pool.native.ts b/scripts/native-proof/reference-pool.native.ts index f6fb7d8f29..1247708471 100644 --- a/scripts/native-proof/reference-pool.native.ts +++ b/scripts/native-proof/reference-pool.native.ts @@ -563,12 +563,23 @@ const shapes = await create("staging", 32 * MIB); expect((await status()).refusal, "REFERENCE_ACCESS_ACCOUNTED").toBeNull(); // #2729: the pool's own release refuses a granted worktree, atomically with grants, so no // second process can delete what a generation holds; nothing is deleted and the charge stays. - const heldBefore = await charged(); + // The charge compared is the held worktree's own simple-quota owner charge, which an idempotent + // retry of its create reports from the manager's live measurement. The pool aggregate is not + // evidence here: earlier releases still reclaim in the background and lower it meanwhile (#2819). + // Both readings precede the worker's read, whose atime update would dirty the worktree's metadata. + // A released worktree refuses the retry; its code reaches the named assertion instead of a throw. + const heldCharge = async (): Promise => { + await charged(); + try { return (await call({ operation: "poolCreate", id: tree.id, purpose: "worktree", from: base.id, allowanceBytes: 16 * MIB })).ownerBytes; } catch (error) { return `refused: ${(error as { code?: string }).code}`; } + }; + const heldBefore = await heldCharge(); + expect(heldBefore as number, "REFERENCE_ACCESS_HELD_CHARGED").toBeGreaterThan(0); const heldRefusal = await refusal({ operation: "poolRelease", id: tree.id }); const heldRecord = (await call<{ records: NativePoolRecord[] }>({ operation: "listPoolRecovery", after: null })).records.find(item => item.id === tree.id); - note("access-held-release", { refusal: heldRefusal, record: heldRecord }); - expect({ code: heldRefusal.code, state: heldRecord?.state, access: heldRecord?.access, read: await ask("read"), charged: (await charged()).chargedBytes }, - "REFERENCE_ACCESS_HELD_NOT_RELEASED").toEqual({ code: "invalid", state: "writable", access: ACCESS, read: "Telemachus returns", charged: heldBefore.chargedBytes }); + note("access-held-release", { refusal: heldRefusal, record: heldRecord, ownerBytes: heldBefore }); + const heldAfter = await heldCharge(); + expect({ code: heldRefusal.code, state: heldRecord?.state, access: heldRecord?.access, read: await ask("read"), charged: heldAfter }, + "REFERENCE_ACCESS_HELD_NOT_RELEASED").toEqual({ code: "invalid", state: "writable", access: ACCESS, read: "Telemachus returns", charged: heldBefore }); // Parking returns the worktree to the masked roots: the next lookup misses it. expect((await call({ operation: "poolPark", id: tree.id })).access, "REFERENCE_ACCESS_PARKED_RECORD").toBeNull(); expect(await ask("read"), "REFERENCE_ACCESS_PARKED_GONE").toBe("MISSING"); From f77a2dde7e9df4777ae317cd573813884a50cd88 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Sun, 15 Nov 2026 20:06:51 +0000 Subject: [PATCH 2/5] test(native-proof): TEMPORARY #2819 receipt driver for draft heavy feedback Reverted before the PR is marked ready; never proof. Co-Authored-By: Claude Opus 5.5 --- scripts/ci-proof.ts | 2 + scripts/native-proof/receipt-2819.ts | 97 ++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 scripts/native-proof/receipt-2819.ts diff --git a/scripts/ci-proof.ts b/scripts/ci-proof.ts index 9d354e1447..52bf433cfa 100644 --- a/scripts/ci-proof.ts +++ b/scripts/ci-proof.ts @@ -64,6 +64,8 @@ export function categoryCommands(category: ProofCategory, plan: CheckPlan, root: runtime: ["measure-claude-runtime", "measure-claude-enforcement", "native delegation, capabilities and measurement isolation", "shared-process Chrome then child cleanup"], runtime_host: ["native managed hosted admission", "native separate-UID worker identity", "native reference pool allocation"], }; + // TEMPORARY #2819 draft-feedback receipt; reverted before the PR is ready. + if (category === "runtime_host") return [{ name: "native reference pool allocation", argv: [process.execPath, join(root, "scripts/native-proof/receipt-2819.ts")] }]; const selected = inventory.filter(command => names[category].includes(command.name)); if (selected.length !== names[category].length) throw new Error(`${category}: incomplete command inventory`); if (category === "captures") selected.unshift({ name: "pinned capture fonts and original notices", argv: [process.execPath, "run", "capture:fonts"] }); diff --git a/scripts/native-proof/receipt-2819.ts b/scripts/native-proof/receipt-2819.ts new file mode 100644 index 0000000000..c8ce6cc788 --- /dev/null +++ b/scripts/native-proof/receipt-2819.ts @@ -0,0 +1,97 @@ +/** TEMPORARY draft-feedback receipt driver for #2819; reverted before the PR is ready. Never proof. + * + * Runs the real reference pool proof under three source variants and then ten + * times clean under parallel CPU and IO load, printing one RECEIPT_2819 line each: + * - old-aggregate+reclaim: the pre-fix aggregate comparison while an unrelated + * root is released and reclaimed between the readings. Expected to fail + * REFERENCE_ACCESS_HELD_NOT_RELEASED on `charged`. + * - owner+reclaim: the fixed owner-charge comparison under the same + * reclamation. Expected to pass. + * - owner+no-held-refusal: the fixed comparison with #2729's held-worktree + * refusal removed from the pool. Expected to fail REFERENCE_ACCESS_HELD_NOT_RELEASED. + */ +import { readFileSync, writeFileSync } from "node:fs"; +import { join, resolve } from "node:path"; + +const root = resolve(import.meta.dir, "../.."), proof = join(root, "scripts/native-proof/reference-pool.native.ts"); +const pool = join(root, "packages/ui-sdk/src/server/native-reference-pool.ts"); +const started = Date.now(), deadline = started + 12.5 * 60_000; + +const ballast = ` const ballast = await create("staging", 8 * MIB); fill(join(ballast.path!, "ballast.bin"), 4 * MIB);\n`; +const reclaim = ` expect(["deleting", "deleted", "reclaimed"], "RECEIPT_BALLAST_RELEASED").toContain((await release(ballast.id)).state); + for (let wait = 0; wait < 600; wait++) { sync(); await status(); const left = (await call<{ records: NativePoolRecord[] }>({ operation: "listPoolRecovery", after: null })).records.find(item => item.id === ballast.id); + if (!left || left.state === "reclaimed") { note("receipt-ballast", { waited: wait }); break; } await Bun.sleep(100); } +`; +const fixedBefore = ` const heldBefore = await heldCharge();\n`; +const fixedAfter = ` const heldAfter = await heldCharge();\n`; +const fixedBlock = ` const heldAfter = await heldCharge(); + expect({ code: heldRefusal.code, state: heldRecord?.state, access: heldRecord?.access, read: await ask("read"), charged: heldAfter }, + "REFERENCE_ACCESS_HELD_NOT_RELEASED").toEqual({ code: "invalid", state: "writable", access: ACCESS, read: "Telemachus returns", charged: heldBefore }); +`; +const oldBlock = ` expect({ code: heldRefusal.code, state: heldRecord?.state, access: heldRecord?.access, read: await ask("read"), charged: (await charged()).chargedBytes }, + "REFERENCE_ACCESS_HELD_NOT_RELEASED").toEqual({ code: "invalid", state: "writable", access: ACCESS, read: "Telemachus returns", charged: heldAggregate.chargedBytes }); +`; +const refusal = ` if (intent.state === "writable" && intent.access) + throw new NativeBrainManagerError("invalid", "This worktree is held by an access generation; park it before releasing it."); +`; + +type Edit = { file: string; from: string; to: string }; +const variants: { name: string; edits: Edit[]; expectFailure: boolean }[] = [ + { name: "old-aggregate+reclaim", expectFailure: true, edits: [ + { file: proof, from: fixedBefore, to: ballast + ` const heldAggregate = await charged();\n` + fixedBefore }, + { file: proof, from: fixedBlock, to: reclaim + oldBlock }] }, + { name: "owner+reclaim", expectFailure: false, edits: [ + { file: proof, from: fixedBefore, to: ballast + fixedBefore }, + { file: proof, from: fixedAfter, to: reclaim + fixedAfter }] }, + { name: "owner+no-held-refusal", expectFailure: true, edits: [{ file: pool, from: refusal, to: "" }] }, +]; + +function run(name: string): { code: number; output: string; seconds: number } { + const at = Date.now(); + const child = Bun.spawnSync([process.execPath, join(root, "scripts/prove-reference-pool.ts")], { cwd: root, stdout: "pipe", stderr: "pipe" }); + const output = new TextDecoder().decode(child.stdout) + new TextDecoder().decode(child.stderr); + const seconds = (Date.now() - at) / 1000; + console.log(`=== ${name}: exit ${child.exitCode} in ${seconds}s`); + return { code: child.exitCode ?? -1, output, seconds }; +} +function excerpt(output: string, marker: string) { + const lines = output.split("\n"), at = lines.findIndex(line => line.includes(marker)); + return at < 0 ? lines.slice(-40).join("\n") : lines.slice(Math.max(0, at - 5), at + 30).join("\n"); +} + +let mismatches = 0; +for (const variant of variants) { + const originals = new Map(); + for (const edit of variant.edits) { + const text = originals.get(edit.file) ?? readFileSync(edit.file, "utf8"); + if (!originals.has(edit.file)) originals.set(edit.file, text); + const current = readFileSync(edit.file, "utf8"); + if (current.split(edit.from).length !== 2) throw Error(`${variant.name}: anchor not found exactly once in ${edit.file}`); + writeFileSync(edit.file, current.replace(edit.from, edit.to)); + } + try { + const result = run(variant.name); + const named = result.output.includes("REFERENCE_ACCESS_HELD_NOT_RELEASED"); + const ok = variant.expectFailure ? result.code !== 0 && named : result.code === 0; + if (!ok) mismatches++; + console.log(`RECEIPT_2819 ${JSON.stringify({ variant: variant.name, exit: result.code, seconds: result.seconds, namedAssertion: named, asExpected: ok })}`); + if (variant.expectFailure || !ok) console.log(excerpt(result.output, "REFERENCE_ACCESS_HELD_NOT_RELEASED")); + } finally { for (const [file, text] of originals) writeFileSync(file, text); } +} + +// Ten clean runs while parallel load holds the host, as in the reported failures. +const load = [ + ...[0, 1].map(() => Bun.spawn(["nice", "-n", "5", "sh", "-c", "while :; do :; done"], { stdout: "ignore", stderr: "ignore" })), + Bun.spawn(["sh", "-c", `while :; do dd if=/dev/urandom of=${join(root, "tmp/receipt-2819-load.bin")} bs=1M count=256 conv=fsync status=none; done`], { stdout: "ignore", stderr: "ignore" }), +]; +let clean = 0, attempted = 0; +try { + while (attempted < 10 && Date.now() < deadline) { + attempted++; + const result = run(`clean+load ${attempted}`); + if (result.code === 0) clean++; else { mismatches++; console.log(excerpt(result.output, "REFERENCE_")); } + console.log(`RECEIPT_2819 ${JSON.stringify({ variant: "clean+load", attempt: attempted, exit: result.code, seconds: result.seconds })}`); + } +} finally { for (const child of load) child.kill("SIGKILL"); } +console.log(`RECEIPT_2819_SUMMARY ${JSON.stringify({ cleanPassed: clean, cleanAttempted: attempted, mismatches, elapsedSeconds: (Date.now() - started) / 1000 })}`); +if (mismatches || clean < 10) process.exitCode = 1; From ee73f2d62ffe834c533a4fff67055a9056b16d7f Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Sun, 15 Nov 2026 20:53:34 +0000 Subject: [PATCH 3/5] test(native-proof): TEMPORARY #2819 receipt driver, round two (ten loaded held-release runs) Reverted before the PR is marked ready; never proof. Co-Authored-By: Claude Opus 5.5 --- scripts/native-proof/receipt-2819.ts | 109 +++++++-------------------- 1 file changed, 27 insertions(+), 82 deletions(-) diff --git a/scripts/native-proof/receipt-2819.ts b/scripts/native-proof/receipt-2819.ts index c8ce6cc788..63937d7709 100644 --- a/scripts/native-proof/receipt-2819.ts +++ b/scripts/native-proof/receipt-2819.ts @@ -1,97 +1,42 @@ -/** TEMPORARY draft-feedback receipt driver for #2819; reverted before the PR is ready. Never proof. +/** TEMPORARY draft-feedback receipt driver for #2819 (second round); reverted before the PR is ready. Never proof. * - * Runs the real reference pool proof under three source variants and then ten - * times clean under parallel CPU and IO load, printing one RECEIPT_2819 line each: - * - old-aggregate+reclaim: the pre-fix aggregate comparison while an unrelated - * root is released and reclaimed between the readings. Expected to fail - * REFERENCE_ACCESS_HELD_NOT_RELEASED on `charged`. - * - owner+reclaim: the fixed owner-charge comparison under the same - * reclamation. Expected to pass. - * - owner+no-held-refusal: the fixed comparison with #2729's held-worktree - * refusal removed from the pool. Expected to fail REFERENCE_ACCESS_HELD_NOT_RELEASED. + * Repeats the real reference pool proof ten times on the fixed tree while parallel + * CPU and IO load holds the host. Each run stops on a marker thrown right after + * case 17's REFERENCE_ACCESS_HELD_NOT_RELEASED assertion, so ten loaded runs fit + * the step budget; later cases are not what #2819 measures. A run counts only + * when its output carries the marker and no REFERENCE_ assertion failed. */ import { readFileSync, writeFileSync } from "node:fs"; import { join, resolve } from "node:path"; const root = resolve(import.meta.dir, "../.."), proof = join(root, "scripts/native-proof/reference-pool.native.ts"); -const pool = join(root, "packages/ui-sdk/src/server/native-reference-pool.ts"); -const started = Date.now(), deadline = started + 12.5 * 60_000; +const started = Date.now(), deadline = started + 13 * 60_000; +const held = ` "REFERENCE_ACCESS_HELD_NOT_RELEASED").toEqual({ code: "invalid", state: "writable", access: ACCESS, read: "Telemachus returns", charged: heldBefore });\n`; +const stop = ` note("receipt-held-passed", { ownerBytes: heldBefore }); throw Error("RECEIPT_2819_STOP_AFTER_HELD");\n`; -const ballast = ` const ballast = await create("staging", 8 * MIB); fill(join(ballast.path!, "ballast.bin"), 4 * MIB);\n`; -const reclaim = ` expect(["deleting", "deleted", "reclaimed"], "RECEIPT_BALLAST_RELEASED").toContain((await release(ballast.id)).state); - for (let wait = 0; wait < 600; wait++) { sync(); await status(); const left = (await call<{ records: NativePoolRecord[] }>({ operation: "listPoolRecovery", after: null })).records.find(item => item.id === ballast.id); - if (!left || left.state === "reclaimed") { note("receipt-ballast", { waited: wait }); break; } await Bun.sleep(100); } -`; -const fixedBefore = ` const heldBefore = await heldCharge();\n`; -const fixedAfter = ` const heldAfter = await heldCharge();\n`; -const fixedBlock = ` const heldAfter = await heldCharge(); - expect({ code: heldRefusal.code, state: heldRecord?.state, access: heldRecord?.access, read: await ask("read"), charged: heldAfter }, - "REFERENCE_ACCESS_HELD_NOT_RELEASED").toEqual({ code: "invalid", state: "writable", access: ACCESS, read: "Telemachus returns", charged: heldBefore }); -`; -const oldBlock = ` expect({ code: heldRefusal.code, state: heldRecord?.state, access: heldRecord?.access, read: await ask("read"), charged: (await charged()).chargedBytes }, - "REFERENCE_ACCESS_HELD_NOT_RELEASED").toEqual({ code: "invalid", state: "writable", access: ACCESS, read: "Telemachus returns", charged: heldAggregate.chargedBytes }); -`; -const refusal = ` if (intent.state === "writable" && intent.access) - throw new NativeBrainManagerError("invalid", "This worktree is held by an access generation; park it before releasing it."); -`; - -type Edit = { file: string; from: string; to: string }; -const variants: { name: string; edits: Edit[]; expectFailure: boolean }[] = [ - { name: "old-aggregate+reclaim", expectFailure: true, edits: [ - { file: proof, from: fixedBefore, to: ballast + ` const heldAggregate = await charged();\n` + fixedBefore }, - { file: proof, from: fixedBlock, to: reclaim + oldBlock }] }, - { name: "owner+reclaim", expectFailure: false, edits: [ - { file: proof, from: fixedBefore, to: ballast + fixedBefore }, - { file: proof, from: fixedAfter, to: reclaim + fixedAfter }] }, - { name: "owner+no-held-refusal", expectFailure: true, edits: [{ file: pool, from: refusal, to: "" }] }, -]; - -function run(name: string): { code: number; output: string; seconds: number } { - const at = Date.now(); - const child = Bun.spawnSync([process.execPath, join(root, "scripts/prove-reference-pool.ts")], { cwd: root, stdout: "pipe", stderr: "pipe" }); - const output = new TextDecoder().decode(child.stdout) + new TextDecoder().decode(child.stderr); - const seconds = (Date.now() - at) / 1000; - console.log(`=== ${name}: exit ${child.exitCode} in ${seconds}s`); - return { code: child.exitCode ?? -1, output, seconds }; -} -function excerpt(output: string, marker: string) { - const lines = output.split("\n"), at = lines.findIndex(line => line.includes(marker)); - return at < 0 ? lines.slice(-40).join("\n") : lines.slice(Math.max(0, at - 5), at + 30).join("\n"); -} - -let mismatches = 0; -for (const variant of variants) { - const originals = new Map(); - for (const edit of variant.edits) { - const text = originals.get(edit.file) ?? readFileSync(edit.file, "utf8"); - if (!originals.has(edit.file)) originals.set(edit.file, text); - const current = readFileSync(edit.file, "utf8"); - if (current.split(edit.from).length !== 2) throw Error(`${variant.name}: anchor not found exactly once in ${edit.file}`); - writeFileSync(edit.file, current.replace(edit.from, edit.to)); - } - try { - const result = run(variant.name); - const named = result.output.includes("REFERENCE_ACCESS_HELD_NOT_RELEASED"); - const ok = variant.expectFailure ? result.code !== 0 && named : result.code === 0; - if (!ok) mismatches++; - console.log(`RECEIPT_2819 ${JSON.stringify({ variant: variant.name, exit: result.code, seconds: result.seconds, namedAssertion: named, asExpected: ok })}`); - if (variant.expectFailure || !ok) console.log(excerpt(result.output, "REFERENCE_ACCESS_HELD_NOT_RELEASED")); - } finally { for (const [file, text] of originals) writeFileSync(file, text); } -} - -// Ten clean runs while parallel load holds the host, as in the reported failures. +const original = readFileSync(proof, "utf8"); +if (original.split(held).length !== 2) throw Error("held assertion anchor not found exactly once"); const load = [ ...[0, 1].map(() => Bun.spawn(["nice", "-n", "5", "sh", "-c", "while :; do :; done"], { stdout: "ignore", stderr: "ignore" })), Bun.spawn(["sh", "-c", `while :; do dd if=/dev/urandom of=${join(root, "tmp/receipt-2819-load.bin")} bs=1M count=256 conv=fsync status=none; done`], { stdout: "ignore", stderr: "ignore" }), ]; -let clean = 0, attempted = 0; +let passed = 0, attempted = 0; try { + writeFileSync(proof, original.replace(held, held + stop)); while (attempted < 10 && Date.now() < deadline) { attempted++; - const result = run(`clean+load ${attempted}`); - if (result.code === 0) clean++; else { mismatches++; console.log(excerpt(result.output, "REFERENCE_")); } - console.log(`RECEIPT_2819 ${JSON.stringify({ variant: "clean+load", attempt: attempted, exit: result.code, seconds: result.seconds })}`); + const at = Date.now(); + const child = Bun.spawnSync([process.execPath, join(root, "scripts/prove-reference-pool.ts")], { cwd: root, stdout: "pipe", stderr: "pipe" }); + const output = new TextDecoder().decode(child.stdout) + new TextDecoder().decode(child.stderr); + const reached = output.includes("RECEIPT_2819_STOP_AFTER_HELD"), failed = /error: REFERENCE_[A-Z0-9_]+/.exec(output)?.[0] ?? null; + const ok = reached && !failed; + if (ok) passed++; + console.log(`RECEIPT_2819 ${JSON.stringify({ variant: "clean+load", attempt: attempted, seconds: (Date.now() - at) / 1000, reachedMarker: reached, failedAssertion: failed, passedHeld: ok })}`); + if (!ok) console.log(output.split("\n").slice(-60).join("\n")); } -} finally { for (const child of load) child.kill("SIGKILL"); } -console.log(`RECEIPT_2819_SUMMARY ${JSON.stringify({ cleanPassed: clean, cleanAttempted: attempted, mismatches, elapsedSeconds: (Date.now() - started) / 1000 })}`); -if (mismatches || clean < 10) process.exitCode = 1; +} finally { + writeFileSync(proof, original); + for (const child of load) child.kill("SIGKILL"); +} +console.log(`RECEIPT_2819_SUMMARY ${JSON.stringify({ heldPassed: passed, attempted, elapsedSeconds: (Date.now() - started) / 1000 })}`); +if (passed < 10) process.exitCode = 1; From c0081e95b98ce03f88f447e9fa650fd0f9a72229 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Mon, 16 Nov 2026 01:22:56 +0000 Subject: [PATCH 4/5] Revert "test(native-proof): TEMPORARY #2819 receipt driver, round two (ten loaded held-release runs)" This reverts commit ee73f2d62ffe834c533a4fff67055a9056b16d7f. --- scripts/native-proof/receipt-2819.ts | 109 ++++++++++++++++++++------- 1 file changed, 82 insertions(+), 27 deletions(-) diff --git a/scripts/native-proof/receipt-2819.ts b/scripts/native-proof/receipt-2819.ts index 63937d7709..c8ce6cc788 100644 --- a/scripts/native-proof/receipt-2819.ts +++ b/scripts/native-proof/receipt-2819.ts @@ -1,42 +1,97 @@ -/** TEMPORARY draft-feedback receipt driver for #2819 (second round); reverted before the PR is ready. Never proof. +/** TEMPORARY draft-feedback receipt driver for #2819; reverted before the PR is ready. Never proof. * - * Repeats the real reference pool proof ten times on the fixed tree while parallel - * CPU and IO load holds the host. Each run stops on a marker thrown right after - * case 17's REFERENCE_ACCESS_HELD_NOT_RELEASED assertion, so ten loaded runs fit - * the step budget; later cases are not what #2819 measures. A run counts only - * when its output carries the marker and no REFERENCE_ assertion failed. + * Runs the real reference pool proof under three source variants and then ten + * times clean under parallel CPU and IO load, printing one RECEIPT_2819 line each: + * - old-aggregate+reclaim: the pre-fix aggregate comparison while an unrelated + * root is released and reclaimed between the readings. Expected to fail + * REFERENCE_ACCESS_HELD_NOT_RELEASED on `charged`. + * - owner+reclaim: the fixed owner-charge comparison under the same + * reclamation. Expected to pass. + * - owner+no-held-refusal: the fixed comparison with #2729's held-worktree + * refusal removed from the pool. Expected to fail REFERENCE_ACCESS_HELD_NOT_RELEASED. */ import { readFileSync, writeFileSync } from "node:fs"; import { join, resolve } from "node:path"; const root = resolve(import.meta.dir, "../.."), proof = join(root, "scripts/native-proof/reference-pool.native.ts"); -const started = Date.now(), deadline = started + 13 * 60_000; -const held = ` "REFERENCE_ACCESS_HELD_NOT_RELEASED").toEqual({ code: "invalid", state: "writable", access: ACCESS, read: "Telemachus returns", charged: heldBefore });\n`; -const stop = ` note("receipt-held-passed", { ownerBytes: heldBefore }); throw Error("RECEIPT_2819_STOP_AFTER_HELD");\n`; +const pool = join(root, "packages/ui-sdk/src/server/native-reference-pool.ts"); +const started = Date.now(), deadline = started + 12.5 * 60_000; -const original = readFileSync(proof, "utf8"); -if (original.split(held).length !== 2) throw Error("held assertion anchor not found exactly once"); +const ballast = ` const ballast = await create("staging", 8 * MIB); fill(join(ballast.path!, "ballast.bin"), 4 * MIB);\n`; +const reclaim = ` expect(["deleting", "deleted", "reclaimed"], "RECEIPT_BALLAST_RELEASED").toContain((await release(ballast.id)).state); + for (let wait = 0; wait < 600; wait++) { sync(); await status(); const left = (await call<{ records: NativePoolRecord[] }>({ operation: "listPoolRecovery", after: null })).records.find(item => item.id === ballast.id); + if (!left || left.state === "reclaimed") { note("receipt-ballast", { waited: wait }); break; } await Bun.sleep(100); } +`; +const fixedBefore = ` const heldBefore = await heldCharge();\n`; +const fixedAfter = ` const heldAfter = await heldCharge();\n`; +const fixedBlock = ` const heldAfter = await heldCharge(); + expect({ code: heldRefusal.code, state: heldRecord?.state, access: heldRecord?.access, read: await ask("read"), charged: heldAfter }, + "REFERENCE_ACCESS_HELD_NOT_RELEASED").toEqual({ code: "invalid", state: "writable", access: ACCESS, read: "Telemachus returns", charged: heldBefore }); +`; +const oldBlock = ` expect({ code: heldRefusal.code, state: heldRecord?.state, access: heldRecord?.access, read: await ask("read"), charged: (await charged()).chargedBytes }, + "REFERENCE_ACCESS_HELD_NOT_RELEASED").toEqual({ code: "invalid", state: "writable", access: ACCESS, read: "Telemachus returns", charged: heldAggregate.chargedBytes }); +`; +const refusal = ` if (intent.state === "writable" && intent.access) + throw new NativeBrainManagerError("invalid", "This worktree is held by an access generation; park it before releasing it."); +`; + +type Edit = { file: string; from: string; to: string }; +const variants: { name: string; edits: Edit[]; expectFailure: boolean }[] = [ + { name: "old-aggregate+reclaim", expectFailure: true, edits: [ + { file: proof, from: fixedBefore, to: ballast + ` const heldAggregate = await charged();\n` + fixedBefore }, + { file: proof, from: fixedBlock, to: reclaim + oldBlock }] }, + { name: "owner+reclaim", expectFailure: false, edits: [ + { file: proof, from: fixedBefore, to: ballast + fixedBefore }, + { file: proof, from: fixedAfter, to: reclaim + fixedAfter }] }, + { name: "owner+no-held-refusal", expectFailure: true, edits: [{ file: pool, from: refusal, to: "" }] }, +]; + +function run(name: string): { code: number; output: string; seconds: number } { + const at = Date.now(); + const child = Bun.spawnSync([process.execPath, join(root, "scripts/prove-reference-pool.ts")], { cwd: root, stdout: "pipe", stderr: "pipe" }); + const output = new TextDecoder().decode(child.stdout) + new TextDecoder().decode(child.stderr); + const seconds = (Date.now() - at) / 1000; + console.log(`=== ${name}: exit ${child.exitCode} in ${seconds}s`); + return { code: child.exitCode ?? -1, output, seconds }; +} +function excerpt(output: string, marker: string) { + const lines = output.split("\n"), at = lines.findIndex(line => line.includes(marker)); + return at < 0 ? lines.slice(-40).join("\n") : lines.slice(Math.max(0, at - 5), at + 30).join("\n"); +} + +let mismatches = 0; +for (const variant of variants) { + const originals = new Map(); + for (const edit of variant.edits) { + const text = originals.get(edit.file) ?? readFileSync(edit.file, "utf8"); + if (!originals.has(edit.file)) originals.set(edit.file, text); + const current = readFileSync(edit.file, "utf8"); + if (current.split(edit.from).length !== 2) throw Error(`${variant.name}: anchor not found exactly once in ${edit.file}`); + writeFileSync(edit.file, current.replace(edit.from, edit.to)); + } + try { + const result = run(variant.name); + const named = result.output.includes("REFERENCE_ACCESS_HELD_NOT_RELEASED"); + const ok = variant.expectFailure ? result.code !== 0 && named : result.code === 0; + if (!ok) mismatches++; + console.log(`RECEIPT_2819 ${JSON.stringify({ variant: variant.name, exit: result.code, seconds: result.seconds, namedAssertion: named, asExpected: ok })}`); + if (variant.expectFailure || !ok) console.log(excerpt(result.output, "REFERENCE_ACCESS_HELD_NOT_RELEASED")); + } finally { for (const [file, text] of originals) writeFileSync(file, text); } +} + +// Ten clean runs while parallel load holds the host, as in the reported failures. const load = [ ...[0, 1].map(() => Bun.spawn(["nice", "-n", "5", "sh", "-c", "while :; do :; done"], { stdout: "ignore", stderr: "ignore" })), Bun.spawn(["sh", "-c", `while :; do dd if=/dev/urandom of=${join(root, "tmp/receipt-2819-load.bin")} bs=1M count=256 conv=fsync status=none; done`], { stdout: "ignore", stderr: "ignore" }), ]; -let passed = 0, attempted = 0; +let clean = 0, attempted = 0; try { - writeFileSync(proof, original.replace(held, held + stop)); while (attempted < 10 && Date.now() < deadline) { attempted++; - const at = Date.now(); - const child = Bun.spawnSync([process.execPath, join(root, "scripts/prove-reference-pool.ts")], { cwd: root, stdout: "pipe", stderr: "pipe" }); - const output = new TextDecoder().decode(child.stdout) + new TextDecoder().decode(child.stderr); - const reached = output.includes("RECEIPT_2819_STOP_AFTER_HELD"), failed = /error: REFERENCE_[A-Z0-9_]+/.exec(output)?.[0] ?? null; - const ok = reached && !failed; - if (ok) passed++; - console.log(`RECEIPT_2819 ${JSON.stringify({ variant: "clean+load", attempt: attempted, seconds: (Date.now() - at) / 1000, reachedMarker: reached, failedAssertion: failed, passedHeld: ok })}`); - if (!ok) console.log(output.split("\n").slice(-60).join("\n")); + const result = run(`clean+load ${attempted}`); + if (result.code === 0) clean++; else { mismatches++; console.log(excerpt(result.output, "REFERENCE_")); } + console.log(`RECEIPT_2819 ${JSON.stringify({ variant: "clean+load", attempt: attempted, exit: result.code, seconds: result.seconds })}`); } -} finally { - writeFileSync(proof, original); - for (const child of load) child.kill("SIGKILL"); -} -console.log(`RECEIPT_2819_SUMMARY ${JSON.stringify({ heldPassed: passed, attempted, elapsedSeconds: (Date.now() - started) / 1000 })}`); -if (passed < 10) process.exitCode = 1; +} finally { for (const child of load) child.kill("SIGKILL"); } +console.log(`RECEIPT_2819_SUMMARY ${JSON.stringify({ cleanPassed: clean, cleanAttempted: attempted, mismatches, elapsedSeconds: (Date.now() - started) / 1000 })}`); +if (mismatches || clean < 10) process.exitCode = 1; From bfdb0d8112c7410ae3d86306d509a22f6e5a7ff2 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Mon, 16 Nov 2026 01:22:56 +0000 Subject: [PATCH 5/5] Revert "test(native-proof): TEMPORARY #2819 receipt driver for draft heavy feedback" This reverts commit f77a2dde7e9df4777ae317cd573813884a50cd88. --- scripts/ci-proof.ts | 2 - scripts/native-proof/receipt-2819.ts | 97 ---------------------------- 2 files changed, 99 deletions(-) delete mode 100644 scripts/native-proof/receipt-2819.ts diff --git a/scripts/ci-proof.ts b/scripts/ci-proof.ts index 52bf433cfa..9d354e1447 100644 --- a/scripts/ci-proof.ts +++ b/scripts/ci-proof.ts @@ -64,8 +64,6 @@ export function categoryCommands(category: ProofCategory, plan: CheckPlan, root: runtime: ["measure-claude-runtime", "measure-claude-enforcement", "native delegation, capabilities and measurement isolation", "shared-process Chrome then child cleanup"], runtime_host: ["native managed hosted admission", "native separate-UID worker identity", "native reference pool allocation"], }; - // TEMPORARY #2819 draft-feedback receipt; reverted before the PR is ready. - if (category === "runtime_host") return [{ name: "native reference pool allocation", argv: [process.execPath, join(root, "scripts/native-proof/receipt-2819.ts")] }]; const selected = inventory.filter(command => names[category].includes(command.name)); if (selected.length !== names[category].length) throw new Error(`${category}: incomplete command inventory`); if (category === "captures") selected.unshift({ name: "pinned capture fonts and original notices", argv: [process.execPath, "run", "capture:fonts"] }); diff --git a/scripts/native-proof/receipt-2819.ts b/scripts/native-proof/receipt-2819.ts deleted file mode 100644 index c8ce6cc788..0000000000 --- a/scripts/native-proof/receipt-2819.ts +++ /dev/null @@ -1,97 +0,0 @@ -/** TEMPORARY draft-feedback receipt driver for #2819; reverted before the PR is ready. Never proof. - * - * Runs the real reference pool proof under three source variants and then ten - * times clean under parallel CPU and IO load, printing one RECEIPT_2819 line each: - * - old-aggregate+reclaim: the pre-fix aggregate comparison while an unrelated - * root is released and reclaimed between the readings. Expected to fail - * REFERENCE_ACCESS_HELD_NOT_RELEASED on `charged`. - * - owner+reclaim: the fixed owner-charge comparison under the same - * reclamation. Expected to pass. - * - owner+no-held-refusal: the fixed comparison with #2729's held-worktree - * refusal removed from the pool. Expected to fail REFERENCE_ACCESS_HELD_NOT_RELEASED. - */ -import { readFileSync, writeFileSync } from "node:fs"; -import { join, resolve } from "node:path"; - -const root = resolve(import.meta.dir, "../.."), proof = join(root, "scripts/native-proof/reference-pool.native.ts"); -const pool = join(root, "packages/ui-sdk/src/server/native-reference-pool.ts"); -const started = Date.now(), deadline = started + 12.5 * 60_000; - -const ballast = ` const ballast = await create("staging", 8 * MIB); fill(join(ballast.path!, "ballast.bin"), 4 * MIB);\n`; -const reclaim = ` expect(["deleting", "deleted", "reclaimed"], "RECEIPT_BALLAST_RELEASED").toContain((await release(ballast.id)).state); - for (let wait = 0; wait < 600; wait++) { sync(); await status(); const left = (await call<{ records: NativePoolRecord[] }>({ operation: "listPoolRecovery", after: null })).records.find(item => item.id === ballast.id); - if (!left || left.state === "reclaimed") { note("receipt-ballast", { waited: wait }); break; } await Bun.sleep(100); } -`; -const fixedBefore = ` const heldBefore = await heldCharge();\n`; -const fixedAfter = ` const heldAfter = await heldCharge();\n`; -const fixedBlock = ` const heldAfter = await heldCharge(); - expect({ code: heldRefusal.code, state: heldRecord?.state, access: heldRecord?.access, read: await ask("read"), charged: heldAfter }, - "REFERENCE_ACCESS_HELD_NOT_RELEASED").toEqual({ code: "invalid", state: "writable", access: ACCESS, read: "Telemachus returns", charged: heldBefore }); -`; -const oldBlock = ` expect({ code: heldRefusal.code, state: heldRecord?.state, access: heldRecord?.access, read: await ask("read"), charged: (await charged()).chargedBytes }, - "REFERENCE_ACCESS_HELD_NOT_RELEASED").toEqual({ code: "invalid", state: "writable", access: ACCESS, read: "Telemachus returns", charged: heldAggregate.chargedBytes }); -`; -const refusal = ` if (intent.state === "writable" && intent.access) - throw new NativeBrainManagerError("invalid", "This worktree is held by an access generation; park it before releasing it."); -`; - -type Edit = { file: string; from: string; to: string }; -const variants: { name: string; edits: Edit[]; expectFailure: boolean }[] = [ - { name: "old-aggregate+reclaim", expectFailure: true, edits: [ - { file: proof, from: fixedBefore, to: ballast + ` const heldAggregate = await charged();\n` + fixedBefore }, - { file: proof, from: fixedBlock, to: reclaim + oldBlock }] }, - { name: "owner+reclaim", expectFailure: false, edits: [ - { file: proof, from: fixedBefore, to: ballast + fixedBefore }, - { file: proof, from: fixedAfter, to: reclaim + fixedAfter }] }, - { name: "owner+no-held-refusal", expectFailure: true, edits: [{ file: pool, from: refusal, to: "" }] }, -]; - -function run(name: string): { code: number; output: string; seconds: number } { - const at = Date.now(); - const child = Bun.spawnSync([process.execPath, join(root, "scripts/prove-reference-pool.ts")], { cwd: root, stdout: "pipe", stderr: "pipe" }); - const output = new TextDecoder().decode(child.stdout) + new TextDecoder().decode(child.stderr); - const seconds = (Date.now() - at) / 1000; - console.log(`=== ${name}: exit ${child.exitCode} in ${seconds}s`); - return { code: child.exitCode ?? -1, output, seconds }; -} -function excerpt(output: string, marker: string) { - const lines = output.split("\n"), at = lines.findIndex(line => line.includes(marker)); - return at < 0 ? lines.slice(-40).join("\n") : lines.slice(Math.max(0, at - 5), at + 30).join("\n"); -} - -let mismatches = 0; -for (const variant of variants) { - const originals = new Map(); - for (const edit of variant.edits) { - const text = originals.get(edit.file) ?? readFileSync(edit.file, "utf8"); - if (!originals.has(edit.file)) originals.set(edit.file, text); - const current = readFileSync(edit.file, "utf8"); - if (current.split(edit.from).length !== 2) throw Error(`${variant.name}: anchor not found exactly once in ${edit.file}`); - writeFileSync(edit.file, current.replace(edit.from, edit.to)); - } - try { - const result = run(variant.name); - const named = result.output.includes("REFERENCE_ACCESS_HELD_NOT_RELEASED"); - const ok = variant.expectFailure ? result.code !== 0 && named : result.code === 0; - if (!ok) mismatches++; - console.log(`RECEIPT_2819 ${JSON.stringify({ variant: variant.name, exit: result.code, seconds: result.seconds, namedAssertion: named, asExpected: ok })}`); - if (variant.expectFailure || !ok) console.log(excerpt(result.output, "REFERENCE_ACCESS_HELD_NOT_RELEASED")); - } finally { for (const [file, text] of originals) writeFileSync(file, text); } -} - -// Ten clean runs while parallel load holds the host, as in the reported failures. -const load = [ - ...[0, 1].map(() => Bun.spawn(["nice", "-n", "5", "sh", "-c", "while :; do :; done"], { stdout: "ignore", stderr: "ignore" })), - Bun.spawn(["sh", "-c", `while :; do dd if=/dev/urandom of=${join(root, "tmp/receipt-2819-load.bin")} bs=1M count=256 conv=fsync status=none; done`], { stdout: "ignore", stderr: "ignore" }), -]; -let clean = 0, attempted = 0; -try { - while (attempted < 10 && Date.now() < deadline) { - attempted++; - const result = run(`clean+load ${attempted}`); - if (result.code === 0) clean++; else { mismatches++; console.log(excerpt(result.output, "REFERENCE_")); } - console.log(`RECEIPT_2819 ${JSON.stringify({ variant: "clean+load", attempt: attempted, exit: result.code, seconds: result.seconds })}`); - } -} finally { for (const child of load) child.kill("SIGKILL"); } -console.log(`RECEIPT_2819_SUMMARY ${JSON.stringify({ cleanPassed: clean, cleanAttempted: attempted, mismatches, elapsedSeconds: (Date.now() - started) / 1000 })}`); -if (mismatches || clean < 10) process.exitCode = 1;