Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions adapters/cloudflare-workflow/worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ async function checkReviewQuorum({
const requiredProviders = requiredProviderCountForReview({
allFiles: reviewPathsFromFiles(ctx.files),
});
const previousReview = findPreviousReview(ctx.comments, {
headSha,
trustedLogins: trustedReviewerLogins({
reviewerProviders,
enabledSubscriptionProviders: enabledSubscriptions,
}),
});
const decision = planApiReviewer({
provider,
role: providerRole,
Expand All @@ -72,6 +79,7 @@ async function checkReviewQuorum({
forceProvider,
graceMinutes,
waitedForFallback,
stickyProvider: previousReview?.provider ?? null,
});
if (!decision.run) {
return {
Expand All @@ -84,13 +92,6 @@ async function checkReviewQuorum({
// Re-review converges only on an ancestor previous head; rebases/force
// pushes and compare failures fall back to a normal full review.
let incremental = null;
const previousReview = findPreviousReview(ctx.comments, {
headSha,
trustedLogins: trustedReviewerLogins({
reviewerProviders,
enabledSubscriptionProviders: enabledSubscriptions,
}),
});
if (previousReview) {
try {
const compare = await fetchCompareDiff({
Expand Down
16 changes: 16 additions & 0 deletions packages/review-core/route.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export function planApiReviewer({
forceProvider = false,
graceMinutes = DEFAULT_FALLBACK_GRACE_MINUTES,
waitedForFallback = false,
stickyProvider = null,
} = {}) {
const current = String(provider || '').trim().toLowerCase();
if (!current) throw new Error('Missing API review provider');
Expand All @@ -115,6 +116,21 @@ export function planApiReviewer({
return { run: false, waitMinutes: 0, role: normalizedRole, reason: 'quorum_satisfied' };
}

const sticky = String(stickyProvider || '').trim().toLowerCase();
if (requiredProviders < 2 && existing.size === 0 && sticky) {
if (current === sticky) {
return { run: true, waitMinutes: 0, role: normalizedRole, reason: 'sticky_provider' };
}
if (waitedForFallback) {
return { run: true, waitMinutes: 0, role: normalizedRole, reason: 'fallback_after_sticky_grace' };
}
const waitMinutes = parseGraceMinutes(graceMinutes);
if (waitMinutes > 0) {
return { run: false, waitMinutes, role: normalizedRole, reason: 'waiting_for_sticky_provider' };
}
return { run: true, waitMinutes: 0, role: normalizedRole, reason: 'fallback_after_sticky_grace' };
}

if (normalizedRole === 'fallback' && (requiredProviders < 2 || existing.size === 0)) {
if (waitedForFallback) {
return { run: true, waitMinutes: 0, role: normalizedRole, reason: 'fallback_after_grace' };
Expand Down
51 changes: 51 additions & 0 deletions tests/review-core.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2501,6 +2501,57 @@ test('executeReviewWithFallback runs dual-model OpenCode cross-review on high-ri
}, mockFetch), /must differ from OPENCODE_MODEL/);
});

test('planApiReviewer honours PR-level stickyProvider before fallback grace takeover', () => {
const stickyFallback = planApiReviewer({
provider: 'opencode',
role: 'fallback',
stickyProvider: 'opencode',
graceMinutes: 10,
});
assert.deepEqual(stickyFallback, {
run: true,
waitMinutes: 0,
role: 'fallback',
reason: 'sticky_provider',
});

const nonStickyWaiting = planApiReviewer({
provider: 'deepseek',
role: 'primary',
stickyProvider: 'opencode',
graceMinutes: 10,
});
assert.deepEqual(nonStickyWaiting, {
run: false,
waitMinutes: 10,
role: 'primary',
reason: 'waiting_for_sticky_provider',
});

const takeoverAfterGrace = planApiReviewer({
provider: 'deepseek',
role: 'primary',
stickyProvider: 'opencode',
graceMinutes: 10,
waitedForFallback: true,
});
assert.deepEqual(takeoverAfterGrace, {
run: true,
waitMinutes: 0,
role: 'primary',
reason: 'fallback_after_sticky_grace',
});

const forcedPrimary = planApiReviewer({
provider: 'deepseek',
role: 'primary',
stickyProvider: 'opencode',
forceProvider: true,
});
assert.equal(forcedPrimary.reason, 'forced');
assert.equal(forcedPrimary.run, true);
});

test('buildReviewBatches/Diff surface skipped lockfiles and buildReviewMessages isolates calibration vs untrusted summary', () => {
const files = [
{ filename: 'pyproject.toml', status: 'modified', additions: 2, deletions: 0, patch: '+import-linter==2.17' },
Expand Down
Loading