Skip to content

Commit 8a4dc46

Browse files
committed
fix(review): keep local reviews running without statistics
1 parent 43c6be9 commit 8a4dc46

8 files changed

Lines changed: 342 additions & 93 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ checkpoint, and status-only commits are intentionally omitted.
6565
### Fixed
6666

6767
- Aligned PR proof comments and status labels with the existing host requirement when a reviewer records proof as not applicable, while preserving recorded assessments and merge gates.
68-
- Preserved authoritative whole-range Git line counts in local reviews and report rendering, keeping unavailable statistics and incomplete file lists from appearing as verified zero totals.
68+
- Preserved authoritative whole-range Git line counts in local reviews and report rendering, allowing review to complete with unavailable best-effort statistics while requiring complete file enumeration under its prior capture and timeout contract and never showing unknown counts as verified zero totals.
6969
- 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.
7070
- Stopped treating pane-local runtime state as stored data while retaining warnings for explicit persistence changes and incomplete storage patches.
7171
- Recover hosted PR reviews that refused `incomplete_source` by fetching reviewed-head history before the bounded base/head fallback, preserving merge-base verification and secret-scanning gates. Thanks @masatohoshino. ([#1308](https://github.com/openclaw/clawsweeper/pull/1308))

‎docs/commit-sweeper.md‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,14 @@ the local Markdown report is the only output.
4646
For `review --local-range`, per-file line counts come from complete Git numstat
4747
metadata for the resolved merge-base-to-HEAD range, independently of bounded
4848
review patches and introduction evidence. NUL-framed paths preserve rename and
49-
copy identities. Unreadable, malformed, or over-limit metadata fails the review;
50-
binary line counts remain unknown, while a pure rename or mode-only change can
51-
have verified zero counts. Reports preserve unknown counts as JSON nulls. The
49+
copy identities. Complete file enumeration is mandatory and retains the prior
50+
runtime command contract (128 MiB capture budget and no read deadline); an
51+
unreadable, malformed, or over-limit required file list still fails the review.
52+
Statistics are best-effort metadata bounded to 1 MiB and five seconds:
53+
unreadable, over-limit, timed-out, malformed, or mismatched numstat leaves all
54+
file counts unknown without stopping review. Binary line counts remain unknown,
55+
while a pure rename or mode-only change can have verified zero counts when
56+
metadata is valid. Reports preserve unknown counts as JSON nulls. The
5257
OpenClaw PR surface renders numeric totals only for a complete file list with
5358
known counts for every file; otherwise it explains why statistics are unavailable.
5459
Historical reports are unchanged. OpenClaw Bay needs no update because its

‎src/clawsweeper-local-review.ts‎

Lines changed: 64 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { spawnSync } from "node:child_process";
2-
import { UserFacingCommandError } from "./command.js";
2+
import { SWEEPER_COMMAND_MAX_BUFFER_BYTES, UserFacingCommandError } from "./command.js";
33
import { commitMetadata, dirtyWorktree } from "./commit-sweeper.js";
4-
import { readReviewGit } from "./pr-review-evidence.js";
4+
import { readReviewGit, type ReviewGitReadOptions } from "./pr-review-evidence.js";
55
import { truncateText } from "./clawsweeper-text.js";
66
import type { Item, ItemContext } from "./clawsweeper-types.js";
77

@@ -19,72 +19,89 @@ interface LocalRangeReviewDependencies {
1919

2020
function localRangeFiles(targetDir: string, diffArgs: string[]) {
2121
const invalid = () =>
22-
new UserFacingCommandError("Could not read complete local-range Git file statistics.");
23-
function fields(format: string): string[] {
24-
const raw = readReviewGit(targetDir, [...diffArgs, format, "-z", "--"]);
25-
if (raw === null) throw invalid();
22+
new UserFacingCommandError("Could not read complete local-range Git file list.");
23+
function fields(format: string, options: ReviewGitReadOptions = {}): string[] | null {
24+
const raw = readReviewGit(targetDir, [...diffArgs, format, "-z", "--"], options);
25+
if (raw === null) return null;
2626
const text = raw.toString("utf8");
2727
// Refuse lossy path decoding and incomplete reads rather than join different identities.
2828
if (!Buffer.from(text, "utf8").equals(raw) || (text && !text.endsWith("\0"))) {
29-
throw invalid();
29+
return null;
3030
}
3131
return text ? text.slice(0, -1).split("\0") : [];
3232
}
33-
const names = fields("--name-status");
33+
// Required enumeration retains runtime run()'s capture budget and absence of a deadline.
34+
const names = fields("--name-status", {
35+
maxBytes: SWEEPER_COMMAND_MAX_BUFFER_BYTES,
36+
deadlineAt: null,
37+
});
38+
if (names === null) throw invalid();
3439
const files: Array<{ filename: string; previous_filename?: string; status: string }> = [];
40+
const filenames = new Set<string>();
3541
for (let index = 0; index < names.length;) {
3642
const status = names[index++];
3743
if (!status || !/^(?:[ADMTUXB]|[RC](?:100|0[0-9]{2}))$/.test(status)) throw invalid();
3844
const first = names[index++];
3945
const renamed = /^[RC]/.test(status);
4046
const filename = renamed ? names[index++] : first;
41-
if (!first || !filename) throw invalid();
47+
if (!first || !filename || filenames.has(filename)) throw invalid();
48+
filenames.add(filename);
4249
files.push({ filename, ...(renamed ? { previous_filename: first } : {}), status });
4350
}
4451
const identity = (filename: string, previous?: string) => JSON.stringify([previous, filename]);
45-
const statistics = new Map<string, { additions: number | null; deletions: number | null }>();
46-
const counts = fields("--numstat");
47-
for (let index = 0; index < counts.length;) {
48-
const record = counts[index++];
49-
if (!record) throw invalid();
50-
const firstTab = record.indexOf("\t");
51-
const secondTab = record.indexOf("\t", firstTab + 1);
52-
if (firstTab < 1 || secondTab <= firstTab + 1) throw invalid();
53-
const added = record.slice(0, firstTab);
54-
const removed = record.slice(firstTab + 1, secondTab);
55-
let filename = record.slice(secondTab + 1);
56-
let previous: string | undefined;
57-
// Rename/copy numstat records frame old and new paths separately after an empty path.
58-
if (!filename) {
59-
previous = counts[index++];
60-
filename = counts[index++] ?? "";
61-
if (!previous) throw invalid();
52+
function readStatistics() {
53+
const statistics = new Map<string, { additions: number | null; deletions: number | null }>();
54+
const counts = fields("--numstat");
55+
if (counts === null) return null;
56+
for (let index = 0; index < counts.length;) {
57+
const record = counts[index++];
58+
if (!record) return null;
59+
const firstTab = record.indexOf("\t");
60+
const secondTab = record.indexOf("\t", firstTab + 1);
61+
if (firstTab < 1 || secondTab <= firstTab + 1) return null;
62+
const added = record.slice(0, firstTab);
63+
const removed = record.slice(firstTab + 1, secondTab);
64+
let filename = record.slice(secondTab + 1);
65+
let previous: string | undefined;
66+
// Rename/copy numstat records frame old and new paths separately after an empty path.
67+
if (!filename) {
68+
previous = counts[index++];
69+
filename = counts[index++] ?? "";
70+
if (!previous) return null;
71+
}
72+
if (!filename) return null;
73+
const binary = added === "-" && removed === "-";
74+
if (
75+
!binary &&
76+
(![added, removed].every((value) => /^[0-9]+$/.test(value)) ||
77+
![added, removed].every((value) => Number.isSafeInteger(Number(value))))
78+
) {
79+
return null;
80+
}
81+
const key = identity(filename, previous);
82+
if (statistics.has(key)) return null;
83+
statistics.set(key, {
84+
additions: binary ? null : Number(added),
85+
deletions: binary ? null : Number(removed),
86+
});
6287
}
63-
if (!filename) throw invalid();
64-
const binary = added === "-" && removed === "-";
6588
if (
66-
!binary &&
67-
(![added, removed].every((value) => /^[0-9]+$/.test(value)) ||
68-
![added, removed].every((value) => Number.isSafeInteger(Number(value))))
89+
statistics.size !== files.length ||
90+
files.some((file) => !statistics.has(identity(file.filename, file.previous_filename)))
6991
) {
70-
throw invalid();
92+
return null;
7193
}
72-
const key = identity(filename, previous);
73-
if (statistics.has(key)) throw invalid();
74-
statistics.set(key, {
75-
additions: binary ? null : Number(added),
76-
deletions: binary ? null : Number(removed),
77-
});
94+
return statistics;
7895
}
79-
const result = files.map((file) => {
80-
const key = identity(file.filename, file.previous_filename);
81-
const stats = statistics.get(key);
82-
if (!stats) throw invalid();
83-
statistics.delete(key);
84-
return { ...file, ...stats };
85-
});
86-
if (statistics.size) throw invalid();
87-
return result;
96+
// Optional bounded metadata is all-or-nothing; never publish a partially validated map.
97+
const statistics = readStatistics();
98+
return files.map((file) => ({
99+
...file,
100+
...(statistics?.get(identity(file.filename, file.previous_filename)) ?? {
101+
additions: null,
102+
deletions: null,
103+
}),
104+
}));
88105
}
89106

90107
export function createLocalRangeReviewer({

‎src/clawsweeper-runtime.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { flushWorkflowActionEvents } from "./action-ledger-runtime.js";
77
import { boolArg, itemNumbersArg, parseArgs, stringArg, type Args } from "./clawsweeper-args.js";
88
import { dispatchCommand, type CommandHandler } from "./clawsweeper-command-dispatch.js";
99
import { createDecisionParser } from "./clawsweeper-decision-parser.js";
10-
import { runText } from "./command.js";
10+
import { runText, SWEEPER_COMMAND_MAX_BUFFER_BYTES } from "./command.js";
1111
import { AUTOMATION_LIMITS } from "./limits.js";
1212
import {
1313
DEFAULT_TARGET_REPO,
@@ -312,7 +312,7 @@ function run(
312312
return runText(command, args, {
313313
cwd: options.cwd ?? ROOT,
314314
env: options.env,
315-
maxBuffer: 128 * 1024 * 1024,
315+
maxBuffer: SWEEPER_COMMAND_MAX_BUFFER_BYTES,
316316
stdio: ["ignore", "pipe", "pipe"],
317317
timeoutMs: options.timeoutMs,
318318
trim: "both",

‎src/command.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { execFileSync } from "node:child_process";
22
import { existsSync, readFileSync, readdirSync } from "node:fs";
33
import { delimiter, dirname, isAbsolute, join, normalize, resolve } from "node:path";
44

5+
export const SWEEPER_COMMAND_MAX_BUFFER_BYTES = 128 * 1024 * 1024;
6+
57
export type RunTextOptions = {
68
cwd?: string | undefined;
79
env?: NodeJS.ProcessEnv | undefined;

‎src/pr-review-evidence.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ function objectId(value: unknown): string | null {
6161
export interface ReviewGitReadOptions {
6262
executable?: string;
6363
objectEnv?: NodeJS.ProcessEnv;
64-
deadlineAt?: number;
64+
// Omitted uses the five-second read deadline; null explicitly disables it.
65+
deadlineAt?: number | null;
6566
maxBytes?: number;
6667
input?: Buffer;
6768
configuration?: "normalization";
@@ -81,8 +82,11 @@ export function readReviewGit(
8182
args.includes("--get") &&
8283
["core.autocrlf", "core.eol", "core.symlinks"].includes(args.at(-1) ?? ""));
8384
if (normalizationQuery && !readsNormalization) return null;
84-
const timeout = (options.deadlineAt ?? Date.now() + 5_000) - Date.now();
85-
if (timeout <= 0) return null;
85+
const timeout =
86+
options.deadlineAt === null
87+
? undefined
88+
: (options.deadlineAt ?? Date.now() + 5_000) - Date.now();
89+
if (timeout !== undefined && timeout <= 0) return null;
8690
const result = spawnSync(
8791
options.executable ?? "git",
8892
[

0 commit comments

Comments
 (0)