Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/repair/event-record-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,16 @@ export function resetEventSnapshot(store: EventRecordStore): void {
fs.mkdirSync(store.snapshotDir, { recursive: true });
}

export function captureEventBaseSnapshot(store: EventRecordStore): EventRecordPaths {
export function captureEventBaseSnapshot(
store: EventRecordStore,
options: { sourceRoot?: string } = {},
): EventRecordPaths {
const paths = eventRecordPaths(store);
copyIfExists(paths.itemRecord, paths.snapshotBaseItem);
copyIfExists(paths.closedRecord, paths.snapshotBaseClosed);
copyIfExists(paths.planRecord, paths.snapshotBasePlan);
copyIfExists(paths.decisionPacket, paths.snapshotBaseDecisionPacket);
const sourceRoot = options.sourceRoot ?? ".";
copyIfExists(path.resolve(sourceRoot, paths.itemRecord), paths.snapshotBaseItem);
copyIfExists(path.resolve(sourceRoot, paths.closedRecord), paths.snapshotBaseClosed);
copyIfExists(path.resolve(sourceRoot, paths.planRecord), paths.snapshotBasePlan);
copyIfExists(path.resolve(sourceRoot, paths.decisionPacket), paths.snapshotBaseDecisionPacket);
return paths;
}

Expand Down
7 changes: 5 additions & 2 deletions src/repair/publish-event-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,13 @@ async function publishEventResult(options: EventOptions): Promise<void> {
itemNumber: options.itemNumber,
snapshotDir: options.snapshotDir,
};
const stateRoot = publishRoot();

resetEventSnapshot(recordStore);
const recordPaths = captureEventBaseSnapshot(recordStore);
const recordPaths = captureEventBaseSnapshot(
recordStore,
stateRoot ? { sourceRoot: stateRoot } : {},
);
fs.rmSync(options.reportPath, { force: true });

runClawsweeper(options, [
Expand All @@ -174,7 +178,6 @@ async function publishEventResult(options: EventOptions): Promise<void> {
captureEventSnapshot(recordStore);
hardResetToRemoteMain();
const stateBaseCommit = captureStatePublishBaseline();
const stateRoot = publishRoot();
const preflightResult = applyEventSnapshotIfCurrent(
recordPaths,
stateRoot ? { remoteRoot: stateRoot } : {},
Expand Down
5 changes: 5 additions & 0 deletions test/dashboard-worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7331,6 +7331,11 @@ test("exact-review queue retains a synchronize update after an unclassified 422"
return jsonResponse({ id: 999 });
if (/^\/repos\/openclaw\/(?:clawsweeper|gogcli)\/issues\/\d+$/.test(url.pathname))
return jsonResponse({ state: "open" });
if (url.pathname === "/repos/openclaw/clawsweeper/pulls/842")
return jsonResponse({
state: "open",
head: { sha: "81e4abc894e7d3ec1fddbd856378b6aadb4392f3" },
});
if (url.pathname === "/app/installations/999/access_tokens")
return jsonResponse({ token: "dispatch-token" });
if (url.pathname === "/repos/openclaw/clawsweeper/dispatches") {
Expand Down
47 changes: 47 additions & 0 deletions test/repair/event-record-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,53 @@ test("event record directories stay inside the isolated worker root", () => {
});
});

test("event base snapshot uses durable state when the isolated worker starts empty", () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "clawsweeper-event-records-"));
const workerRoot = path.join(root, "worker");
const stateRoot = path.join(root, "state");
const store = {
targetRepo: "openclaw/openclaw",
itemNumber: "93584",
snapshotDir: path.join(workerRoot, "snapshot"),
};
const paths = eventRecordPaths(store);
fs.mkdirSync(workerRoot, { recursive: true });
fs.mkdirSync(stateRoot, { recursive: true });

withCwd(stateRoot, () => {
writeEventTuple(paths, {
marker: "durable previous review",
reviewedAt: "2026-07-24T22:16:08.206Z",
itemUpdatedAt: "2026-07-24T22:14:34Z",
});
});

withCwd(workerRoot, () => {
resetEventSnapshot(store);
captureEventBaseSnapshot(store);
writeEventTuple(paths, {
marker: "fresh exact review",
reviewedAt: "2026-07-25T03:12:20.195Z",
itemUpdatedAt: "2026-07-25T03:10:15Z",
});
captureEventSnapshot(store);
assert.throws(
() => applyEventSnapshot(paths, { remoteRoot: stateRoot }),
/missing comparable state-mutation timestamp/,
);

resetEventSnapshot(store);
captureEventBaseSnapshot(store, { sourceRoot: stateRoot });
writeEventTuple(paths, {
marker: "fresh exact review",
reviewedAt: "2026-07-25T03:12:20.195Z",
itemUpdatedAt: "2026-07-25T03:10:15Z",
});
captureEventSnapshot(store);
assert.equal(applyEventSnapshot(paths, { remoteRoot: stateRoot }), "open");
});
});

test("event snapshot match follows the final tuple winner, not only its action", () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "clawsweeper-event-records-"));
const store = {
Expand Down