Skip to content

Commit 0a3d5c5

Browse files
committed
fix(review): ignore duplicate checks in cache keys
1 parent c8f4488 commit 0a3d5c5

6 files changed

Lines changed: 179 additions & 4 deletions

‎src/clawsweeper.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import {
5454
} from "./github-retry.js";
5555
import { parseGhJson, parseGhJsonLinesWithRetry, parseGhJsonWithRetry } from "./github-json.js";
5656
import { stableJson } from "./stable-json.js";
57+
import { reviewPullChecksDigestParts } from "./review-checks-digest.js";
5758
import { coverageTrackedItemIdsFromManifest } from "./review-coverage-manifest.js";
5859
import {
5960
LEGACY_FIXED_CLOSE_SKIP_ACTIONS,
@@ -3184,7 +3185,7 @@ function itemContentDigest(item: Item, context: ItemContext, git?: GitInfo): str
31843185
? (context.pullReviewCommentsRevision ??
31853186
reviewCommentDigestParts(context.pullReviewComments))
31863187
: null,
3187-
checks: isPull ? (context.pullChecks ?? null) : null,
3188+
checks: isPull ? reviewPullChecksDigestParts(context.pullChecks ?? null) : null,
31883189
}),
31893190
);
31903191
}
@@ -9165,7 +9166,7 @@ function fetchReviewStructuralRecord(options: {
91659166
if (!headSha) return null;
91669167
const pullChecks = pullChecksContext(options.item.number, headSha);
91679168
if (!completePullChecksContext(pullChecks)) return null;
9168-
pullChecksDigest = sha256(stableJson(pullChecks));
9169+
pullChecksDigest = sha256(stableJson(reviewPullChecksDigestParts(pullChecks)));
91699170
}
91709171
return reviewStructuralRecordFromGraphql({
91719172
response,

‎src/review-checks-digest.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { stableJsonCodeUnit } from "./stable-json.js";
2+
3+
export function reviewPullChecksDigestParts(value: unknown): unknown {
4+
if (!value || typeof value !== "object" || Array.isArray(value)) return value;
5+
const checks = value as Record<string, unknown>;
6+
if (!Array.isArray(checks.checkRuns)) return value;
7+
8+
const seen = new Set<string>();
9+
const checkRuns = checks.checkRuns.filter((checkRun) => {
10+
const identity = stableJsonCodeUnit(checkRun);
11+
if (seen.has(identity)) return false;
12+
seen.add(identity);
13+
return true;
14+
});
15+
16+
return checkRuns.length === checks.checkRuns.length ? value : { ...checks, checkRuns };
17+
}

‎src/review-semantic-cache.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { createVirtualFileSystem, type FileSystem } from "typescript/unstable/fs
66
import { API } from "typescript/unstable/sync";
77

88
import { REVIEW_CACHE_MAX_AGE_DAYS } from "./scheduler-policy.js";
9+
import { reviewPullChecksDigestParts } from "./review-checks-digest.js";
910
import { stableJsonCodeUnit as stableJson } from "./stable-json.js";
1011

1112
export const REVIEW_SEMANTIC_CACHE_VERSION = 10;
@@ -782,7 +783,7 @@ function semanticContext(input: ReviewSemanticInput): {
782783
reviewComments:
783784
input.context.pullReviewCommentsRevision ??
784785
normalizedComments(input.context.pullReviewComments),
785-
checks: input.context.pullChecks ?? null,
786+
checks: reviewPullChecksDigestParts(input.context.pullChecks ?? null),
786787
completeness: {
787788
commentsTruncated: input.context.counts?.commentsTruncated ?? null,
788789
timelineTruncated: input.context.counts?.timelineTruncated ?? null,

‎test/review-comment-rendering.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,10 @@ test("structural cache probes before hydration but acquires a lease before carry
166166
source.indexOf("function collectItemContext"),
167167
);
168168
assert.match(structuralProbeSource, /pullChecksContext\(options\.item\.number, headSha\)/);
169-
assert.match(structuralProbeSource, /pullChecksDigest = sha256\(stableJson\(pullChecks\)\)/);
169+
assert.match(
170+
structuralProbeSource,
171+
/pullChecksDigest = sha256\(stableJson\(reviewPullChecksDigestParts\(pullChecks\)\)\)/,
172+
);
170173
assert.match(structuralProbeSource, /if \(!options\.git\.releaseStateComplete\) return null/);
171174
const gitInfoBlock = source.slice(
172175
source.indexOf("function gitInfo("),

‎test/review-content-cache.test.ts‎

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,101 @@ test("content digest busts when bounded PR check state changes", () => {
294294
assert.notEqual(passing, failing);
295295
});
296296

297+
test("content digest ignores duplicate compacted PR check runs", () => {
298+
const pull = item({ kind: "pull_request", number: 200 });
299+
const notify = {
300+
name: "notify",
301+
status: "completed",
302+
conclusion: "success",
303+
app: "github-actions",
304+
};
305+
const once = itemContentDigestForTest(
306+
pull,
307+
pullContext({
308+
pullChecks: {
309+
complete: true,
310+
checkRuns: [notify],
311+
checkRunsTruncated: false,
312+
statuses: [],
313+
statusesTruncated: false,
314+
},
315+
}),
316+
);
317+
const repeated = itemContentDigestForTest(
318+
pull,
319+
pullContext({
320+
pullChecks: {
321+
complete: true,
322+
checkRuns: [notify, notify],
323+
checkRunsTruncated: false,
324+
statuses: [],
325+
statusesTruncated: false,
326+
},
327+
}),
328+
);
329+
330+
assert.equal(once, repeated);
331+
});
332+
333+
test("content digest keeps check runs that differ only in name or app", () => {
334+
const pull = item({ kind: "pull_request", number: 200 });
335+
const check = {
336+
name: "smoke",
337+
status: "completed",
338+
conclusion: "success",
339+
app: "github-actions",
340+
};
341+
const digest = (checkRuns) =>
342+
itemContentDigestForTest(
343+
pull,
344+
pullContext({
345+
pullChecks: {
346+
complete: true,
347+
checkRuns,
348+
checkRunsTruncated: false,
349+
statuses: [],
350+
statusesTruncated: false,
351+
},
352+
}),
353+
);
354+
355+
const alone = digest([check]);
356+
const byName = digest([check, { ...check, name: "smoke (windows)" }]);
357+
const byApp = digest([check, { ...check, app: "blacksmith-sh" }]);
358+
359+
assert.notEqual(alone, byName);
360+
assert.notEqual(alone, byApp);
361+
assert.notEqual(byName, byApp);
362+
});
363+
364+
test("content digest busts when one of several repeated check runs newly fails", () => {
365+
const pull = item({ kind: "pull_request", number: 200 });
366+
const notify = {
367+
name: "notify",
368+
status: "completed",
369+
conclusion: "success",
370+
app: "github-actions",
371+
};
372+
const digest = (checkRuns) =>
373+
itemContentDigestForTest(
374+
pull,
375+
pullContext({
376+
pullChecks: {
377+
complete: true,
378+
checkRuns,
379+
checkRunsTruncated: false,
380+
statuses: [],
381+
statusesTruncated: false,
382+
},
383+
}),
384+
);
385+
386+
const allPassing = digest([notify, notify, notify]);
387+
const oneFailing = digest([notify, notify, { ...notify, conclusion: "failure" }]);
388+
389+
assert.notEqual(allPassing, oneFailing);
390+
});
391+
297392
test("review comment revision covers comments outside the bounded prompt window", () => {
298393
const comments = Array.from({ length: 81 }, (_, index) => ({
299394
id: index + 1,
@@ -353,6 +448,48 @@ test("cache hits when content is unchanged, fresh, complete, and policy matches"
353448
assert.equal(cacheHit(), true);
354449
});
355450

451+
test("cache hits after an equivalent check run is repeated on an unchanged head", () => {
452+
const pull = item({ kind: "pull_request", number: 200 });
453+
const notify = {
454+
name: "notify",
455+
status: "completed",
456+
conclusion: "success",
457+
app: "github-actions",
458+
};
459+
const priorDigest = itemContentDigestForTest(
460+
pull,
461+
pullContext({
462+
pullChecks: {
463+
complete: true,
464+
checkRuns: [notify],
465+
checkRunsTruncated: false,
466+
statuses: [],
467+
statusesTruncated: false,
468+
},
469+
}),
470+
);
471+
const currentDigest = itemContentDigestForTest(
472+
pull,
473+
pullContext({
474+
pullChecks: {
475+
complete: true,
476+
checkRuns: [notify, notify],
477+
checkRunsTruncated: false,
478+
statuses: [],
479+
statusesTruncated: false,
480+
},
481+
}),
482+
);
483+
484+
assert.equal(
485+
cacheHit({
486+
review: freshReview({ contentDigest: priorDigest }),
487+
contentDigest: currentDigest,
488+
}),
489+
true,
490+
);
491+
});
492+
356493
test("cache misses when the content digest differs", () => {
357494
assert.equal(cacheHit({ contentDigest: "digest-2" }), false);
358495
});

‎test/review-semantic-cache.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,22 @@ test("changed discussion, reviews, checks, or target context busts the context d
10791079
}
10801080
});
10811081

1082+
test("duplicate compacted check runs do not perturb the semantic context digest", () => {
1083+
const prior = record();
1084+
const checkRuns = input().context.pullChecks.checkRuns;
1085+
const repeated = record({
1086+
context: {
1087+
pullChecks: {
1088+
...input().context.pullChecks,
1089+
checkRuns: [...checkRuns, ...checkRuns],
1090+
},
1091+
},
1092+
});
1093+
1094+
assert.equal(prior.contextDigest, repeated.contextDigest);
1095+
assert.equal(decision({ priorRecord: prior, currentRecord: repeated }).reason, "hit");
1096+
});
1097+
10821098
test("head SHA churn alone does not perturb semantic or context digests", () => {
10831099
const prior = record();
10841100
const rebased = record({

0 commit comments

Comments
 (0)