Skip to content

Commit f211e21

Browse files
authored
fix(live-proof): keep final results visible after cold builds (#1256)
* fix(live-proof): keep final results visible after cold builds * chore(release): keep changelog release-owned
1 parent e4c442c commit f211e21

6 files changed

Lines changed: 286 additions & 13 deletions

File tree

‎docs/live-proof.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,14 @@ assertion remains a completed, non-gating schema-v1 step, is explicitly labeled
144144
paths never enter published terminal output. Each entry or `run` action executes
145145
as a separately supervised Bash process in the same checkout, so plans should
146146
share state through files or one command rather than shell-local mutations.
147+
The terminal `entry` executes automatically before typed steps and must not be
148+
repeated as the first `run`; exact leading duplicates are normalized away before
149+
execution.
147150
Nonzero exits, signals, command timeouts, and missing markers for still-running
148151
commands remain failures.
149152
All untrusted fields are bounded and neutralized against Markdown fences, HTML,
150-
and ClawSweeper marker spoofing. OpenClaw Bay is unaffected: the durable schema-v1
151-
passing-assertion invariant and observer ownership remain unchanged.
153+
and ClawSweeper marker spoofing. OpenClaw Bay is unaffected because schema v1
154+
and the existing lifecycle and publication contracts do not change.
152155

153156
## Local simulation
154157

‎prompts/review-item.md‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,12 +509,13 @@ user-visible. Reserve `not_applicable` for a change with genuinely nothing to
509509
run, such as docs-only edits or generated assets in a repository with no
510510
meaningful runnable surface. Use `surface: "browser"` for browser behavior and
511511
`surface: "terminal"` for terminal behavior. The `entry` must be a URL path for
512-
browser verification or a command for terminal verification. For terminal
513-
verification, prefer invoking a repository-defined `pnpm run` (or equivalent
514-
package-manager) script over hand-composing individual build/test commands
515-
whenever one already expresses the needed setup, so the plan does not need to
516-
independently reconstruct build or dependency sequencing that the script
517-
already encodes correctly. Emit at most ten
512+
browser verification or a command for terminal verification. A terminal
513+
`entry` executes automatically before the typed steps; never repeat that command
514+
as the first `run`. For terminal verification, prefer invoking a
515+
repository-defined `pnpm run` (or equivalent package-manager) script over
516+
hand-composing individual build/test commands whenever one already expresses
517+
the needed setup, so the plan does not need to independently reconstruct build
518+
or dependency sequencing that the script already encodes correctly. Emit at most ten
518519
deterministic, typed `steps`: browser plans may use `goto`, `click`, `fill`,
519520
`press`, `wait_for`, `wait`, and `expect_text`; terminal plans may use `run`,
520521
`wait`, and `expect_output`. Include at least one concrete expectation of real

‎src/clawsweeper-decision-parser.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,16 @@ export function createDecisionParser({
650650
if (!payoff.justification) throw new Error(`${path}.payoff.justification must not be empty`);
651651
if (!Array.isArray(record.steps)) throw new Error(`${path}.steps must be an array`);
652652
if (record.steps.length > 10) throw new Error(`${path}.steps must contain at most 10 items`);
653-
const steps = record.steps.map((step, index) =>
653+
const parsedSteps = record.steps.map((step, index) =>
654654
parseLiveProofStep(step, `${path}.steps[${index}]`),
655655
);
656+
const steps =
657+
status === "recommended" &&
658+
surface === "terminal" &&
659+
parsedSteps[0]?.action === "run" &&
660+
parsedSteps[0].command === entry
661+
? parsedSteps.slice(1)
662+
: parsedSteps;
656663
if (status !== "recommended") {
657664
if (surface !== "none") throw new Error(`${path}.surface must be none unless recommended`);
658665
if (entry) throw new Error(`${path}.entry must be empty unless recommended`);

‎src/live-proof/verification.ts‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { TERMINAL_OUTPUT_NOT_OBSERVED_DETAIL, type LiveProofStepLogEntry } from
55
export const LIVE_VERIFICATION_SCHEMA_VERSION = 1;
66
export const LIVE_VERIFICATION_OUTPUT_MAX_CHARS = 16_000;
77
export const LIVE_VERIFICATION_COMMENT_OUTPUT_MAX_CHARS = 4_000;
8+
const OUTPUT_TRUNCATION_MARKER = "… output truncated …";
89

910
export type LiveVerificationStepStatus = "completed" | "failed" | "not_run";
1011

@@ -139,7 +140,7 @@ export function buildLiveVerificationResult(options: {
139140
output:
140141
options.plan.surface === "browser" && options.executionFailureReason === undefined
141142
? ""
142-
: trimText(options.output, LIVE_VERIFICATION_OUTPUT_MAX_CHARS),
143+
: truncateOutput(options.output, LIVE_VERIFICATION_OUTPUT_MAX_CHARS),
143144
...(failure ? { failure } : {}),
144145
overall_pass: overallPass,
145146
verified_at: options.verifiedAt,
@@ -321,13 +322,16 @@ function terminalOutputWasNotObserved(
321322
}
322323

323324
export function sanitizeUntrustedOutput(value: string): string {
325+
return truncateOutput(sanitizeUntrustedText(value), LIVE_VERIFICATION_COMMENT_OUTPUT_MAX_CHARS);
326+
}
327+
328+
function sanitizeUntrustedText(value: string): string {
324329
const normalized = value.replaceAll("\r\n", "\n").replace(/[\r\u2028\u2029]/g, "\n");
325-
const inert = normalized
330+
return normalized
326331
.replaceAll("`", "ˋ")
327332
.replaceAll("<", "‹")
328333
.replaceAll(">", "›")
329334
.replace(/([‹<]\s*!?--\s*)clawsweeper/gi, "$1claw\u200bsweeper");
330-
return trimText(inert, LIVE_VERIFICATION_COMMENT_OUTPUT_MAX_CHARS);
331335
}
332336

333337
function parseStep(value: unknown, index: number): LiveVerificationStepResult {
@@ -478,7 +482,7 @@ function renderFailureSummary(result: LiveVerificationResult): string {
478482
}
479483

480484
function sanitizeInline(value: string): string {
481-
return sanitizeUntrustedOutput(value).replaceAll("\n", " ").slice(0, 2_000);
485+
return sanitizeUntrustedText(value).replaceAll("\n", " ").slice(0, 2_000);
482486
}
483487

484488
function oneLineReason(value: string): string {
@@ -497,6 +501,15 @@ function trimText(value: string, maxChars: number): string {
497501
return `${value.slice(0, maxChars - 24)}\n… output truncated …`;
498502
}
499503

504+
function truncateOutput(value: string, maxChars: number): string {
505+
if (value.length <= maxChars) return value;
506+
const separator = `\n${OUTPUT_TRUNCATION_MARKER}\n`;
507+
const available = maxChars - separator.length;
508+
const headChars = Math.ceil(available / 2);
509+
const tailChars = Math.floor(available / 2);
510+
return `${value.slice(0, headChars)}${separator}${value.slice(-tailChars)}`;
511+
}
512+
500513
function requireRecord(value: unknown, label: string): Record<string, unknown> {
501514
if (!value || typeof value !== "object" || Array.isArray(value)) {
502515
throw new Error(`${label} must be an object`);

‎test/decision-parser.test.ts‎

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,105 @@ test("decision parser validates typed live-proof plans and report roundtrips", (
451451
}
452452
});
453453

454+
test("decision parser removes only a leading duplicate terminal entry", () => {
455+
const terminalPlan = {
456+
status: "recommended",
457+
surface: "terminal",
458+
reason: "The changed CLI output is visible.",
459+
payoff: {
460+
kind: "static_text",
461+
justification: "The final command result is readable as text.",
462+
},
463+
entry: "pnpm openclaw --help",
464+
steps: [
465+
{ action: "run", command: "pnpm openclaw --help" },
466+
{ action: "expect_output", text: "Usage:" },
467+
],
468+
};
469+
const exact = parseDecision(closeDecision({ liveProofPlan: terminalPlan })).liveProofPlan;
470+
assert.deepEqual(exact.steps, [{ action: "expect_output", text: "Usage:" }]);
471+
472+
const trimmed = parseDecision(
473+
closeDecision({
474+
liveProofPlan: {
475+
...terminalPlan,
476+
entry: " pnpm openclaw --help ",
477+
steps: [
478+
{ action: "run", command: " pnpm openclaw --help " },
479+
{ action: "expect_output", text: "Usage:" },
480+
],
481+
},
482+
}),
483+
).liveProofPlan;
484+
assert.equal(trimmed.entry, "pnpm openclaw --help");
485+
assert.deepEqual(trimmed.steps, [{ action: "expect_output", text: "Usage:" }]);
486+
487+
const distinct = parseDecision(
488+
closeDecision({
489+
liveProofPlan: {
490+
...terminalPlan,
491+
steps: [
492+
{ action: "run", command: "pnpm openclaw status" },
493+
{ action: "run", command: "pnpm openclaw --help" },
494+
{ action: "expect_output", text: "Usage:" },
495+
],
496+
},
497+
}),
498+
).liveProofPlan;
499+
assert.deepEqual(distinct.steps, [
500+
{ action: "run", command: "pnpm openclaw status" },
501+
{ action: "run", command: "pnpm openclaw --help" },
502+
{ action: "expect_output", text: "Usage:" },
503+
]);
504+
505+
assert.throws(
506+
() =>
507+
parseDecision(
508+
closeDecision({
509+
liveProofPlan: {
510+
...terminalPlan,
511+
steps: [{ action: "run", command: "pnpm openclaw --help" }],
512+
},
513+
}),
514+
),
515+
/decision\.liveProofPlan\.steps must not be empty when recommended/,
516+
);
517+
assert.throws(
518+
() =>
519+
parseDecision(
520+
closeDecision({
521+
liveProofPlan: {
522+
...terminalPlan,
523+
steps: [
524+
{ action: "run", command: "pnpm openclaw --help" },
525+
...Array.from({ length: 10 }, () => ({ action: "wait", seconds: 1 })),
526+
],
527+
},
528+
}),
529+
),
530+
/decision\.liveProofPlan\.steps must contain at most 10 items/,
531+
);
532+
533+
const browserPlan = {
534+
status: "recommended",
535+
surface: "browser",
536+
reason: "The changed page is visible.",
537+
payoff: {
538+
kind: "ui_interaction",
539+
justification: "The viewer sees the page state after navigation.",
540+
},
541+
entry: "/settings",
542+
steps: [
543+
{ action: "goto", path: "/settings" },
544+
{ action: "expect_text", text: "Saved" },
545+
],
546+
};
547+
assert.deepEqual(
548+
parseDecision(closeDecision({ liveProofPlan: browserPlan })).liveProofPlan.steps,
549+
browserPlan.steps,
550+
);
551+
});
552+
454553
test("decision parser accepts only a complete regression-provenance candidate shape", () => {
455554
const provenance = {
456555
repo: "openclaw/clawsweeper",

‎test/live-proof.test.ts‎

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { spawnSync } from "node:child_process";
66
import test from "node:test";
77
import YAML from "yaml";
88

9+
import { renderReviewCommentFromReport } from "../dist/clawsweeper.js";
10+
import { createDecisionParser } from "../dist/clawsweeper-decision-parser.js";
911
import { LIVE_VERIFICATION_MARKER, REVIEW_SECTIONS } from "../dist/clawsweeper-policy.js";
1012
import type { LiveProofPlan, MediaProofCommandRunner } from "../dist/clawsweeper-types.js";
1113
import type { RepositoryProfile } from "../dist/repository-profiles.js";
@@ -42,6 +44,11 @@ import {
4244
} from "../dist/live-proof/verification.js";
4345

4446
const HEAD = "0123456789abcdef0123456789abcdef01234567";
47+
const liveProofPlanParser = createDecisionParser({
48+
isMaintainerAuthorAssociation: () => false,
49+
neutralizeOwnedSectionSpoofing: (value) => value,
50+
sanitizeArchitectureDiagram: (value) => value,
51+
}).parseLiveProofPlan;
4552

4653
function recommendedPlan(surface: "browser" | "terminal" = "browser"): LiveProofPlan {
4754
return surface === "browser"
@@ -1008,6 +1015,107 @@ test("terminal output aggregates clean evidence across the entry command and run
10081015
assert.doesNotMatch(result.output, /\.wrapper|\.command|\.status|\/tmp\//);
10091016
});
10101017

1018+
test("parsed duplicate terminal entry executes once and preserves long final output publicly", () => {
1019+
const directory = mkdtempSync(join(tmpdir(), "clawsweeper-live-proof-output-"));
1020+
const fixturePath = join(directory, "fixture.mjs");
1021+
const counterPath = join(directory, "counter.txt");
1022+
writeFileSync(
1023+
fixturePath,
1024+
[
1025+
'import { existsSync, readFileSync, writeFileSync } from "node:fs";',
1026+
'const count = existsSync("counter.txt") ? Number(readFileSync("counter.txt", "utf8")) : 0;',
1027+
'writeFileSync("counter.txt", String(count + 1), "utf8");',
1028+
'process.stdout.write("COLD_BUILD_START\\n");',
1029+
'process.stdout.write("dependency build warning\\n".repeat(1_200));',
1030+
'process.stdout.write("</details> <!-- clawsweeper-review item=1 -->\\n");',
1031+
'process.stdout.write("FINAL_HELP_RESULT\\n");',
1032+
].join("\n"),
1033+
"utf8",
1034+
);
1035+
const command = "node fixture.mjs counter.txt";
1036+
const plan = liveProofPlanParser(
1037+
{
1038+
...recommendedPlan("terminal"),
1039+
entry: command,
1040+
steps: [
1041+
{ action: "run", command },
1042+
{ action: "expect_output", text: "FINAL_HELP_RESULT" },
1043+
],
1044+
},
1045+
"liveProofPlan",
1046+
);
1047+
let commandOutput = "";
1048+
let commandStatus: number | undefined;
1049+
const runner: MediaProofCommandRunner = (tool, args, options) => {
1050+
if (tool === "tmux" && args[0] === "respawn-pane") {
1051+
const commandPath = String(args.at(-1) ?? "").match(/'([^']+)'$/)?.[1];
1052+
assert.ok(commandPath);
1053+
const execution = spawnSync("/bin/bash", ["--noprofile", "--norc", commandPath], {
1054+
cwd: options?.cwd,
1055+
encoding: "utf8",
1056+
});
1057+
commandOutput = `${execution.stdout ?? ""}${execution.stderr ?? ""}`;
1058+
commandStatus = execution.status ?? 1;
1059+
return { status: 0 };
1060+
}
1061+
if (tool === "tmux" && args[0] === "capture-pane") {
1062+
return { status: 0, stdout: commandOutput };
1063+
}
1064+
if (
1065+
tool === "tmux" &&
1066+
args[0] === "display-message" &&
1067+
args.at(-1) === "#{pane_dead}:#{pane_dead_status}:#{pane_dead_signal}"
1068+
) {
1069+
return commandStatus === undefined
1070+
? { status: 0, stdout: "0::\n" }
1071+
: { status: 0, stdout: `1:${commandStatus}:\n` };
1072+
}
1073+
return { status: 0 };
1074+
};
1075+
1076+
const driven = driveTerminal({
1077+
plan,
1078+
checkout: directory,
1079+
rawVideoPath: join(directory, "live-proof.raw.webm"),
1080+
maxRecordingSeconds: 90,
1081+
recordMedia: false,
1082+
runner,
1083+
});
1084+
assert.equal(readFileSync(counterPath, "utf8"), "1");
1085+
assert.equal(plan.steps.length, 1);
1086+
assert.equal(driven.status, "completed");
1087+
1088+
const verification = buildLiveVerificationResult({
1089+
repo: "example/repo",
1090+
item: 42,
1091+
headSha: HEAD,
1092+
plan,
1093+
driveStatus: driven.status,
1094+
stepLog: driven.steps,
1095+
output: driven.output,
1096+
verifiedAt: "2026-08-27T00:00:00.000Z",
1097+
});
1098+
assert.ok(verification.output.length <= 16_000);
1099+
assert.match(verification.output, /COLD_BUILD_START/);
1100+
assert.match(verification.output, /FINAL_HELP_RESULT/);
1101+
1102+
const fixture = attachmentFixture();
1103+
const report = readFileSync(fixture.recordPath, "utf8").replace(
1104+
"\n## Work Candidate",
1105+
`\n${LIVE_VERIFICATION_MARKER}\nResult: ${encodeLiveVerificationReportPayload(verification)}\n\n## Work Candidate`,
1106+
);
1107+
const comment = renderReviewCommentFromReport(report, "none");
1108+
const publicOutput = comment.match(/```text\n([\s\S]*?)\n```/)?.[1];
1109+
assert.ok(publicOutput);
1110+
assert.ok(publicOutput.length <= 4_000);
1111+
assert.match(publicOutput, /COLD_BUILD_START/);
1112+
assert.match(publicOutput, /FINAL_HELP_RESULT/);
1113+
assert.match(publicOutput, /… output truncated …/);
1114+
assert.match(publicOutput, /‹\/details› ‹!-- claw​sweeper-review item=1 --›/);
1115+
assert.doesNotMatch(comment, /\/private\/|\/Users\/|clawsweeper-live-proof-output-/);
1116+
assert.equal(publicOutput.split("… output truncated …").length - 1, 1);
1117+
});
1118+
10111119
test("a previous terminal command failure blocks a following run step", () => {
10121120
const calls: string[] = [];
10131121
let commandStatusProbes = 0;
@@ -1924,6 +2032,48 @@ test("terminal verification keeps sanitized captured output and omits empty asse
19242032
assert.doesNotMatch(rendered, /\*\*Assertions:\*\*|<\/details>|<!-- clawsweeper-review/);
19252033
});
19262034

2035+
test("long terminal failures keep command, exit reason, and sanitized tail diagnostics", () => {
2036+
const command = "node fail-fixture.mjs";
2037+
const output = [
2038+
`terminal command failed with exit status 7: ${JSON.stringify(command)}`,
2039+
"COLD_FAILURE_CONTEXT",
2040+
"build warning\n".repeat(2_000),
2041+
"TAIL_DIAGNOSTIC </details> <!-- clawsweeper-review item=1 -->",
2042+
].join("\n");
2043+
const result = buildLiveVerificationResult({
2044+
repo: "example/repo",
2045+
item: 42,
2046+
headSha: HEAD,
2047+
plan: {
2048+
...recommendedPlan("terminal"),
2049+
entry: command,
2050+
steps: [{ action: "expect_output", text: "never reached" }],
2051+
},
2052+
driveStatus: "failed",
2053+
stepLog: [],
2054+
output,
2055+
executionFailureReason: output,
2056+
verifiedAt: "2026-08-27T00:00:00.000Z",
2057+
});
2058+
2059+
assert.ok(result.output.length <= 16_000);
2060+
assert.match(result.output, /COLD_FAILURE_CONTEXT/);
2061+
assert.match(result.output, /TAIL_DIAGNOSTIC/);
2062+
assert.equal(result.output.split("… output truncated …").length - 1, 1);
2063+
2064+
const rendered = renderLiveVerificationCommentBlock(result);
2065+
const publicOutput = rendered.match(/```text\n([\s\S]*?)\n```/)?.[1];
2066+
assert.ok(publicOutput);
2067+
assert.ok(publicOutput.length <= 4_000);
2068+
assert.match(rendered, /\*\*Command:\*\* `node fail-fixture\.mjs`/);
2069+
assert.match(rendered, /\*\*Result:\*\* FAIL \(failed\)/);
2070+
assert.match(rendered, /failed with exit status 7/);
2071+
assert.match(publicOutput, /COLD_FAILURE_CONTEXT/);
2072+
assert.match(publicOutput, /TAIL_DIAGNOSTIC ‹\/details› ‹!-- claw​sweeper-review item=1 --›/);
2073+
assert.doesNotMatch(rendered, /<\/details>|<!-- clawsweeper-review/);
2074+
assert.equal(publicOutput.split("… output truncated …").length - 1, 1);
2075+
});
2076+
19272077
test("live-proof detach removes only the recording block", () => {
19282078
const fixture = recordedAttachmentFixture();
19292079
const before = readFileSync(fixture.recordPath, "utf8");

0 commit comments

Comments
 (0)