Skip to content

Commit 74b0f85

Browse files
authored
fix(review): stop rejecting the approved autoreview fixture (#1309)
* fix(review): stop rejecting the approved autoreview fixture * fix(review): bind fixture approval to every scanned endpoint
1 parent c179a46 commit 74b0f85

5 files changed

Lines changed: 291 additions & 60 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ checkpoint, and status-only commits are intentionally omitted.
6464

6565
### Fixed
6666

67+
- Classified the explicitly approved autoreview fixture only by its exact full-URI digest and canonical or vendored source path, enforcing the same digest/path/mode policy at every scanned endpoint for all reviewed fixtures while preserving scanner gates and value-free audits.
6768
- Stopped treating pane-local runtime state as stored data while retaining warnings for explicit persistence changes and incomplete storage patches.
6869
- Corrected retained terminal-proof cleanup for independent process-exit and PTY-close events, preserving the original wrapper failure and draining dead-pane capture only after verified cleanup.
6970
- Prevented rejected model inputs from surviving in generated prompt artifacts; retained diagnostics now follow admission with owner-only access, and unused prompt copies are no longer written.

‎README.md‎

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -560,17 +560,33 @@ uses the remaining review deadline; it never silently truncates or bypasses.
560560
Diagnostics omit scanner output and source values. Restore prerequisites or
561561
remove sensitive input before retrying a refusal.
562562

563-
The host classifies one reviewed synthetic malformed-configuration URI in
564-
`test/action-ledger-runtime.test.ts` as non-sensitive after a complete scan.
565-
Its policy binds the exact full finding bytes, detector contract, and literal
566-
line in a host-staged Git blob. It does not trust checkout ignore rules or
567-
domain patterns. Prompt, schema, diff, additional-input, and encoded-only
568-
occurrences remain blocking, as do other findings and incomplete scans.
563+
The host classifies the reviewed synthetic malformed-configuration URI in
564+
`test/action-ledger-runtime.test.ts` and the explicitly approved autoreview
565+
negative-test URI in the [canonical autoreview test](https://github.com/openclaw/agent-skills/blob/a8466c1d860588a083610fe41fd277c1d88b14e0/skills/autoreview/tests/test_autoreview_hardening.py)
566+
or its [vendored OpenClaw copy](https://github.com/openclaw/openclaw/blob/136eab023035dd5943818f791d3c3db7d92e4491/.agents/skills/autoreview/tests/test_autoreview_hardening.py)
567+
as non-sensitive after a complete scan. Static host policy associates each
568+
exact full-URI SHA-256 with only its approved source paths, requiring a literal
569+
at the reported line of a host-staged Git blob from mode `100644`.
570+
Deduplicated blobs retain every scanned logical endpoint's path and Git mode,
571+
including mode-only transitions and shared-path aliases. Every captured reference
572+
must qualify under the same digest's exact path and mode `100644` policy before
573+
any source is eligible for classification or an audit notice.
574+
The policy does not trust checkout ignore rules, domain patterns, fixture words,
575+
test names, or unchanged-line inference; no nearby fixture is implicitly approved.
576+
Findings attributed to prompt, schema, diff, additional-input, other-path, or
577+
encoded-only occurrences remain blocking, as do other findings, verified findings,
578+
and incomplete scans. Unverified findings alone never qualify: every finding must
579+
match the exact bytes, source association, and strict detector contract. This
580+
classification does not expand TruffleHog's detection coverage.
569581
The classification is pinned to TruffleHog 3.97.1's output contract; scanner
570582
upgrades require requalification. See `src/agent-input-scan-fixtures.ts`.
571-
Every accepted classification emits a host-side structured stderr notice with
572-
the fixture digest, source blob, line, decoder, and occurrence count. Raw values
573-
and verification diagnostics never appear in that audit notice.
583+
After successful cleanup and final source fences, each accepted fixture/source
584+
pair emits a host-side structured stderr notice with `event`, `fixtureSha256`,
585+
`source`, `detector`, and `findings` entries containing `blob`, `line`, `decoder`,
586+
and `occurrences`. Counts are per source: a shared blob can appear in both source
587+
notices and those counts must not be summed across sources. A refused or drifted
588+
scan emits no success notice. Raw values and verification diagnostics never
589+
appear in that audit notice.
574590

575591
Generated review and repair prompt diagnostics retire the previous attempt's
576592
copy before admission and persist only successfully scanned exact prompt bytes

‎src/agent-input-scan-fixtures.ts‎

Lines changed: 73 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
11
import { createHash } from "node:crypto";
22
import { basename } from "node:path";
33

4-
// Maintainer-reviewed malformed-config fixture introduced by d68b1861172120fc.
54
// This is host policy, never an allowlist loaded from the reviewed checkout.
6-
export const REVIEWED_FIXTURE_SOURCE = "test/action-ledger-runtime.test.ts";
7-
const FIXTURE_SHA256 = "a728de5dbbef23b8aa5ef2d99060835f4f2fb5a0fa2abb9fe249d08aa09bd09e";
5+
const REVIEWED_FIXTURES = [
6+
{
7+
// Maintainer-reviewed malformed-config fixture introduced by d68b1861172120fc.
8+
fixtureSha256: "a728de5dbbef23b8aa5ef2d99060835f4f2fb5a0fa2abb9fe249d08aa09bd09e",
9+
sources: ["test/action-ledger-runtime.test.ts"],
10+
},
11+
{
12+
// Explicitly approved autoreview negative-test fixture, including its vendored path.
13+
fixtureSha256: "662a886a0fd7447dad0acda3aeccc9eb539fc90438b453de7e2f523ca7ee6c83",
14+
sources: [
15+
"skills/autoreview/tests/test_autoreview_hardening.py",
16+
".agents/skills/autoreview/tests/test_autoreview_hardening.py",
17+
],
18+
},
19+
] as const;
20+
21+
export function reviewedFixtureForSource(source: string, mode: string) {
22+
const fixture =
23+
mode === "100644"
24+
? REVIEWED_FIXTURES.find((entry) => entry.sources.some((path) => path === source))
25+
: undefined;
26+
return fixture ? { fixtureSha256: fixture.fixtureSha256, source } : undefined;
27+
}
28+
29+
export interface ReviewedFixtureBlob {
30+
bytes: Buffer;
31+
references: readonly { source: string; mode: string }[];
32+
}
833

934
interface ClassifiedFinding {
1035
blob: string;
@@ -29,13 +54,13 @@ function records(bytes: Buffer): Record<string, unknown>[] {
2954
.map((line) => object(JSON.parse(line)));
3055
}
3156

32-
/** Classify only complete native scans whose every finding is the reviewed fixture. */
57+
/** Classify only complete native scans whose every finding matches host fixture policy. */
3358
export function classifyReviewedFixtureScan(
3459
stdout: Buffer,
3560
stderr: Buffer,
36-
sourceBlobs: ReadonlyMap<string, Buffer>,
61+
sourceBlobs: ReadonlyMap<string, ReviewedFixtureBlob>,
3762
):
38-
| { fixtureSha256: string; source: string; detector: string; findings: ClassifiedFinding[] }
63+
| { fixtureSha256: string; source: string; detector: string; findings: ClassifiedFinding[] }[]
3964
| undefined {
4065
try {
4166
const findings = records(stdout);
@@ -70,7 +95,10 @@ export function classifyReviewedFixtureScan(
7095
)
7196
return undefined;
7297

73-
const classified = new Map<string, ClassifiedFinding>();
98+
const classified = new Map<
99+
string,
100+
{ fixtureSha256: string; source: string; findings: Map<string, ClassifiedFinding> }
101+
>();
74102
for (const finding of findings) {
75103
if (
76104
finding.DetectorType !== 17 ||
@@ -83,21 +111,28 @@ export function classifyReviewedFixtureScan(
83111
typeof finding.Raw !== "string" ||
84112
// URI Raw omits the path; RawV2 must match the complete reviewed value.
85113
finding.RawV2 !== finding.Raw ||
86-
createHash("sha256").update(finding.Raw).digest("hex") !== FIXTURE_SHA256 ||
87114
finding.ExtraData !== null ||
88115
finding.StructuredData !== null
89116
)
90117
return undefined;
118+
const digest = createHash("sha256").update(finding.Raw).digest("hex");
119+
const fixture = REVIEWED_FIXTURES.find((entry) => entry.fixtureSha256 === digest);
120+
if (!fixture) return undefined;
91121
const source = object(object(object(finding.SourceMetadata).Data).Filesystem);
92-
const bytes = typeof source.file === "string" ? sourceBlobs.get(source.file) : undefined;
122+
const staged = typeof source.file === "string" ? sourceBlobs.get(source.file) : undefined;
93123
if (
94-
!bytes ||
124+
!staged ||
125+
!staged.references.length ||
126+
staged.references.some(
127+
({ source, mode }) =>
128+
reviewedFixtureForSource(source, mode)?.fixtureSha256 !== fixture.fixtureSha256,
129+
) ||
95130
typeof source.line !== "number" ||
96131
!Number.isSafeInteger(source.line) ||
97132
source.line <= 0
98133
)
99134
return undefined;
100-
const line = new TextDecoder("utf-8", { fatal: true }).decode(bytes).split("\n")[
135+
const line = new TextDecoder("utf-8", { fatal: true }).decode(staged.bytes).split("\n")[
101136
source.line - 1
102137
];
103138
// HTML may rediscover an unchanged literal. Encoded-only occurrences,
@@ -114,22 +149,34 @@ export function classifyReviewedFixtureScan(
114149
return undefined;
115150
const blob = basename(source.file as string);
116151
const key = `${blob}:${source.line}:${finding.DecoderName}`;
117-
const previous = classified.get(key);
118-
classified.set(key, {
119-
blob,
120-
line: source.line,
121-
decoder: finding.DecoderName,
122-
occurrences: (previous?.occurrences ?? 0) + 1,
123-
});
152+
const sources = new Set(staged.references.map(({ source }) => source));
153+
for (const path of sources) {
154+
const groupKey = `${digest}:${path}`;
155+
const group = classified.get(groupKey) ?? {
156+
fixtureSha256: digest,
157+
source: path,
158+
findings: new Map<string, ClassifiedFinding>(),
159+
};
160+
const previous = group.findings.get(key);
161+
group.findings.set(key, {
162+
blob,
163+
line: source.line,
164+
decoder: finding.DecoderName,
165+
occurrences: (previous?.occurrences ?? 0) + 1,
166+
});
167+
classified.set(groupKey, group);
168+
}
124169
}
125-
return {
126-
fixtureSha256: FIXTURE_SHA256,
127-
source: REVIEWED_FIXTURE_SOURCE,
128-
detector: "URI",
129-
findings: [...classified.entries()]
130-
.sort(([a], [b]) => a.localeCompare(b))
131-
.map(([, value]) => value),
132-
};
170+
return [...classified.entries()]
171+
.sort(([a], [b]) => a.localeCompare(b))
172+
.map(([, group]) => ({
173+
fixtureSha256: group.fixtureSha256,
174+
source: group.source,
175+
detector: "URI",
176+
findings: [...group.findings.entries()]
177+
.sort(([a], [b]) => a.localeCompare(b))
178+
.map(([, value]) => value),
179+
}));
133180
} catch {
134181
// Scanner output includes credential-shaped bytes; never expose parse errors.
135182
return undefined;

‎src/agent-input-scan.ts‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { fileURLToPath } from "node:url";
2121
import { readReviewGit, reviewMergeBase, type ReviewGitReadOptions } from "./pr-review-evidence.js";
2222
import {
2323
classifyReviewedFixtureScan,
24-
REVIEWED_FIXTURE_SOURCE,
24+
type ReviewedFixtureBlob,
2525
} from "./agent-input-scan-fixtures.js";
2626

2727
export type AgentScanSource =
@@ -124,7 +124,7 @@ export function scanAgentInput(options: {
124124
throw new AgentInputScanError("unsafe_path");
125125
const inputDir = join(root, "input");
126126
mkdirSync(inputDir, { mode: 0o700 });
127-
const reviewedFixtureBlobs = new Map<string, Buffer>();
127+
const reviewedFixtureBlobs = new Map<string, ReviewedFixtureBlob>();
128128
let staged = 0;
129129
let ordinal = 0;
130130
const stage = (bytes: Buffer, name = String(ordinal++)) => {
@@ -337,8 +337,7 @@ export function scanAgentInput(options: {
337337
};
338338
}
339339
assertCurrent();
340-
const blobs = new Set<string>();
341-
const fixtureBlobs = new Set<string>();
340+
const blobs = new Map<string, { source: string; mode: string }[]>();
342341
const endpoints =
343342
source.kind === "snapshot"
344343
? [mergeBase.sha, source.headSha, source.indexTreeSha, source.treeSha]
@@ -383,16 +382,18 @@ export function scanAgentInput(options: {
383382
if (!["100644", "100755", "120000"].includes(mode!))
384383
throw new AgentInputScanError("unsupported_content");
385384
if (!OBJECT_ID.test(oid!)) throw new AgentInputScanError("incomplete_source");
386-
blobs.add(oid!);
387-
if (path === REVIEWED_FIXTURE_SOURCE && mode === "100644") fixtureBlobs.add(oid!);
385+
// An OID identifies bytes, not each scanned endpoint's path/mode eligibility.
386+
const references = blobs.get(oid!) ?? [];
387+
references.push({ source: path, mode: mode! });
388+
blobs.set(oid!, references);
388389
}
389390
}
390391
stage(git([...args, "--patch", "--binary", "--full-index", "--"]));
391392
}
392393
// Only live committed checkouts need normalized raw files staged here;
393394
// snapshot objects were already captured and fenced before preparation.
394395
if (source.kind === "committed") assertCurrent();
395-
for (const oid of blobs) {
396+
for (const [oid, references] of blobs) {
396397
const size = Number(git(["cat-file", "-s", oid], 100).toString().trim());
397398
if (!Number.isSafeInteger(size) || size < 0)
398399
throw new AgentInputScanError("incomplete_source");
@@ -405,7 +406,7 @@ export function scanAgentInput(options: {
405406
throw new AgentInputScanError("unsupported_content");
406407
// OID names preserve multiline bytes and make symlinks ordinary scan files.
407408
stage(bytes, oid);
408-
if (fixtureBlobs.has(oid)) reviewedFixtureBlobs.set(join(inputDir, oid), bytes);
409+
reviewedFixtureBlobs.set(join(inputDir, oid), { bytes, references });
409410
}
410411
}
411412
const result = spawnSync(
@@ -466,12 +467,12 @@ export function scanAgentInput(options: {
466467
if (failure) throw failure;
467468
// Emit from the host after cleanup: successful callers can discard provider
468469
// stderr, but this classification must remain visible without exposing values.
469-
if (classified)
470+
for (const classification of classified ?? [])
470471
console.error(
471472
JSON.stringify({
472473
event: "agent_input_scan_classified",
473474
notice: "Reviewed synthetic fixture findings classified as non-sensitive.",
474-
...classified,
475+
...classification,
475476
}),
476477
);
477478
}

0 commit comments

Comments
 (0)