Skip to content

Commit ec2f84c

Browse files
steipetePeter Steinberger
andauthored
fix: recover reviewed issue fixes without enabling merge (#982)
* fix: recover reviewed issue fixes without enabling merge * fix: hydrate restricted review blobs and recover deduplicated issue workers * fix: harden bounded review hydration and issue retry recovery --------- Co-authored-by: Peter Steinberger <[email protected]>
1 parent 16f01b2 commit ec2f84c

14 files changed

Lines changed: 1701 additions & 25 deletions

‎.github/workflows/repair-cluster-worker.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ jobs:
186186
CLAWSWEEPER_ALLOWED_OWNER: ${{ vars.CLAWSWEEPER_ALLOWED_OWNER || 'openclaw' }}
187187
CLAWSWEEPER_ALLOW_EXECUTE: ${{ (inputs.mode == 'execute' || inputs.mode == 'autonomous') && vars.CLAWSWEEPER_ALLOW_EXECUTE == '1' && '1' || '0' }}
188188
CLAWSWEEPER_ALLOW_FIX_PR: ${{ (inputs.mode == 'execute' || inputs.mode == 'autonomous') && vars.CLAWSWEEPER_ALLOW_FIX_PR == '1' && '1' || '0' }}
189-
CLAWSWEEPER_ALLOW_MERGE: ${{ (inputs.mode == 'execute' || inputs.mode == 'autonomous') && (vars.CLAWSWEEPER_ALLOW_MERGE || '0') || '0' }}
189+
CLAWSWEEPER_ALLOW_MERGE: ${{ !contains(inputs.job, '/inbox/issue-') && (inputs.mode == 'execute' || inputs.mode == 'autonomous') && (vars.CLAWSWEEPER_ALLOW_MERGE || '0') || '0' }}
190190
CLAWSWEEPER_HYDRATE_CLUSTER_REFS: ${{ vars.CLAWSWEEPER_HYDRATE_CLUSTER_REFS || '1' }}
191191
CLAWSWEEPER_HYDRATE_COMMENTS: ${{ vars.CLAWSWEEPER_HYDRATE_COMMENTS || '1' }}
192192
CLAWSWEEPER_MAX_COMMENTS_PER_ITEM: ${{ vars.CLAWSWEEPER_MAX_COMMENTS_PER_ITEM || '30' }}
@@ -498,7 +498,7 @@ jobs:
498498
CLAWSWEEPER_ALLOWED_OWNER: ${{ vars.CLAWSWEEPER_ALLOWED_OWNER || 'openclaw' }}
499499
CLAWSWEEPER_ALLOW_EXECUTE: ${{ needs.cluster.outputs.allow_execute == '1' && '1' || '0' }}
500500
CLAWSWEEPER_ALLOW_FIX_PR: ${{ needs.cluster.outputs.allow_fix_pr == '1' && '1' || '0' }}
501-
CLAWSWEEPER_ALLOW_MERGE: ${{ needs.cluster.outputs.allow_merge || '0' }}
501+
CLAWSWEEPER_ALLOW_MERGE: ${{ !contains(inputs.job, '/inbox/issue-') && needs.cluster.outputs.allow_merge || '0' }}
502502
CLAWSWEEPER_OPENCLAW_MODEL: ${{ contains(inputs.job, '/inbox/issue-') && format('openai/{0}', vars.CLAWSWEEPER_FIX_PR_MODEL || 'gpt-5.6-sol') || secrets.CLAWSWEEPER_OPENCLAW_MODEL }}
503503
CLAWSWEEPER_CODEX_REASONING_EFFORT: ${{ contains(inputs.job, '/inbox/issue-') && (vars.CLAWSWEEPER_FIX_PR_REASONING_EFFORT || 'xhigh') || vars.CLAWSWEEPER_CODEX_REASONING_EFFORT || 'high' }}
504504
CLAWSWEEPER_CODEX_REVIEW_ATTEMPTS: ${{ vars.CLAWSWEEPER_CODEX_REVIEW_ATTEMPTS || '4' }}

‎.github/workflows/repair-issue-implementation-intake.yml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ jobs:
178178
id: prepare
179179
env:
180180
GH_TOKEN: ${{ steps.target-token.outputs.token }}
181+
CLAWSWEEPER_ISSUE_IMPLEMENTATION_WORKFLOW_TOKEN: ${{ steps.dispatch-token.outputs.token }}
181182
ENABLED: ${{ github.event.inputs.enabled || github.event.client_payload.enabled || vars.CLAWSWEEPER_AUTO_IMPLEMENT_ISSUES || 'false' }}
182183
TARGET_REPO: ${{ github.event.inputs.target_repo || github.event.client_payload.target_repo || 'openclaw/openclaw' }}
183184
ITEM_NUMBER: ${{ github.event.inputs.item_number || github.event.client_payload.item_number }}
@@ -240,6 +241,7 @@ jobs:
240241
--run-url "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
241242
242243
- name: Dispatch repair worker
244+
id: dispatch-worker
243245
if: ${{ steps.prepare.outputs.should_repair == 'true' || steps.prepare.outputs.existing_job_path != '' }}
244246
env:
245247
GH_TOKEN: ${{ steps.dispatch-token.outputs.token }}
@@ -270,11 +272,13 @@ jobs:
270272
CLAWSWEEPER_WEBHOOK_SECRET: ${{ secrets.CLAWSWEEPER_WEBHOOK_SECRET }}
271273
AUDIT_PATH: ${{ steps.prepare.outputs.audit_path }}
272274
JOB_PATH: ${{ steps.prepare.outputs.job_path || steps.prepare.outputs.existing_job_path }}
275+
WORKER_CREATED_AT: ${{ steps.dispatch-worker.outputs.issue_worker_created_at || '' }}
273276
run: |
274277
set -euo pipefail
275278
pnpm run repair:issue-implementation-intake -- mark-dispatched \
276279
--audit-path "$AUDIT_PATH" \
277-
--job-path "$JOB_PATH"
280+
--job-path "$JOB_PATH" \
281+
--worker-created-at "$WORKER_CREATED_AT"
278282
for attempt in 1 2 3; do
279283
if pnpm run repair:publish-main -- \
280284
--message "chore: record issue implementation worker dispatch" \

‎src/clawsweeper-review-blobs.ts‎

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
import { spawnSync } from "node:child_process";
2+
3+
const MAX_REVIEW_FILES = 80;
4+
const MAX_GIT_OUTPUT_BYTES = 4 * 1024 * 1024;
5+
const MAX_REVIEW_BLOB_BYTES = 4 * 1024 * 1024;
6+
const GIT_OBJECT_ID = /^[0-9a-f]{40,64}$/i;
7+
8+
type ReviewBlobFile = {
9+
filename?: unknown;
10+
previous_filename?: unknown;
11+
status?: unknown;
12+
};
13+
14+
export type ReviewBlobHydration = {
15+
hydrated: boolean;
16+
blobs: number;
17+
};
18+
19+
export function hydratePullRequestReviewBlobs({
20+
targetDir,
21+
baseSha,
22+
headSha,
23+
files,
24+
resolveBlobSizes,
25+
}: {
26+
targetDir: string;
27+
baseSha: string;
28+
headSha: string;
29+
files: readonly unknown[];
30+
resolveBlobSizes?: (objectIds: readonly string[]) => ReadonlyMap<string, number>;
31+
}): ReviewBlobHydration {
32+
if (
33+
!GIT_OBJECT_ID.test(baseSha) ||
34+
!GIT_OBJECT_ID.test(headSha) ||
35+
files.length > MAX_REVIEW_FILES
36+
) {
37+
return { hydrated: false, blobs: 0 };
38+
}
39+
40+
const basePaths = new Set<string>();
41+
const headPaths = new Set<string>();
42+
for (const value of files) {
43+
if (!value || typeof value !== "object") return { hydrated: false, blobs: 0 };
44+
const file = value as ReviewBlobFile;
45+
const filename = safeReviewPath(file.filename);
46+
if (!filename) return { hydrated: false, blobs: 0 };
47+
const previous =
48+
file.previous_filename === undefined ? filename : safeReviewPath(file.previous_filename);
49+
if (!previous) return { hydrated: false, blobs: 0 };
50+
const status = typeof file.status === "string" ? file.status.toLowerCase() : "";
51+
if (status !== "added" && status !== "a") basePaths.add(previous);
52+
if (status !== "removed" && status !== "deleted" && status !== "d") {
53+
headPaths.add(filename);
54+
}
55+
}
56+
57+
const objectIds = new Set<string>();
58+
for (const [sha, paths] of [
59+
[baseSha, basePaths],
60+
[headSha, headPaths],
61+
] as const) {
62+
if (paths.size === 0) continue;
63+
const tree = spawnSync("git", ["--literal-pathspecs", "ls-tree", "-z", sha, "--", ...paths], {
64+
cwd: targetDir,
65+
encoding: "utf8",
66+
env: { ...process.env, GIT_OPTIONAL_LOCKS: "0" },
67+
maxBuffer: MAX_GIT_OUTPUT_BYTES,
68+
});
69+
if (tree.error || tree.status !== 0) return { hydrated: false, blobs: 0 };
70+
for (const entry of tree.stdout.split("\0")) {
71+
if (!entry) continue;
72+
const match = entry.match(/^\d{6} (blob|commit) ([0-9a-f]{40,64})\t(.*)$/s);
73+
if (!match || !paths.has(match[3]!)) return { hydrated: false, blobs: 0 };
74+
if (match[1] === "blob") objectIds.add(match[2]!);
75+
}
76+
}
77+
78+
if (objectIds.size === 0) return { hydrated: true, blobs: 0 };
79+
const objectInput = `${[...objectIds].join("\n")}\n`;
80+
const localObjects = spawnSync(
81+
"git",
82+
["cat-file", "--batch-check=%(objectname) %(objecttype) %(objectsize)"],
83+
{
84+
cwd: targetDir,
85+
encoding: "utf8",
86+
env: { ...process.env, GIT_OPTIONAL_LOCKS: "0", GIT_NO_LAZY_FETCH: "1" },
87+
input: objectInput,
88+
maxBuffer: MAX_GIT_OUTPUT_BYTES,
89+
},
90+
);
91+
if (localObjects.error || localObjects.status !== 0) return { hydrated: false, blobs: 0 };
92+
const found = localObjects.stdout.trim().split("\n");
93+
if (found.length !== objectIds.size) return { hydrated: false, blobs: 0 };
94+
const sizes = new Map<string, number>();
95+
const missing = new Set<string>();
96+
for (const entry of found) {
97+
const [objectId, type, size] = entry.split(" ");
98+
if (!objectId || !objectIds.has(objectId) || (type !== "blob" && type !== "missing")) {
99+
return { hydrated: false, blobs: 0 };
100+
}
101+
if (type === "missing") missing.add(objectId);
102+
else sizes.set(objectId, Number(size));
103+
}
104+
if (missing.size > 0) {
105+
if (!resolveBlobSizes) return { hydrated: false, blobs: 0 };
106+
let remoteSizes: ReadonlyMap<string, number>;
107+
try {
108+
remoteSizes = resolveBlobSizes([...missing]);
109+
} catch {
110+
return { hydrated: false, blobs: 0 };
111+
}
112+
for (const objectId of missing) {
113+
const bytes = remoteSizes.get(objectId);
114+
if (bytes === undefined) return { hydrated: false, blobs: 0 };
115+
sizes.set(objectId, bytes);
116+
}
117+
}
118+
119+
let objectBytes = 0;
120+
let skippedOversizedBlob = false;
121+
const bounded = new Set<string>();
122+
for (const objectId of objectIds) {
123+
const bytes = sizes.get(objectId);
124+
if (
125+
bytes === undefined ||
126+
!Number.isSafeInteger(bytes) ||
127+
bytes < 0 ||
128+
bytes > MAX_REVIEW_BLOB_BYTES - objectBytes
129+
) {
130+
skippedOversizedBlob = true;
131+
continue;
132+
}
133+
bounded.add(objectId);
134+
objectBytes += bytes;
135+
}
136+
137+
const boundedMissing = [...missing].filter((objectId) => bounded.has(objectId));
138+
if (boundedMissing.length > 0) {
139+
const fetched = spawnSync(
140+
"git",
141+
[
142+
"-c",
143+
"fetch.negotiationAlgorithm=noop",
144+
"fetch",
145+
"origin",
146+
"--no-tags",
147+
"--no-write-fetch-head",
148+
"--recurse-submodules=no",
149+
"--filter=blob:none",
150+
"--stdin",
151+
],
152+
{
153+
cwd: targetDir,
154+
encoding: "utf8",
155+
env: { ...process.env, GIT_OPTIONAL_LOCKS: "0" },
156+
input: `${boundedMissing.join("\n")}\n`,
157+
maxBuffer: MAX_GIT_OUTPUT_BYTES,
158+
},
159+
);
160+
if (fetched.error || fetched.status !== 0) return { hydrated: false, blobs: 0 };
161+
}
162+
return { hydrated: !skippedOversizedBlob, blobs: bounded.size };
163+
}
164+
165+
export function githubReviewBlobSizes({
166+
repository,
167+
objectIds,
168+
request,
169+
}: {
170+
repository: string;
171+
objectIds: readonly string[];
172+
request: (query: string) => unknown;
173+
}): ReadonlyMap<string, number> {
174+
const match = repository.match(/^([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)$/);
175+
if (
176+
!match ||
177+
match[1] === "." ||
178+
match[1] === ".." ||
179+
match[2] === "." ||
180+
match[2] === ".." ||
181+
objectIds.length > MAX_REVIEW_FILES * 2
182+
) {
183+
throw new Error("invalid bounded review blob metadata request");
184+
}
185+
const objects = objectIds.map((objectId, index) => {
186+
if (!GIT_OBJECT_ID.test(objectId)) throw new Error("invalid review blob object ID");
187+
return `b${index}: object(oid: "${objectId}") { ... on Blob { byteSize } }`;
188+
});
189+
const query = `query { repository(owner: "${match[1]}", name: "${match[2]}") { ${objects.join(" ")} } }`;
190+
const response = request(query);
191+
if (!response || typeof response !== "object") throw new Error("invalid review blob response");
192+
const data = (response as { data?: unknown }).data;
193+
if (!data || typeof data !== "object") throw new Error("missing review blob response data");
194+
const values = (data as { repository?: unknown }).repository;
195+
if (!values || typeof values !== "object") throw new Error("missing review blob repository");
196+
const result = new Map<string, number>();
197+
for (const [index, objectId] of objectIds.entries()) {
198+
const object = (values as Record<string, unknown>)[`b${index}`];
199+
const bytes =
200+
object && typeof object === "object" ? (object as { byteSize?: unknown }).byteSize : null;
201+
if (typeof bytes !== "number" || !Number.isSafeInteger(bytes) || bytes < 0) {
202+
throw new Error("invalid review blob size");
203+
}
204+
result.set(objectId, bytes);
205+
}
206+
return result;
207+
}
208+
209+
function safeReviewPath(value: unknown): string | null {
210+
if (typeof value !== "string" || !value || value.length > 4096) return null;
211+
if (value.startsWith("/") || value.includes("\\")) {
212+
return null;
213+
}
214+
for (let index = 0; index < value.length; index += 1) {
215+
const code = value.charCodeAt(index);
216+
if (code < 32 || code === 127) return null;
217+
}
218+
const parts = value.split("/");
219+
if (parts.some((part) => !part || part === "." || part === ".." || part === ".git")) {
220+
return null;
221+
}
222+
return value;
223+
}

‎src/clawsweeper.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ import {
5555
import { parseGhJson, parseGhJsonLinesWithRetry, parseGhJsonWithRetry } from "./github-json.js";
5656
import { stableJson } from "./stable-json.js";
5757
import { reviewPullChecksDigestParts } from "./review-checks-digest.js";
58+
import {
59+
githubReviewBlobSizes,
60+
hydratePullRequestReviewBlobs,
61+
} from "./clawsweeper-review-blobs.js";
5862
import { coverageTrackedItemIdsFromManifest } from "./review-coverage-manifest.js";
5963
import {
6064
LEGACY_FIXED_CLOSE_SKIP_ACTIONS,
@@ -4603,6 +4607,24 @@ function semanticPullFilesWithTreeIdentity(options: {
46034607
destinationRef: `refs/clawsweeper/review-cache/head-${options.itemNumber}`,
46044608
});
46054609

4610+
if (commitsAvailable) {
4611+
const hydration = hydratePullRequestReviewBlobs({
4612+
targetDir: options.targetDir,
4613+
baseSha,
4614+
headSha,
4615+
files: options.files,
4616+
resolveBlobSizes: (objectIds) =>
4617+
githubReviewBlobSizes({
4618+
repository: targetRepo(),
4619+
objectIds,
4620+
request: (query) => ghJson(["api", "graphql", "-f", `query=${query}`]),
4621+
}),
4622+
});
4623+
if (!hydration.hydrated) {
4624+
console.warn("pull-request review blobs could not be hydrated before restricted review");
4625+
}
4626+
}
4627+
46064628
return options.files.map((value) => {
46074629
const compact = asRecord(compactSemanticPullFile(value));
46084630
if (!commitsAvailable) return { ...compact, treeModesComplete: false };

‎src/repair/dispatch-jobs.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ function shouldDispatchJob(relative: JsonValue) {
154154
activeRunsByPrefix: activeRepairRunsByPrefix,
155155
});
156156
if (!activeRun) return true;
157+
const createdAt = String(activeRun.createdAt ?? "");
158+
if (
159+
relative.includes("/inbox/issue-") &&
160+
process.env.GITHUB_OUTPUT &&
161+
Number.isFinite(Date.parse(createdAt))
162+
) {
163+
fs.appendFileSync(process.env.GITHUB_OUTPUT, `issue_worker_created_at=${createdAt}\n`);
164+
}
157165
console.log(
158166
`skipping ${relative}: active ${workflow} run already exists (${activeRun.url ?? activeRun.databaseId ?? "unknown run"})`,
159167
);

‎src/repair/execute-fix-validation.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import fs from "node:fs";
22
import path from "node:path";
33

44
import type { JsonValue, LooseRecord } from "./json-types.js";
5+
import {
6+
REVIEW_REPRODUCIBLE_BUG_TRIGGER_SOURCE,
7+
REVIEW_VIABLE_ISSUE_TRIGGER_SOURCE,
8+
REVIEW_VISION_FIT_TRIGGER_SOURCE,
9+
} from "./comment-router-core.js";
510
import { validateRepairContractShape } from "./repair-contract.js";
611
import { GITHUB_PR_TITLE_MAX_LENGTH } from "./pr-title.js";
712
import { slug } from "./text-utils.js";
@@ -13,6 +18,11 @@ const REPAIR_STRATEGIES = new Set([
1318
]);
1419
export const HUMAN_REVIEW_LABEL = "clawsweeper:human-review";
1520
export const MANUAL_ONLY_LABEL = "clawsweeper:manual-only";
21+
const REVIEWED_ISSUE_TRIGGER_SOURCES = new Set([
22+
REVIEW_REPRODUCIBLE_BUG_TRIGGER_SOURCE,
23+
REVIEW_VIABLE_ISSUE_TRIGGER_SOURCE,
24+
REVIEW_VISION_FIT_TRIGGER_SOURCE,
25+
]);
1626

1727
export function repairPauseLabel(labels: Iterable<JsonValue> | null | undefined): string | null {
1828
for (const label of labels ?? []) {
@@ -172,7 +182,7 @@ function isTrustedIssueImplementation({ job, fixArtifact }: LooseRecord): boolea
172182
if (!Array.isArray(frontmatter.allowed_actions) || !frontmatter.allowed_actions.includes("fix")) {
173183
return false;
174184
}
175-
if (frontmatter.trigger_source !== "review_viable_issue") return false;
185+
if (!REVIEWED_ISSUE_TRIGGER_SOURCES.has(frontmatter.trigger_source)) return false;
176186
const repo = String(frontmatter.repo ?? "")
177187
.trim()
178188
.toLowerCase();

0 commit comments

Comments
 (0)