Skip to content

Commit 673c0f1

Browse files
committed
fix(apply): bound report retention and ledger finalization
1 parent 4a6f9ec commit 673c0f1

11 files changed

Lines changed: 868 additions & 76 deletions

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ checkpoint, and status-only commits are intentionally omitted.
5959

6060
### Fixed
6161

62+
- Bounded apply/proof/comment-sync record retention to selected records and paired dependencies, avoiding unrelated archive loads during ledger finalization without changing close guards.
63+
- Kept projected GitHub reads out of the durable ETag cache so incompatible response shapes cannot hide requested reviewers from close guards. Thanks @goutamadwant! (#1242)
64+
- Normalized unexpected exact-review failures at the Worker boundary without weakening Durable Object transaction rollback. Thanks @yetval and @vincentkoc! (#1240)
6265
- Terminal live verification preserves successful commands when a marker is not observed, reports that distinction truthfully, and still rejects real command failures and timeouts.
6366
- Replaced public Worker exception text with endpoint-owned error codes and bounded direct-publication rejection categories, preserving distinct operational fingerprints without exposing submitted values or stack traces.
6467
- Replaced terminal live proof's authenticated `xvfb-run` wrapper with a TCP-disabled local Xvfb display so readiness probes and recording can connect without X authorization failures.

‎docs/scheduler.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,16 @@ position. Coverage proof, live-state refresh, freshness checks, and close gates
691691
remain unchanged. Explicit targeted apply runs keep their requested item set and
692692
ordering policy.
693693

694+
Apply keeps selected report bodies in memory and loads independently reviewed
695+
paired records only when a close guard requests them. Exact-event publication
696+
does not expand its selected set. Broad apply still sorts the complete open
697+
candidate set; it no longer loads a second copy for paired lookups. Finalization
698+
reloads only requested, result, and unfinished/in-flight item records from the
699+
open and closed directories, rather than retaining the archive. This includes
700+
partial failures and runtime-budget yields and does not change cursor ordering,
701+
close eligibility, canonical baselines, or ledger identities. OpenClaw Bay needs
702+
no change: the public status, record, and ledger contracts are unchanged.
703+
694704
Before a close-mode apply run starts, the workflow summarizes the selected close
695705
candidate mix by quality bucket in the status detail. Buckets such as
696706
implemented-on-main, duplicate/superseded, needs PR close proof,

‎scripts/e2e/apply-memory-gh.cjs‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Secretless, fail-closed transport: all writes are local fixture state.
2+
const fs = require("node:fs");
3+
const path = require("node:path");
4+
const root = process.env.APPLY_MEMORY_CASE;
5+
const raw = process.argv.slice(2);
6+
const args = raw[0] === "--repo" ? raw.slice(2) : raw;
7+
const endpoint = args.includes("-i") ? args[args.indexOf("-i") + 1] : args[1] || "";
8+
const method = args.includes("--method") ? args[args.indexOf("--method") + 1] : "GET";
9+
fs.appendFileSync(path.join(root, "requests.jsonl"), `${JSON.stringify({ args, method })}\n`);
10+
const match = endpoint.match(/\/issues\/(\d+)(?:\/|$)/);
11+
const number = Number(match?.[1]);
12+
const commentPath = path.join(root, `comment-${number}.json`);
13+
const output = (value) => {
14+
if (args.includes("-i")) process.stdout.write("HTTP/2 200\n\n");
15+
console.log(JSON.stringify(value));
16+
};
17+
if (number === 102 && process.env.APPLY_MEMORY_INTERRUPT) {
18+
if (process.env.APPLY_MEMORY_INTERRUPT === "budget") {
19+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10_000);
20+
}
21+
console.error("fixture interrupted second item (HTTP 422)");
22+
process.exit(1);
23+
}
24+
if (args[0] === "api" && /\/issues\/\d+\/comments(?:\?|$)/.test(endpoint)) {
25+
if (method === "POST") {
26+
const payload = JSON.parse(fs.readFileSync(args[args.indexOf("--input") + 1], "utf8"));
27+
const comment = {
28+
id: 9000 + number,
29+
html_url: `https://github.com/openclaw/openclaw/issues/${number}#issuecomment-${9000 + number}`,
30+
created_at: "2026-08-02T00:00:00Z",
31+
updated_at: "2026-08-02T00:00:00Z",
32+
user: { login: "clawsweeper[bot]" },
33+
body: payload.body,
34+
};
35+
fs.writeFileSync(commentPath, JSON.stringify(comment));
36+
output(comment);
37+
} else if (method === "GET") {
38+
output([fs.existsSync(commentPath) ? [JSON.parse(fs.readFileSync(commentPath, "utf8"))] : []]);
39+
} else throw new Error(`unexpected comment mutation: ${method}`);
40+
} else if (args[0] === "api" && /\/issues\/\d+\/timeline(?:\?|$)/.test(endpoint)) {
41+
output([[]]);
42+
} else if (args[0] === "api" && /\/issues\/\d+$/.test(endpoint) && method === "GET") {
43+
const isPull = process.env.APPLY_MEMORY_KIND === "pull_request";
44+
output({
45+
number,
46+
title: "Memory proof",
47+
body: "",
48+
html_url: `https://github.com/openclaw/openclaw/${isPull ? "pull" : "issues"}/${number}`,
49+
created_at: "2026-05-01T00:00:00Z",
50+
updated_at:
51+
process.env.APPLY_MEMORY_DRIFT && number >= 121
52+
? "2026-05-02T00:00:00Z"
53+
: "2026-05-01T00:00:00Z",
54+
closed_at: null,
55+
state: "open",
56+
locked: false,
57+
active_lock_reason: null,
58+
author_association: "CONTRIBUTOR",
59+
user: { login: "reporter" },
60+
labels: isPull
61+
? ["security"]
62+
: ["security", "issue-rating: 🦀 challenger crab", "clawsweeper:current-main-repro"],
63+
comments: fs.existsSync(commentPath) ? 1 : 0,
64+
pull_request: isPull
65+
? { url: `https://api.github.com/repos/openclaw/openclaw/pulls/${number}` }
66+
: null,
67+
});
68+
} else if (args[0] === "api" && /\/pulls\/\d+$/.test(endpoint) && method === "GET") {
69+
output({ head: { sha: "a".repeat(40) }, base: { ref: "main" }, merged: false, state: "open" });
70+
} else if (
71+
args[0] === "api" &&
72+
/\/pulls\/\d+\/(files|commits|comments|reviews)(?:\?|$)/.test(endpoint) &&
73+
method === "GET"
74+
) {
75+
output([[]]);
76+
} else if (
77+
args[0] === "api" &&
78+
endpoint === "graphql" &&
79+
args.some((arg) => arg.includes("reviewThreads"))
80+
) {
81+
output({
82+
data: {
83+
repository: {
84+
pullRequest: {
85+
reviewThreads: { nodes: [], pageInfo: { hasNextPage: false, endCursor: null } },
86+
},
87+
},
88+
},
89+
});
90+
} else if (args[0] === "issue" && args[1] === "view") {
91+
output({ closedByPullRequestsReferences: [] });
92+
} else if (
93+
args[0] === "api" &&
94+
/\/commits\/[a-f0-9]+\/check-runs\?/.test(endpoint) &&
95+
method === "GET"
96+
) {
97+
output({ total_count: 0, check_runs: [] });
98+
} else if (
99+
args[0] === "api" &&
100+
/\/commits\/[a-f0-9]+\/status(?:\?|$)/.test(endpoint) &&
101+
method === "GET"
102+
) {
103+
output({ total_count: 0, statuses: [] });
104+
} else if (args[0] === "api" && endpoint.startsWith("search/issues?") && method === "GET") {
105+
output({ items: [] });
106+
} else if (args[0] === "label" || (args[0] === "issue" && args[1] === "edit")) {
107+
output({});
108+
} else {
109+
throw new Error(`unexpected fixture request: ${JSON.stringify(args)}`);
110+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Observe the built CLI without changing record contents or its memory limit.
2+
const fs = require("node:fs");
3+
const net = require("node:net");
4+
const childProcess = require("node:child_process");
5+
const { syncBuiltinESMExports } = require("node:module");
6+
7+
net.Socket.prototype.connect = () => {
8+
throw new Error("apply memory proof forbids network access");
9+
};
10+
globalThis.fetch = () => {
11+
throw new Error("apply memory proof forbids fetch");
12+
};
13+
14+
if (process.argv[1]?.endsWith("/dist/clawsweeper.js")) {
15+
for (const method of ["spawn", "spawnSync", "execFile", "execFileSync"]) {
16+
const original = childProcess[method];
17+
childProcess[method] = (command, args, ...rest) => {
18+
// The ledger uses these local process-identity probes on macOS.
19+
const ledgerProbe = ["/usr/bin/python3", "/usr/sbin/sysctl", "/bin/ps"].includes(command);
20+
if (
21+
!ledgerProbe &&
22+
(command !== process.execPath || args[0] !== process.env.APPLY_MEMORY_TRANSPORT)
23+
) {
24+
throw new Error(`apply memory proof forbids subprocess: ${command}`);
25+
}
26+
return original(command, args, ...rest);
27+
};
28+
}
29+
const originalRead = fs.readFileSync;
30+
const counts = { items: 0, closed: 0, bytes: 0 };
31+
const firstStacks = {};
32+
let peakHeapUsed = 0;
33+
let peakRss = 0;
34+
const save = () => {
35+
const memory = process.memoryUsage();
36+
peakHeapUsed = Math.max(peakHeapUsed, memory.heapUsed);
37+
peakRss = Math.max(peakRss, memory.rss);
38+
fs.writeFileSync(
39+
process.env.APPLY_MEMORY_METRICS,
40+
JSON.stringify({
41+
counts,
42+
peakHeapUsed,
43+
peakRss,
44+
maxRSSKiB: process.resourceUsage().maxRSS,
45+
firstStacks,
46+
}),
47+
);
48+
};
49+
fs.readFileSync = (file, ...args) => {
50+
const value = originalRead(file, ...args);
51+
const path = String(file);
52+
const match = path.startsWith(process.env.APPLY_MEMORY_RECORDS)
53+
? path.match(/\/(items|closed)\/\d+\.md$/)
54+
: null;
55+
if (match) {
56+
counts[match[1]] += 1;
57+
counts.bytes += Buffer.byteLength(value);
58+
firstStacks[match[1]] ??= new Error(`first ${match[1]} read`).stack;
59+
if ((counts.items + counts.closed) % 10 === 0) save();
60+
}
61+
return value;
62+
};
63+
process.on("exit", save);
64+
save();
65+
}
66+
syncBuiltinESMExports();

0 commit comments

Comments
 (0)