Skip to content

Commit 5edc064

Browse files
fix: gate scheduled feed on worker support
1 parent eeca3e7 commit 5edc064

3 files changed

Lines changed: 47 additions & 12 deletions

File tree

‎docs/scheduler.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ items, records each candidate's previous-review age in `plan.json`, and writes a
315315
run-summary funnel for selected, attempted, enqueued, deduped, shed, and deferred
316316
items. The queue exposes the configured rate, burst, and currently available
317317
token balance under `scheduled_feed` in `GET /api/exact-review-queue`.
318+
The producer probes that field before its first enqueue and fails closed while
319+
an older Worker is still deployed, preventing a workflow-first rollout from
320+
bypassing the rate limiter.
318321

319322
At the configured target, the installation-token estimate is
320323
`200 reviews/hour * 30 calls/review = 6,000 calls/hour`. That is half of the

‎src/repair/scheduled-review-enqueue.ts‎

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ export async function enqueueScheduledReviewPlan(
4747
options: EnqueueOptions,
4848
): Promise<ScheduledReviewEnqueueSummary> {
4949
const fetchImpl = options.fetchImpl ?? fetch;
50+
for (const candidate of options.plan.candidates) validateCandidate(candidate, options.targetRepo);
51+
const queueUrl = options.queueUrl.replace(/\/$/, "");
52+
const capabilityResponse = await fetchImpl(`${queueUrl}/api/exact-review-queue`, {
53+
signal: AbortSignal.timeout(20_000),
54+
});
55+
const capability = (await capabilityResponse.json().catch(() => null)) as Record<
56+
string,
57+
unknown
58+
> | null;
59+
const scheduledFeed = capability?.scheduled_feed as Record<string, unknown> | undefined;
60+
if (
61+
!capabilityResponse.ok ||
62+
!scheduledFeed ||
63+
!Number.isFinite(Number(scheduledFeed.target_rate_per_hour))
64+
) {
65+
throw new Error("exact-review queue does not advertise scheduled feed admission");
66+
}
5067
const ages = (options.plan.selection ?? [])
5168
.map((selection) => Number(selection.ageMs))
5269
.filter((age) => Number.isFinite(age) && age >= 0)
@@ -75,7 +92,6 @@ export async function enqueueScheduledReviewPlan(
7592
};
7693

7794
for (const [index, candidate] of options.plan.candidates.entries()) {
78-
validateCandidate(candidate, options.targetRepo);
7995
const payload = JSON.stringify({
8096
delivery_id: `${options.deliveryPrefix}:${index}:${candidate.number}`,
8197
decision: {
@@ -92,18 +108,15 @@ export async function enqueueScheduledReviewPlan(
92108
});
93109
const signature = `sha256=${createHmac("sha256", options.secret).update(payload).digest("hex")}`;
94110
summary.attempted += 1;
95-
const response = await fetchImpl(
96-
`${options.queueUrl.replace(/\/$/, "")}/internal/exact-review/enqueue`,
97-
{
98-
method: "POST",
99-
headers: {
100-
"content-type": "application/json",
101-
"x-clawsweeper-exact-review-signature": signature,
102-
},
103-
body: payload,
104-
signal: AbortSignal.timeout(20_000),
111+
const response = await fetchImpl(`${queueUrl}/internal/exact-review/enqueue`, {
112+
method: "POST",
113+
headers: {
114+
"content-type": "application/json",
115+
"x-clawsweeper-exact-review-signature": signature,
105116
},
106-
);
117+
body: payload,
118+
signal: AbortSignal.timeout(20_000),
119+
});
107120
const body = (await response.json().catch(() => null)) as Record<string, unknown> | null;
108121
if (!response.ok || !body || body.ok !== true) {
109122
throw new Error(

‎test/repair/scheduled-review-enqueue.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ test("scheduled review enqueue reports the full selection-to-queue funnel and st
2929
secret,
3030
deliveryPrefix: "scheduled:100:1",
3131
fetchImpl: async (_input, init) => {
32+
if (!init?.method) {
33+
return Response.json({ scheduled_feed: { target_rate_per_hour: 200 } });
34+
}
3235
const body = String(init?.body || "");
3336
const headers = (init?.headers ?? {}) as Record<string, string>;
3437
requests.push({
@@ -65,6 +68,22 @@ test("scheduled review enqueue reports the full selection-to-queue funnel and st
6568
assert.equal(second.decision.supersedesInProgress, false);
6669
});
6770

71+
test("scheduled review enqueue fails closed until the queue advertises pacing", async () => {
72+
await assert.rejects(
73+
enqueueScheduledReviewPlan({
74+
plan: { candidates: [] },
75+
lane: "normal_backfill",
76+
targetRepo: "openclaw/openclaw",
77+
targetBranch: "main",
78+
queueUrl: "https://queue.example",
79+
secret: "secret",
80+
deliveryPrefix: "scheduled:100:1",
81+
fetchImpl: async () => Response.json({ lanes: {} }),
82+
}),
83+
/does not advertise scheduled feed admission/,
84+
);
85+
});
86+
6887
test("scheduled review enqueue rejects cross-repository plan candidates", async () => {
6988
await assert.rejects(
7089
enqueueScheduledReviewPlan({

0 commit comments

Comments
 (0)