Skip to content

Commit 0925eca

Browse files
authored
fix(apply): bound exact review publication state (#980)
1 parent b07ab75 commit 0925eca

5 files changed

Lines changed: 93 additions & 17 deletions

File tree

‎.github/workflows/sweep.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,7 @@ jobs:
12891289
records-url: ${{ vars.CLAWSWEEPER_EXACT_REVIEW_QUEUE_URL || 'https://clawsweeper.openclaw.ai' }}
12901290
records-secret: ${{ secrets.CLAWSWEEPER_WEBHOOK_SECRET }}
12911291
records-repo-slugs: ${{ steps.target.outputs.target_slug }}
1292+
records-item-number: ${{ steps.target.outputs.item_number }}
12921293
hydrate-git-state: "false"
12931294
hydrate-state-blobs: "false"
12941295

@@ -2254,6 +2255,7 @@ jobs:
22542255
records-url: ${{ vars.CLAWSWEEPER_EXACT_REVIEW_QUEUE_URL || 'https://clawsweeper.openclaw.ai' }}
22552256
records-secret: ${{ secrets.CLAWSWEEPER_WEBHOOK_SECRET }}
22562257
records-repo-slugs: ${{ steps.publication-context.outputs.target_slug }}
2258+
records-item-number: ${{ steps.publication-context.outputs.item_number }}
22572259
hydrate-git-state: "false"
22582260
hydrate-state-blobs: "false"
22592261

‎src/clawsweeper.ts‎

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23460,7 +23460,10 @@ function applyDecisionsCommandInner(args: Args, runtimeBudget: GitHubRuntimeBudg
2346023460
applyCheckedAt: number;
2346123461
}
2346223462
> =>
23463-
reportEntriesForDir(dir)
23463+
reportEntriesForDir(
23464+
dir,
23465+
filterRequested && requestedItemNumberSet.size > 0 ? requestedItemNumberSet : undefined,
23466+
)
2346423467
.filter(
2346523468
(entry) =>
2346623469
entry.repo === targetRepo() &&
@@ -23530,7 +23533,12 @@ function applyDecisionsCommandInner(args: Args, runtimeBudget: GitHubRuntimeBudg
2353023533
left.number - right.number,
2353123534
);
2353223535
const files = fileEntries.map((entry) => entry.name);
23533-
const allOpenFileEntries = applyReportEntriesForDir(itemsDir, "items", false);
23536+
const boundedExactSelection = exactEventPublication && requestedItemNumberSet.size > 0;
23537+
// Exact-event publication handles one leased item and cannot pair-close with
23538+
// limit=1. Keep unrelated canonical records out of this memory-bounded path.
23539+
const allOpenFileEntries = boundedExactSelection
23540+
? fileEntries
23541+
: applyReportEntriesForDir(itemsDir, "items", false);
2353423542
const openFileEntryByNumber = new Map(allOpenFileEntries.map((entry) => [entry.number, entry]));
2353523543
const closedThisRun = new Set<string>();
2353623544
const authorPrBudgetClosesThisRun = new Map<string, number>();
@@ -23590,10 +23598,16 @@ function applyDecisionsCommandInner(args: Args, runtimeBudget: GitHubRuntimeBudg
2359023598
} catch (error) {
2359123599
publicationError = error;
2359223600
}
23601+
const finalEntryNumbers = boundedExactSelection
23602+
? new Set([
23603+
...requestedItemNumberSet,
23604+
...results.flatMap((result) => (result.number > 0 ? [result.number] : [])),
23605+
])
23606+
: undefined;
2359323607
const finalEntries = new Map<number, ReportEntry>();
2359423608
for (const finalEntry of [
23595-
...reportEntriesForDir(itemsDir),
23596-
...reportEntriesForDir(closedDir),
23609+
...reportEntriesForDir(itemsDir, finalEntryNumbers),
23610+
...reportEntriesForDir(closedDir, finalEntryNumbers),
2359723611
].filter((candidate) => candidate.repo === targetRepo())) {
2359823612
finalEntries.set(finalEntry.number, finalEntry);
2359923613
}
@@ -26899,18 +26913,20 @@ function markdownFiles(dir: string): string[] {
2689926913
: [];
2690026914
}
2690126915

26902-
function reportEntriesForDir(dir: string): ReportEntry[] {
26903-
return markdownFiles(dir).map((name) => {
26904-
const path = join(dir, name);
26905-
const markdown = readFileSync(path, "utf8");
26906-
return {
26907-
name,
26908-
number: numberForMarkdownFile(name),
26909-
path,
26910-
repo: markdownRepository(markdown, path),
26911-
markdown,
26912-
};
26913-
});
26916+
function reportEntriesForDir(dir: string, itemNumbers?: ReadonlySet<number>): ReportEntry[] {
26917+
return markdownFiles(dir)
26918+
.filter((name) => !itemNumbers || itemNumbers.has(numberForMarkdownFile(name)))
26919+
.map((name) => {
26920+
const path = join(dir, name);
26921+
const markdown = readFileSync(path, "utf8");
26922+
return {
26923+
name,
26924+
number: numberForMarkdownFile(name),
26925+
path,
26926+
repo: markdownRepository(markdown, path),
26927+
markdown,
26928+
};
26929+
});
2691426930
}
2691526931

2691626932
function numberForMarkdownFile(file: string): number {

‎test/apply-cursor-trace.test.ts‎

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import assert from "node:assert/strict";
2-
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
33
import { join } from "node:path";
44
import test from "node:test";
55

@@ -62,6 +62,51 @@ test("apply-decisions preserves auto-selected order and traces only examined rec
6262
}
6363
});
6464

65+
test("exact-event apply does not read unrelated canonical records", () => {
66+
const root = mkdtempSync(tmpPrefix);
67+
try {
68+
const itemsDir = join(root, "items");
69+
const closedDir = join(root, "closed");
70+
const plansDir = join(root, "plans");
71+
const reportPath = join(root, "apply-report.json");
72+
mkdirSync(itemsDir, { recursive: true });
73+
mkdirSync(plansDir, { recursive: true });
74+
writeFileSync(
75+
join(itemsDir, "20.md"),
76+
workPlanCandidateReport({
77+
repository: "openclaw/openclaw",
78+
number: 20,
79+
local_checkout_access: "unverified",
80+
decision: "keep_open",
81+
action_taken: "kept_open",
82+
}),
83+
"utf8",
84+
);
85+
symlinkSync(join(root, "missing-record.md"), join(itemsDir, "999.md"));
86+
87+
runApplyDecisionsForTest({
88+
itemsDir,
89+
closedDir,
90+
plansDir,
91+
reportPath,
92+
extraArgs: [
93+
"--target-repo",
94+
"openclaw/openclaw",
95+
"--item-numbers",
96+
"20",
97+
"--exact-event-publication",
98+
"--limit",
99+
"1",
100+
],
101+
});
102+
103+
const report = JSON.parse(readFileSync(reportPath, "utf8"));
104+
assert.equal(report[0]?.number, 20);
105+
} finally {
106+
rmSync(root, { recursive: true, force: true });
107+
}
108+
});
109+
65110
test("apply-decisions keeps close-limit candidates out of the cursor trace", () => {
66111
const root = mkdtempSync(tmpPrefix);
67112
try {

‎test/repair/exact-review-batch-workflow.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ test("batch workflow signs queue ownership, isolates item failures, and commits
170170

171171
test("exact-review producer uses direct publication with bounded legacy fallback", () => {
172172
assert.match(sweepSource, /name: Deliver GitHub effects and prepare direct state mutation/);
173+
assert.match(sweepSource, /records-item-number: \$\{\{ steps\.target\.outputs\.item_number \}\}/);
173174
assert.match(
174175
sweepSource,
175176
/EXACT_REVIEW_BATCH_MUTATION_OUTPUT: \.artifacts\/direct-publication-outcome\.json/,

‎test/sweep-workflow.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,14 @@ test("exact event review publishes directly with a queue-bounded canonical fallb
666666
assert.match(step(reviewer, "Review exact event item").run ?? "", /sleep 60/);
667667

668668
const create = step(reviewer, "Create exact review artifact bundle");
669+
const directSetupState = reviewer.steps.find(
670+
(candidate) => candidate.id === "direct-setup-state",
671+
);
672+
assert.ok(directSetupState);
673+
assert.equal(
674+
directSetupState.with?.["records-item-number"],
675+
"${{ steps.target.outputs.item_number }}",
676+
);
669677
const prepareDirect = step(reviewer, "Deliver GitHub effects and prepare direct state mutation");
670678
const postDirect = step(reviewer, "Post direct exact review publication result");
671679
const finalizeDirect = step(reviewer, "Finalize direct exact review lifecycle");
@@ -843,6 +851,10 @@ test("exact event review publishes directly with a queue-bounded canonical fallb
843851
const targetWriteStep = step(publisher, "Create target write token");
844852
const stateSetup = publisher.steps.find((candidate) => candidate.uses?.endsWith("/setup-state"));
845853
assert.ok(stateSetup);
854+
assert.equal(
855+
stateSetup.with?.["records-item-number"],
856+
"${{ steps.publication-context.outputs.item_number }}",
857+
);
846858
const publisherCheckout = publisher.steps.find(
847859
(candidate) => candidate.uses === "actions/checkout@v7",
848860
);

0 commit comments

Comments
 (0)