Skip to content

Commit b91382f

Browse files
committed
🔬 Capture host assertion failures after a recorded prefix
1 parent 63eef68 commit b91382f

12 files changed

Lines changed: 920 additions & 108 deletions

File tree

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
name: One fallback attribution capture
22
on:
33
push:
4-
branches: [codex/fallback-attribution-owner-35749f4]
4+
branches: [codex/fallback-host-plugin-35749f4]
55
permissions:
66
contents: read
77
jobs:
88
capture:
99
runs-on: ubuntu-26.04
10-
timeout-minutes: 20
10+
timeout-minutes: 25
1111
steps:
1212
- name: Retain initial envelope before checkout or runtime setup
1313
run: |
14-
mkdir -p "$RUNNER_TEMP/fallback-capture/evidence"
15-
printf '{"schema":"fallback-initial.v1","consumerExecutions":0,"status":"before-checkout-and-setup","envelope":"%s","run":"%s","attempt":"%s","image":"%s","runner":"%s"}\n' "$GITHUB_SHA" "$GITHUB_RUN_ID" "$GITHUB_RUN_ATTEMPT" "$ImageVersion" "$RUNNER_NAME" > "$RUNNER_TEMP/fallback-capture/evidence/initial-manifest.json"
16-
uname -a > "$RUNNER_TEMP/fallback-capture/evidence/initial-uname.txt"
17-
cat /etc/os-release > "$RUNNER_TEMP/fallback-capture/evidence/initial-os-release.txt"
14+
mkdir -p "$RUNNER_TEMP/fallback-host-attribution/evidence"
15+
printf '{"schema":"fallback-initial.v1","consumerExecutions":0,"status":"before-checkout-and-setup","envelope":"%s","run":"%s","attempt":"%s","image":"%s","runner":"%s"}\n' "$GITHUB_SHA" "$GITHUB_RUN_ID" "$GITHUB_RUN_ATTEMPT" "$ImageVersion" "$RUNNER_NAME" > "$RUNNER_TEMP/fallback-host-attribution/evidence/initial-manifest.json"
16+
uname -a > "$RUNNER_TEMP/fallback-host-attribution/evidence/initial-uname.txt"
17+
cat /etc/os-release > "$RUNNER_TEMP/fallback-host-attribution/evidence/initial-os-release.txt"
1818
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
1919
with:
2020
fetch-depth: 0
@@ -32,27 +32,41 @@ jobs:
3232
- name: Admit runner and complete outer diagnostic preflights
3333
run: |
3434
runner_binary="$(readlink -f "/proc/$PPID/exe")"
35-
printf '%s\n' "$runner_binary" > "$RUNNER_TEMP/fallback-capture/evidence/runner-worker-path.txt"
35+
printf '%s\n' "$runner_binary" > "$RUNNER_TEMP/fallback-host-attribution/evidence/runner-worker-path.txt"
3636
export CAPTURE_RUNNER_VERSION="$("$(dirname "$runner_binary")/Runner.Listener" --version)"
3737
deno run --allow-all --node-modules-dir=none --frozen scripts/fallback-capture-deno.ts preflight
38-
cp "$RUNNER_TEMP/fallback-capture/evidence/manifest.json" "$RUNNER_TEMP/fallback-capture/evidence/preflight-manifest.json"
39-
cp "$RUNNER_TEMP/fallback-capture/evidence/provenance.json" "$RUNNER_TEMP/fallback-capture/evidence/preflight-provenance.json"
38+
cp "$RUNNER_TEMP/fallback-host-attribution/evidence/manifest.json" "$RUNNER_TEMP/fallback-host-attribution/evidence/preflight-manifest.json"
4039
- name: Prepare exact product after successful outer preflight
4140
run: |
4241
runner_binary="$(readlink -f "/proc/$PPID/exe")"
43-
printf '%s\n' "$runner_binary" > "$RUNNER_TEMP/fallback-capture/evidence/runner-worker-prepare-path.txt"
42+
printf '%s\n' "$runner_binary" > "$RUNNER_TEMP/fallback-host-attribution/evidence/runner-worker-prepare-path.txt"
4443
export CAPTURE_RUNNER_VERSION="$("$(dirname "$runner_binary")/Runner.Listener" --version)"
4544
deno run --allow-all --node-modules-dir=none --frozen scripts/fallback-capture-deno.ts prepare
46-
cp "$RUNNER_TEMP/fallback-capture/evidence/manifest.json" "$RUNNER_TEMP/fallback-capture/evidence/prepare-manifest.json"
47-
cp "$RUNNER_TEMP/fallback-capture/evidence/provenance.json" "$RUNNER_TEMP/fallback-capture/evidence/prepare-provenance.json"
45+
cp "$RUNNER_TEMP/fallback-host-attribution/evidence/manifest.json" "$RUNNER_TEMP/fallback-host-attribution/evidence/prepare-manifest.json"
46+
- name: Replay fixed original prefix before either overlay
47+
timeout-minutes: 9
48+
run: |
49+
runner_binary="$(readlink -f "/proc/$PPID/exe")"
50+
export CAPTURE_RUNNER_VERSION="$("$(dirname "$runner_binary")/Runner.Listener" --version)"
51+
deno run --allow-all --node-modules-dir=none --frozen scripts/fallback-capture-deno.ts prefix
52+
cp "$RUNNER_TEMP/fallback-host-attribution/evidence/manifest.json" "$RUNNER_TEMP/fallback-host-attribution/evidence/prefix-manifest.json"
53+
- name: Apply two overlays after prefix and baseline proof
54+
run: |
55+
runner_binary="$(readlink -f "/proc/$PPID/exe")"
56+
export CAPTURE_RUNNER_VERSION="$("$(dirname "$runner_binary")/Runner.Listener" --version)"
57+
deno run --allow-all --node-modules-dir=none --frozen scripts/fallback-capture-deno.ts overlay
58+
cp "$RUNNER_TEMP/fallback-host-attribution/evidence/manifest.json" "$RUNNER_TEMP/fallback-host-attribution/evidence/overlay-manifest.json"
4859
- name: Capture complete original consumer once after successful preparation
4960
timeout-minutes: 6
50-
run: deno run --allow-all --node-modules-dir=none --frozen scripts/fallback-capture-deno.ts consume
61+
run: |
62+
runner_binary="$(readlink -f "/proc/$PPID/exe")"
63+
export CAPTURE_RUNNER_VERSION="$("$(dirname "$runner_binary")/Runner.Listener" --version)"
64+
deno run --allow-all --node-modules-dir=none --frozen scripts/fallback-capture-deno.ts consume
5165
- name: Retain partial evidence after every terminal outcome
5266
if: always()
5367
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
5468
with:
55-
name: fallback-capture-35749f4-${{ github.run_id }}-attempt-${{ github.run_attempt }}
56-
path: ${{ runner.temp }}/fallback-capture/evidence
69+
name: fallback-host-attribution-35749f4-${{ github.run_id }}-attempt-${{ github.run_attempt }}
70+
path: ${{ runner.temp }}/fallback-host-attribution/evidence
5771
include-hidden-files: true
5872
if-no-files-found: error

