Skip to content

Commit a65acb1

Browse files
fix(review): hosted pull request reviews fail closed before Codex runs (#1308)
* fix(review): hosted pull request reviews fail closed before Codex runs Review history hydration attempts one bounded fetch that names both the pinned base and the reviewed head. A depth-limited fetch sets the retained depth from every revision it names rather than extending history, so naming the base moves that window's origin to the base and drops the merge base out of it. On a live reproduction the commits reachable from the pinned base fall from 84,773 to 256 and the merge base, 189 commits behind that base, is lost with them. Hydration then reports no merge base and the host-owned input scan refuses incomplete_source before any agent runs, so the pull request gets no verdict and the durable queue re-leases an item that keeps failing. Deepen the reviewed head on its own first, since tree hydration fetched it at depth one and the merge base sits just behind it. If that does not establish one, fall back to the fetch this function already issued, unchanged, for the case where the base is itself shallow. The fallback is byte-identical to today's behaviour, so this can only add recoveries; the depth bound, filters, timeout and admission predicate are unchanged, and history that cannot be reached within the bound still reports no merge base and still refuses. * docs(changelog): record hosted review history recovery * docs(changelog): avoid concurrent main entry conflict --------- Co-authored-by: Peter Steinberger <[email protected]>
1 parent 76636fa commit a65acb1

3 files changed

Lines changed: 280 additions & 20 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ checkpoint, and status-only commits are intentionally omitted.
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.
6868
- 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.
6969
- Stopped treating pane-local runtime state as stored data while retaining warnings for explicit persistence changes and incomplete storage patches.
70+
- 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))
7071
- Corrected retained terminal-proof cleanup for independent process-exit and PTY-close events, preserving the original wrapper failure and draining dead-pane capture only after verified cleanup.
7172
- Prevented rejected model inputs from surviving in generated prompt artifacts; retained diagnostics now follow admission with owner-only access, and unused prompt copies are no longer written.
7273
- Provisioned pinned TruffleHog for hosted reviews and enforced complete host-owned input scans before native review or cache reuse, preserving read-only workers, proxy authentication, and redacted fail-closed errors.

‎src/clawsweeper-review-blobs.ts‎

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,30 @@ export function ensurePullRequestReviewHead({
9393
);
9494
}
9595

