ci: retry issue triage when the model is rate limited (#157)

* ci: retry issue triage when the model is rate limited

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ci: suggest the upstream tracker only for complete bug reports

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ci: fix the triage comment test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
千川白浪andClaude Opus 5.5 authored and GitHub committed 2026-12-04 00:20:27 +08:00
1 parent ddd9be14c7
commit 94a7d4f5b7
3 files changed
+31 -7

No files matched your search

+19 -3
View File
@@ -52,12 +52,17 @@ test("the comment guides the reporter with fixed text only", async () => {
assert.equal(result.status, "commented");
assert.match(result.body, /请补充以下信息\*\*\n\n- Reims-Go、运行时和 macOS 的版本\n\n/);
assert.match(result.body, /疑似重复[^\n]*\n\n- #3\n/);
assert.match(result.body, /路线图中\*\*\n\n- #75\n/);
assert.match(result.body, /steelbrain\/reims-vgpu/);
assert.doesNotMatch(result.body, /INJECTED|everyone|#999/);
assert.match(result.body, /路线图中\*\*\n\n- #75$/);
assert.doesNotMatch(result.body, /INJECTED|everyone|#999|steelbrain/);
assert.deepEqual(writes.map(([method, route]) => method + " " + route), ["POST /issues/10/comments", "POST /issues/10/labels"]);
});
test("only complete bug reports are pointed to the upstream engine", async () => {
const run = (missing) => triageIssue(10, { ...fakeGitHub(issue()), publish: false, ask: async () => ({ kind: "bug", missing, target: "engine" }) });
assert.match((await run([])).body, /steelbrain\/reims-vgpu/);
assert.doesNotMatch((await run(["logs"])).body, /steelbrain/);
});
test("feature requests that fit a plugin are pointed to the plugin documentation", async () => {
const target = issue({ title: "[Feature]: new theme", body: "Please add a theme" });
const result = await triageIssue(10, { ...fakeGitHub(target), publish: false, ask: async () => ({ kind: "feature", target: "plugin" }) });
@@ -146,3 +151,14 @@ test("diagnosis history covers every page of bot issues", async () => {
};
assert.equal((await previousDiagnoses(github)).length, 130);
});
test("rate-limited model requests are retried before failing", async () => {
const env = { PR_REVIEW_LLM_KEY: "key", PR_REVIEW_LLM_BASE_URL: "https://example.com/api/anthropic", PR_REVIEW_LLM_MODEL: "glm-5.4" };
const waits = [];
const wait = async (ms) => waits.push(ms);
const replies = [{ ok: false, status: 429 }, { ok: false, status: 503 }, { ok: true, status: 200, json: async () => ({ content: [{ type: "text", text: "{}" }] }) }];
assert.deepEqual(await askModel("rules", {}, { env, wait, request: async () => replies.shift() }), {});
assert.deepEqual(waits, [20_000, 40_000]);
await assert.rejects(askModel("rules", {}, { env, wait, request: async () => ({ ok: false, status: 429 }) }), /HTTP 429/);
await assert.rejects(askModel("rules", {}, { env, wait: () => assert.fail("retried"), request: async () => ({ ok: false, status: 401 }) }), /HTTP 401/);
});
+11 -3
View File
@@ -87,11 +87,11 @@ export function issueLanguage({ title, body }) {
return /[㐀-鿿]/.test(prose + String(title ?? "")) ? "zh" : "en";
}
export async function askModel(system, data, { env = process.env, request = fetch } = {}) {
export async function askModel(system, data, { env = process.env, request = fetch, wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) } = {}) {
const protocol = env.PR_REVIEW_LLM_PROTOCOL?.trim() || "anthropic";
if (protocol !== "anthropic") throw new Error("Issue automation supports only the anthropic protocol");
const key = required("PR_REVIEW_LLM_KEY", env);
const response = await request(normalizeLLMBaseURL(required("PR_REVIEW_LLM_BASE_URL", env), protocol), {
const send = () => request(normalizeLLMBaseURL(required("PR_REVIEW_LLM_BASE_URL", env), protocol), {
method: "POST",
headers: { Authorization: "Bearer " + key, "x-api-key": key, "anthropic-version": "2023-06-01", "Content-Type": "application/json" },
body: JSON.stringify({
@@ -101,6 +101,13 @@ export async function askModel(system, data, { env = process.env, request = fetc
redirect: "error",
signal: AbortSignal.timeout(120_000),
});
let response = await send();
// The plan's rate limit is shared with PR reviews, so wait for running requests to finish.
for (const seconds of [20, 40, 80, 160]) {
if (response.status !== 429 && !(response.status >= 500)) break;
await wait(seconds * 1000);
response = await send();
}
if (!response.ok) throw new Error("The model returned HTTP " + response.status);
const reply = await response.json();
const text = (Array.isArray(reply.content) ? reply.content : []).filter((part) => part.type === "text").map((part) => part.text).join("");
@@ -138,7 +145,8 @@ export function triageComment(triage, language) {
if (triage.missing.length) section(text.missing, triage.missing.map((field) => "- " + text.fields[field]).join("\n"));
if (duplicates.length) section(text.duplicates, links(duplicates));
if (planned.length) section(text.planned, links(planned));
if (triage.target === "engine") section(text.target, triage.feature ? text.engineFeature : text.engineBug);
// Without enough details, a guess would send reporters to the upstream tracker for nothing.
if (triage.target === "engine" && (triage.feature || !triage.missing.length)) section(text.target, triage.feature ? text.engineFeature : text.engineBug);
if (triage.target === "plugin" && triage.feature) section(text.target, text.plugin);
return sections.length ? [MARKER, text.intro, ...sections].join("\n\n") : null;
}