‎examples/adversarial-implementation/tests/components/Fixture/Entry.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ returns: {type: object}
2020
```bash exec as="location"
2121
pwd -P
2222
```
23-
<Let as="entryArguments" value={[props.root + "/examples/adversarial-implementation/" + ({"delivery-case":"tests/DeliveryCase","planning-case":"tests/PlanningCase","fallback-case":"tests/FallbackCase"}[props.entry] ?? props.entry) + ".md","--props-" + (props.entry === "phase" ? "request" : props.entry === "run" ? "task" : "record"),props.taskPath ?? location.stdout.trim() + "/input.json",...(props.steps === undefined ? [] : ["--props-steps",String(props.steps)]),"--raw","--include",props.root + "/examples/adversarial-implementation/tests/components","--include",props.root + "/examples/adversarial-implementation/components"].map(value => "'" + value.replaceAll("'","'\"'\"'") + "'").join(" ")} />
23+
<Let as="entryArguments" value={[props.root + "/examples/adversarial-implementation/" + ({"delivery-case":"tests/DeliveryCase","planning-case":"tests/PlanningCase","fallback-case":"tests/FallbackCase"}[props.entry] ?? props.entry) + ".md","--props-" + (props.entry === "phase" ? "request" : props.entry === "run" ? "task" : "record"),props.taskPath ?? location.stdout.trim() + "/input.json",...(props.steps === undefined ? [] : ["--props-steps",String(props.steps)]),"--raw","--include",props.root + "/examples/adversarial-implementation/tests/components","--include",props.root + "/examples/adversarial-implementation/components","--plugin",props.root + "/packages/cli/tests/fixtures/failure-attribution-plugin.mjs"].map(value => "'" + value.replaceAll("'","'\"'\"'") + "'").join(" ")} />
2424
<Let as="directory" value={"'" + (props.repository ?? (props.entry === "run" ? props.value.repository : location.stdout.trim())).replaceAll("'","'\"'\"'") + "'"} />
2525
```bash exec as="child"
2626
set -e
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import { Component, Plugin } from "@executablemd/core/api";
2+
import { ensure } from "effection";
3+
import { ensureDir, readTextFile, writeTextFile } from "@effectionx/fs";
4+
import { createHash } from "node:crypto";
5+
import { fileURLToPath } from "node:url";
6+
import { join, resolve } from "node:path";
7+
import process from "node:process";
8+
9+
function data(value, key) {
10+
if (typeof value !== "object" || value === null) {
11+
return undefined;
12+
}
13+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
14+
return descriptor && "value" in descriptor ? descriptor.value : undefined;
15+
}
16+
function text(value) {
17+
return typeof value === "string"
18+
? value.length <= 8192
19+
? value
20+
: { availability: "truncated", prefix: value.slice(0, 8192), length: value.length }
21+
: { availability: "not-own-string-data" };
22+
}
23+
export default Plugin({
24+
name: "fixture-failure-attribution",
25+
*install() {
26+
const candidates = [];
27+
let observed = 0;
28+
let overflow = 0;
29+
yield* ensure(function* () {
30+
const destination = process.env.XMD_TEST_ARTIFACTS;
31+
if (!observed || !destination) {
32+
return;
33+
}
34+
const directory = join(destination, "failure-attribution");
35+
const identity = `${process.pid}-${crypto.randomUUID()}`;
36+
try {
37+
yield* ensureDir(directory);
38+
for (const candidate of candidates) {
39+
const record = candidate.record;
40+
if (typeof record.position.path !== "string") {
41+
record.source = { availability: "missing-path" };
42+
continue;
43+
}
44+
try {
45+
const path = record.position.path.startsWith("file:")
46+
? fileURLToPath(record.position.path)
47+
: resolve(process.cwd(), record.position.path);
48+
const source = yield* readTextFile(path);
49+
record.source = {
50+
path: record.position.path,
51+
sha256: createHash("sha256").update(source).digest("hex"),
52+
elementAtOffset: source.slice(record.position.offset).startsWith(`<${record.name}`),
53+
};
54+
} catch {
55+
record.source = { availability: "source-unreadable" };
56+
}
57+
}
58+
function serialized() {
59+
return JSON.stringify(
60+
{
61+
schema: "fixture-failure-attribution.v1",
62+
pid: process.pid,
63+
classification: "observed; not proof of terminal attribution",
64+
observed,
65+
overflow,
66+
limits: { candidates: 16, stringCharacters: 8192, metadataBytes: 1048576 },
67+
candidates: candidates.map(({ record }) => record),
68+
},
69+
undefined,
70+
2,
71+
);
72+
}
73+
let metadata = serialized();
74+
while (new TextEncoder().encode(metadata).length > 1048576 && candidates.length) {
75+
const lowest = Math.min(...candidates.map((candidate) => candidate.priority));
76+
const remove = candidates.findLastIndex((candidate) => candidate.priority === lowest);
77+
candidates.splice(remove, 1);
78+
overflow++;
79+
metadata = serialized();
80+
}
81+
yield* writeTextFile(join(directory, identity + ".json"), metadata);
82+
} catch (error) {
83+
// Diagnostics cannot replace the command's selected outcome.
84+
try {
85+
yield* writeTextFile(
86+
join(directory, identity + "-capture-error.json"),
87+
JSON.stringify({ incomplete: true, error: text(data(error, "message")) }),
88+
);
89+
} catch {
90+
// The unavailable destination cannot carry an auxiliary fault either.
91+
}
92+
}
93+
});
94+
yield* Component.around({
95+
*handleFailure([failure], next) {
96+
observed++;
97+
const environment = yield* Component.operations.env;
98+
const position = failure.position;
99+
const record = {
100+
observation: observed,
101+
classification: "observed",
102+
name: text(failure.name),
103+
origin: failure.origin ?? null,
104+
position:
105+
position === undefined
106+
? { availability: "missing" }
107+
: {
108+
path: text(data(position, "path")),
109+
offset: data(position, "offset"),
110+
line: data(position, "line"),
111+
column: data(position, "column"),
112+
},
113+
scenario: text(data(data(environment, "values"), "scenario")),
114+
errorName: text(data(failure.error, "name")),
115+
message: text(data(failure.error, "message")),
116+
report: text(data(failure.error, "report")),
117+
detail: {
118+
actual: text(data(data(failure.error, "detail"), "actual")),
119+
expected: text(data(data(failure.error, "detail"), "expected")),
120+
},
121+
};
122+
const repeated = candidates.find((candidate) => candidate.error === failure.error);
123+
if (repeated) {
124+
repeated.record.repeatedCount = (repeated.record.repeatedCount ?? 0) + 1;
125+
repeated.record.lastRepeatedObservation = observed;
126+
overflow++;
127+
} else {
128+
const path = data(position, "path");
129+
const priority =
130+
typeof path === "string" &&
131+
/(?:^|\/)examples\/adversarial-implementation\/tests\/components\/Fixture\/Fallback\.md$/.test(
132+
path.replaceAll("\\", "/"),
133+
) &&
134+
/^Assert\w*$/.test(failure.name)
135+
? 2
136+
: 1;
137+
const candidate = { error: failure.error, priority, record };
138+
if (candidates.length < 16) {
139+
candidates.push(candidate);
140+
} else {
141+
const replace = candidates.findIndex(
142+
(entry) =>
143+
entry.priority < priority || (priority === 2 && entry.priority === priority),
144+
);
145+
if (replace !== -1) {
146+
candidates.splice(replace, 1, candidate);
147+
}
148+
overflow++;
149+
}
150+
}
151+
return yield* next(failure);
152+
},
153+
});
154+
},
155+
});

0 commit comments

Comments
 (0)