96+
const REVIEW_HISTORY_DEPTH = 256;
97+
98+
function deepenReviewHistory(targetDir: string, revisions: readonly string[]): void {
99+
spawnSync(
100+
"git",
101+
[
102+
"fetch",
103+
"--filter=blob:none",
104+
"--no-tags",
105+
"--no-write-fetch-head",
106+
"--recurse-submodules=no",
107+
`--depth=${REVIEW_HISTORY_DEPTH}`,
108+
"origin",
109+
...revisions,
110+
],
111+
{
112+
cwd: targetDir,
113+
env: { ...process.env, GIT_OPTIONAL_LOCKS: "0" },
114+
stdio: "ignore",
115+
timeout: 30_000,
116+
},
117+
);
118+
}
119+
96120
export function hydratePullRequestReviewHistory(options: {
97121
targetDir: string;
98122
baseSha: string;
@@ -111,26 +135,18 @@ export function hydratePullRequestReviewHistory(options: {
111135
if (reviewMergeBase(targetDir, baseSha, headSha).status === "unavailable") {
112136
// Existing tree hydration may have fetched only the PR tip. Bound history, not
113137
// the reviewed identity; failure remains explicit in the local evidence reader.
114-
spawnSync(
115-
"git",
116-
[
117-
"fetch",
118-
"--filter=blob:none",
119-
"--no-tags",
120-
"--no-write-fetch-head",
121-
"--recurse-submodules=no",
122-
"--depth=256",
123-
"origin",
124-
baseSha,
125-
headSha,
126-
],
127-
{
128-
cwd: targetDir,
129-
env: { ...process.env, GIT_OPTIONAL_LOCKS: "0" },
130-
stdio: "ignore",
131-
timeout: 30_000,
132-
},
133-
);
138+
//
139+
// Deepen the reviewed head on its own first. A depth-limited fetch re-bounds the
140+
// ancestry of every revision it names, so naming the pinned base here as well
141+
// truncates a base branch whose history the checkout already had -- the very
142+
// ancestry a merge base is found in. Only deepen the base when the head alone did
143+
// not establish one, which is the case where the base is itself shallow.
144+
deepenReviewHistory(targetDir, [headSha]);
145+
if (reviewMergeBase(targetDir, baseSha, headSha).status === "unavailable") {
146+
// Unchanged fallback: the same fetch this function has always issued, for the case
147+
// where the base is itself shallow and has to be deepened to reach an ancestor.
148+
deepenReviewHistory(targetDir, [baseSha, headSha]);
149+
}
134150
}
135151
if (testMergeSha && GIT_OBJECT_ID.test(testMergeSha)) {
136152
ensureReviewTreeCommit({

‎test/review-blob-hydration.test.ts‎

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import {
99
ensurePullRequestReviewHead,
1010
githubReviewBlobSizes,
1111
hydratePullRequestReviewBlobs,
12+
hydratePullRequestReviewHistory,
1213
materializePullRequestReviewTree,
1314
removePullRequestReviewTree,
1415
} from "../dist/clawsweeper-review-blobs.js";
16+
import { reviewMergeBase } from "../dist/pr-review-evidence.js";
1517

1618
function git(cwd: string, ...args: string[]): string {
1719
return execFileSync("git", args, { cwd, encoding: "utf8" }).trim();
@@ -104,6 +106,247 @@ function objectExistsOffline(cwd: string, sha: string): boolean {
104106
);
105107
}
106108

109+
// A review target is a single-branch, blobless clone of the base branch, so the reviewed
110+
// head arrives shallow and history hydration has to reach a merge base. A depth-limited
111+
// fetch re-bounds every revision it names, so hydration must not name a base branch whose
112+
// ancestry the checkout already holds.
113+
function reviewHistoryFixture({
114+
commitsBeforeBranch,
115+
commitsAfterBranch,
116+
commitsOnBranch = 0,
117+
commitsPastBase = 0,
118+
cloneDepth,
119+
baseRefreshDepth = 50,
120+
publishPullRef = true,
121+
}: {
122+
commitsBeforeBranch: number;
123+
commitsAfterBranch: number;
124+
commitsOnBranch?: number;
125+
commitsPastBase?: number;
126+
cloneDepth?: number;
127+
baseRefreshDepth?: number;
128+
publishPullRef?: boolean;
129+
}) {
130+
const root = mkdtempSync(join(tmpdir(), "clawsweeper-review-history-"));
131+
const origin = join(root, "origin.git");
132+
const source = join(root, "source");
133+
const target = join(root, "target");
134+
mkdirSync(source);
135+
git(root, "init", "--bare", "-q", origin);
136+
git(origin, "config", "uploadpack.allowFilter", "true");
137+
git(origin, "config", "uploadpack.allowAnySHA1InWant", "true");
138+
git(source, "init", "-q", "-b", "main");
139+
git(source, "config", "user.name", "ClawSweeper Review Test");
140+
git(source, "config", "user.email", "[email protected]");
141+
git(source, "config", "commit.gpgsign", "false");
142+
const commit = (name: string) => {
143+
writeFileSync(join(source, "history.txt"), `${name}\n`);
144+
git(source, "add", "-A");
145+
git(source, "commit", "-qm", name);
146+
};
147+
commit("root");
148+
for (let index = 0; index < commitsBeforeBranch; index += 1) commit(`history ${index}`);
149+
const branchPoint = git(source, "rev-parse", "HEAD");
150+
git(source, "checkout", "-qb", "feature");
151+
writeFileSync(join(source, "feature.txt"), "feature\n");
152+
git(source, "add", "-A");
153+
git(source, "commit", "-qm", "feature");
154+
for (let index = 0; index < commitsOnBranch; index += 1) {
155+
writeFileSync(join(source, "feature.txt"), `feature ${index}\n`);
156+
git(source, "commit", "-qam", `feature ${index}`);
157+
}
158+
const headSha = git(source, "rev-parse", "HEAD");
159+
git(source, "checkout", "-q", "main");
160+
for (let index = 0; index < commitsAfterBranch; index += 1) commit(`base ${index}`);
161+
// A pull request pins the base branch where it stood when the request was opened, so the
162+
// branch usually moves on past it. Commits past that point put the pinned base behind the
163+
// depth-limited refresh boundary, exactly as it sits in a hosted review.
164+
const baseSha = git(source, "rev-parse", "HEAD");
165+
for (let index = 0; index < commitsPastBase; index += 1) commit(`past base ${index}`);
166+
git(source, "remote", "add", "origin", origin);
167+
git(source, "push", "-q", "origin", "main");
168+
if (publishPullRef) git(source, "push", "-q", "origin", "feature:refs/pull/982/head");
169+
170+
git(
171+
root,
172+
"clone",
173+
"-q",
174+
"--filter=blob:none",
175+
"--branch",
176+
"main",
177+
"--single-branch",
178+
...(cloneDepth ? [`--depth=${cloneDepth}`] : []),
179+
`file://${origin}`,
180+
target,
181+
);
182+
// The review runtime refreshes the base branch with a depth-limited fetch before reviewing.
183+
git(
184+
target,
185+
"fetch",
186+
"-q",
187+
"origin",
188+
"refs/heads/main:refs/remotes/origin/main",
189+
`--depth=${baseRefreshDepth}`,
190+
);
191+
return { root, target, baseSha, headSha, branchPoint };
192+
}
193+
194+
function reachable(target: string, sha: string): number {
195+
const count = spawnSync("git", ["rev-list", "--count", sha], {
196+
cwd: target,
197+
encoding: "utf8",
198+
env: { ...process.env, GIT_NO_LAZY_FETCH: "1" },
199+
});
200+
return count.status === 0 ? Number(count.stdout.trim()) : -1;
201+
}
202+
203+
test("review history hydration keeps base ancestry the checkout already had", () => {
204+
// The base branch's history is present and deeper than the bounded deepening, and the
205+
// merge base is two commits behind the reviewed head but further behind the pinned base
206+
// than the bound reaches. Naming the base in that fetch re-bounds ancestry the checkout
207+
// already had and loses the merge base with it; deepening the head alone finds it.
208+
const fixture = reviewHistoryFixture({
209+
commitsBeforeBranch: 300,
210+
commitsAfterBranch: 300,
211+
commitsPastBase: 100,
212+
});
213+
try {
214+
assert.ok(
215+
ensurePullRequestReviewHead({
216+
targetDir: fixture.target,
217+
itemNumber: 982,
218+
headSha: fixture.headSha,
219+
}),
220+
);
221+
const before = reachable(fixture.target, fixture.baseSha);
222+
assert.ok(before > 256, `expected deep base ancestry, saw ${before}`);
223+
assert.equal(
224+
reviewMergeBase(fixture.target, fixture.baseSha, fixture.headSha).status,
225+
"unavailable",
226+
);
227+
228+
assert.equal(
229+
hydratePullRequestReviewHistory({
230+
targetDir: fixture.target,
231+
baseSha: fixture.baseSha,
232+
headSha: fixture.headSha,
233+
itemNumber: 982,
234+
}),
235+
fixture.branchPoint,
236+
);
237+
238+
assert.equal(
239+
reviewMergeBase(fixture.target, fixture.baseSha, fixture.headSha).status,
240+
"verified",
241+
);
242+
assert.ok(
243+
reachable(fixture.target, fixture.baseSha) > 256,
244+
"hydration must not re-bound base ancestry to the fetch depth",
245+
);
246+
} finally {
247+
rmSync(fixture.root, { recursive: true, force: true });
248+
}
249+
});
250+
251+
test("review history hydration still deepens a base branch that is itself shallow", () => {
252+
// Shallow clone: the pinned base arrives with no ancestry, so reaching a merge base needs
253+
// the base deepened too. Deepening only the head must not be the whole story.
254+
const fixture = reviewHistoryFixture({
255+
commitsBeforeBranch: 10,
256+
commitsAfterBranch: 20,
257+
cloneDepth: 1,
258+
baseRefreshDepth: 1,
259+
});
260+
try {
261+
assert.ok(
262+
ensurePullRequestReviewHead({
263+
targetDir: fixture.target,
264+
itemNumber: 982,
265+
headSha: fixture.headSha,
266+
}),
267+
);
268+
assert.equal(reachable(fixture.target, fixture.baseSha), 1);
269+
270+
assert.equal(
271+
hydratePullRequestReviewHistory({
272+
targetDir: fixture.target,
273+
baseSha: fixture.baseSha,
274+
headSha: fixture.headSha,
275+
itemNumber: 982,
276+
}),
277+
fixture.branchPoint,
278+
);
279+
assert.equal(
280+
reviewMergeBase(fixture.target, fixture.baseSha, fixture.headSha).status,
281+
"verified",
282+
);
283+
} finally {
284+
rmSync(fixture.root, { recursive: true, force: true });
285+
}
286+
});
287+
288+
test("review history hydration stays fail-closed when the bounded deepening cannot reach", () => {
289+
// The merge base is further from the reviewed head than the bounded deepening reaches.
290+
// That is the documented bound doing its job, not the defect above: no merge base is
291+
// reported and the caller keeps refusing.
292+
const fixture = reviewHistoryFixture({
293+
commitsBeforeBranch: 5,
294+
commitsAfterBranch: 400,
295+
cloneDepth: 1,
296+
baseRefreshDepth: 1,
297+
});
298+
try {
299+
assert.ok(
300+
ensurePullRequestReviewHead({
301+
targetDir: fixture.target,
302+
itemNumber: 982,
303+
headSha: fixture.headSha,
304+
}),
305+
);
306+
assert.equal(
307+
hydratePullRequestReviewHistory({
308+
targetDir: fixture.target,
309+
baseSha: fixture.baseSha,
310+
headSha: fixture.headSha,
311+
itemNumber: 982,
312+
}),
313+
null,
314+
);
315+
assert.equal(
316+
reviewMergeBase(fixture.target, fixture.baseSha, fixture.headSha).status,
317+
"unavailable",
318+
);
319+
} finally {
320+
rmSync(fixture.root, { recursive: true, force: true });
321+
}
322+
});
323+
324+
test("review history hydration reports no merge base when the pull ref is unreachable", () => {
325+
const fixture = reviewHistoryFixture({
326+
commitsBeforeBranch: 5,
327+
commitsAfterBranch: 5,
328+
publishPullRef: false,
329+
});
330+
try {
331+
rmSync(join(fixture.root, "origin.git"), { recursive: true, force: true });
332+
assert.equal(
333+
hydratePullRequestReviewHistory({
334+
targetDir: fixture.target,
335+
baseSha: fixture.baseSha,
336+
headSha: fixture.headSha,
337+
itemNumber: 982,
338+
}),
339+
null,
340+
);
341+
assert.equal(
342+
reviewMergeBase(fixture.target, fixture.baseSha, fixture.headSha).status,
343+
"unavailable",
344+
);
345+
} finally {
346+
rmSync(fixture.root, { recursive: true, force: true });
347+
}
348+
});
349+
107350
test("restricted PR review can inspect changed blobs from a genuine blobless clone offline", () => {
108351
const fixture = partialCloneFixture();
109352
try {

0 commit comments

Comments
 (0)