Skip to content

Commit 9f76d13

Browse files
committed
harden close-verdict cache against target-branch drift
A close verdict (for example implemented_on_main) depends on target-branch code that is not in the content digest, because the live main sha advances on every merge and would collapse the cache. Gate cache hits for close verdicts on the stored main_sha matching the current one, so a main-branch change forces a full re-review before any close and a close is never carried across target-branch state it was not verified against. keep_open verdicts still cache on content alone.
1 parent 08928d4 commit 9f76d13

3 files changed

Lines changed: 50 additions & 0 deletions

File tree

‎src/clawsweeper.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ interface ExistingReview {
339339
decision: string | undefined;
340340
reviewStatus: string | undefined;
341341
reviewPolicy: string | undefined;
342+
mainSha: string | undefined;
342343
contentDigest: string | undefined;
343344
lastFullReviewAt: string | undefined;
344345
}
@@ -5361,6 +5362,7 @@ function existingReview(
53615362
decision: frontMatterValue(markdown, "decision"),
53625363
reviewStatus: effectiveReviewStatus(markdown),
53635364
reviewPolicy: frontMatterValue(markdown, "review_policy"),
5365+
mainSha: frontMatterValue(markdown, "main_sha"),
53645366
contentDigest: frontMatterValue(markdown, "review_content_digest"),
53655367
lastFullReviewAt: frontMatterValue(markdown, "last_full_review_at"),
53665368
};
@@ -5391,6 +5393,7 @@ function buildExistingReviewIndex(itemsDir: string): ExistingReviewIndex {
53915393
decision: frontMatterValue(markdown, "decision"),
53925394
reviewStatus: effectiveReviewStatus(markdown),
53935395
reviewPolicy: frontMatterValue(markdown, "review_policy"),
5396+
mainSha: frontMatterValue(markdown, "main_sha"),
53945397
contentDigest: frontMatterValue(markdown, "review_content_digest"),
53955398
lastFullReviewAt: frontMatterValue(markdown, "last_full_review_at"),
53965399
});
@@ -16787,6 +16790,7 @@ function reviewCommand(args: Args): void {
1678716790
review: priorReview,
1678816791
reviewPolicy,
1678916792
contentDigest,
16793+
currentMainSha: git.mainSha,
1679016794
now: Date.now(),
1679116795
explicitDispatch,
1679216796
maintainerRequest,

‎src/scheduler-policy.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export interface SchedulerExistingReview {
1515
labelsSyncedAt?: string | undefined;
1616
reviewStatus?: string | undefined;
1717
reviewPolicy?: string | undefined;
18+
decision?: string | undefined;
19+
mainSha?: string | undefined;
1820
contentDigest?: string | undefined;
1921
lastFullReviewAt?: string | undefined;
2022
}
@@ -147,6 +149,7 @@ export function reviewContentCacheHit(options: {
147149
review: SchedulerExistingReview | null;
148150
reviewPolicy: string | undefined;
149151
contentDigest: string;
152+
currentMainSha?: string | undefined;
150153
now?: number;
151154
explicitDispatch: boolean;
152155
maintainerRequest: boolean;
@@ -156,6 +159,12 @@ export function reviewContentCacheHit(options: {
156159
if (!review || review.reviewStatus !== "complete") return false;
157160
if (hasReviewPolicyMismatch(review, options.reviewPolicy)) return false;
158161
if (!review.contentDigest || review.contentDigest !== options.contentDigest) return false;
162+
if (
163+
review.decision === "close" &&
164+
(!review.mainSha || review.mainSha !== options.currentMainSha)
165+
) {
166+
return false;
167+
}
159168
const lastFullReviewAt = timestampMs(review.lastFullReviewAt);
160169
if (lastFullReviewAt === null) return false;
161170
const now = options.now ?? Date.now();

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,40 @@ test("cache misses on a first-ever review", () => {
216216
test("cache misses when the prior review predates the digest field", () => {
217217
assert.equal(cacheHit({ review: freshReview({ contentDigest: undefined }) }), false);
218218
});
219+
220+
test("close verdict cache hits when target-branch state is unchanged", () => {
221+
assert.equal(
222+
cacheHit({
223+
review: freshReview({ decision: "close", mainSha: "main-1" }),
224+
currentMainSha: "main-1",
225+
}),
226+
true,
227+
);
228+
});
229+
230+
test("close verdict cache misses when the target branch moved", () => {
231+
assert.equal(
232+
cacheHit({
233+
review: freshReview({ decision: "close", mainSha: "main-1" }),
234+
currentMainSha: "main-2",
235+
}),
236+
false,
237+
);
238+
});
239+
240+
test("close verdict cache misses when the prior review has no target-branch sha", () => {
241+
assert.equal(
242+
cacheHit({ review: freshReview({ decision: "close" }), currentMainSha: "main-1" }),
243+
false,
244+
);
245+
});
246+
247+
test("keep-open verdict cache hits despite target-branch movement", () => {
248+
assert.equal(
249+
cacheHit({
250+
review: freshReview({ decision: "keep_open", mainSha: "main-1" }),
251+
currentMainSha: "main-2",
252+
}),
253+
true,
254+
);
255+
});

0 commit comments

Comments
 (0)