Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(ci-gate): a permanent 4xx reading a run artifact refuses reuse instead of reading as transient (#8370)

garrytan301b56392857
diff --git a/scripts/lib/gh-issue.ts b/scripts/lib/gh-issue.ts
index 0d980333d7..e4cec6aaab 100644
--- a/scripts/lib/gh-issue.ts
+++ b/scripts/lib/gh-issue.ts
@@ -260,7 +260,7 @@ export function readZipEntry(zip: Uint8Array, name: string): Uint8Array | undefi
return undefined;
}
-/** One JSON file from a run's named artifact; `reason` says why it could not be read (missing, expired, unreadable), and `transient` marks a failed request that a later read may get past. */
+/** One JSON file from a run's named artifact; `reason` says why it could not be read (missing, expired, unreadable), and `transient` marks a failed request that a later read may get past: no response, a 5xx, a 429 or a rate-limit 403, never another 4xx such as a 403 or an expired artifact's 410. */
export async function fetchArtifactJson(client: GitHubClient, runId: number, artifact: string, file: string): Promise<{ value?: unknown; reason?: string; transient?: boolean }> {
if (!client.download) return { reason: 'this client cannot download artifacts' };
const failed = (e: unknown) => `reading run ${runId}'s '${artifact}' artifact failed: ${e instanceof Error ? e.message : String(e)}`;
@@ -272,7 +272,9 @@ export async function fetchArtifactJson(client: GitHubClient, runId: number, art
if (found.expired) return { reason: `run ${runId}'s '${artifact}' artifact has expired` };
zip = await client.download(`repos/{repo}/actions/artifacts/${found.id}/zip`);
} catch (e) {
- return { reason: failed(e), transient: true };
+ const status = (e as { status?: number }).status ?? 0;
+ const permanent = status >= 400 && status < 500 && status !== 429 && !(status === 403 && /rate limit/i.test(e instanceof Error ? e.message : ''));
+ return permanent ? { reason: failed(e) } : { reason: failed(e), transient: true };
}
try {
const bytes = readZipEntry(zip, file);
diff --git a/test/scripts/ci-reuse.test.ts b/test/scripts/ci-reuse.test.ts
index 0740cba86d..c8d397b6f6 100644
--- a/test/scripts/ci-reuse.test.ts
+++ b/test/scripts/ci-reuse.test.ts
@@ -438,6 +438,27 @@ describe('ci-reuse remote-gate decision', () => {
.toEqual({ reason: expect.stringMatching(/^reading run 600's 'executed-identities' artifact failed: /) });
});
+ test('#8370: a permanent 4xx reading the artifact is a refusal; only no response, a 5xx, a 429 or a rate-limit 403 is transient', async () => {
+ const r600 = run('test.yml');
+ const status = (code: number, message = `HTTP ${code}`) => Object.assign(new Error(message), { status: code });
+ const download = (e: Error): GitHubClient => ({ ...identitiesClient(null), download: async () => { throw e; } });
+ const listing = (e: Error): GitHubClient => ({ ...identitiesClient(null), request: async () => { throw e; } });
+ for (const code of [403, 404, 410]) {
+ const got = await gateDeps(download(status(code))).executed(r600);
+ expect(got).toEqual({ reason: `reading run 600's 'executed-identities' artifact failed: HTTP ${code}` });
+ expect(await gateDeps(listing(status(code))).executed(r600)).not.toHaveProperty('transient');
+ }
+ for (const e of [status(429), status(403, 'API rate limit exceeded for installation'), status(502), Object.assign(new Error('no response'), { network: true })]) {
+ expect(await gateDeps(listing(e)).executed(r600)).toMatchObject({ transient: true });
+ }
+ const live = run('e2e.yml', { status: 'in_progress', conclusion: null });
+ const deps = gate({ runs: [run('test.yml'), live], executed: { 600: await gateDeps(download(status(410))).executed(r600) as { reason: string } } });
+ expect(await decideGate(deps, PROFILES.test, A, T, REPO)).toMatchObject({ state: 'rejected' });
+ const g = await go(deps, A, T, 90 * 60_000);
+ expect(g.code).toBe(4);
+ expect(g.lines.some(l => l.includes('waiting for'))).toBe(false);
+ });
+
/** A run's receipts as scripts/lib/test-env.sh writes them: one artifact directory per job, one test file each. */
function writeReceipts(dir: string, artifact: string, lane: string, attempt: number, tests: string[]) {
const at = join(dir, artifact); mkdirSync(at, { recursive: true });