Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: adversarial review fixes (a refused artifact-storage redirect and a rate-limit 403 known by its headers or abuse-detection wording stay transient)
garrytanc2e2b2a99dd7
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d69ea279cf..b744ecea24 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -26,7 +26,7 @@ identifiers and attribution are available in the pre-removal Git revision### Itemized changes-- `scripts/lib/gh-issue.ts`: `fetchArtifactJson` marks a failed artifact read transient only for no response, a 5xx, a 429 or a 403 whose message names a rate limit (#8370). Both clients' artifact downloads now carry the HTTP status and the response text, so the `gh` CLI client (used when no `GH_TOKEN` is set) classifies the same way, and a rate-limit 403 on the zip stays transient.+- `scripts/lib/gh-issue.ts`: `fetchArtifactJson` marks a failed artifact read transient only for no response, a 5xx, a 429 or a 403 whose message names a rate limit (#8370). Both clients' artifact downloads now carry the HTTP status and the response text, so the `gh` CLI client (used when no `GH_TOKEN` is set) classifies the same way. A rate-limit 403 stays transient whether its headers (`x-ratelimit-remaining: 0`, `retry-after`) or its text (rate limit, abuse detection) say so, and so does a refusal from the artifact storage the download redirects to, since a fresh read mints a new signed URL.- `test/scripts/ci-reuse.test.ts`: a probe checks that 403, 404 and 410 are refusals and that 429, a rate-limit 403, a 502 and no response stay transient, and that a refused receipt ends the gate's wait at once. It fails without the fix.- `.gstack/pregate.json`: `scripts/bench/**`, `docs/eval/system-one/runners/**` and `docs/eval/system-one/generators/**` declare no lane (`[]`), which applies only where no test maps the file, so the VM-setup scripts keep `test/scripts/vm-setup-usage.test.ts` (#7690).- `scripts/postgres-arm-weights.json`: re-mined with `bun scripts/postgres-unit-arms.ts mine` from those eight runs' 98 job logs, unscaled.diff --git a/scripts/lib/gh-issue.ts b/scripts/lib/gh-issue.tsindex d6e38cb2c2..632eca64ea 100644--- a/scripts/lib/gh-issue.ts+++ b/scripts/lib/gh-issue.ts@@ -114,7 +114,9 @@ function tokenClient(resolve: (path: string) => string, token: string): GitHubClconst body = location ? await fetch(location) : res;if (!body.ok) {const text = await body.text().catch(() => '');- throw Object.assign(new Error(`GitHub download ${url} -> ${body.status}: ${text.slice(0, 300)}`), { status: body.status });+ if (location) throw new Error(`GitHub download ${url} -> artifact storage answered ${body.status}: ${text.slice(0, 300)}`);+ const rateLimited = body.headers.get('x-ratelimit-remaining') === '0' || body.headers.has('retry-after');+ throw Object.assign(new Error(`GitHub download ${url} -> ${body.status}: ${text.slice(0, 300)}`), { status: body.status, rateLimited });}return new Uint8Array(await body.arrayBuffer());},@@ -267,7 +269,7 @@ export function readZipEntry(zip: Uint8Array, name: string): Uint8Array | undefireturn 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: no response, a 5xx, a 429 or a rate-limit 403, never another 4xx such as a 403 or an expired artifact's 410. */+/** 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, a rate-limit 403 (by its headers, or its text naming a rate limit or abuse detection) or a refusal from the artifact storage the download redirects to (a fresh read mints a new signed URL), 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)}`;@@ -280,7 +282,8 @@ export async function fetchArtifactJson(client: GitHubClient, runId: number, artzip = await client.download(`repos/{repo}/actions/artifacts/${found.id}/zip`);} catch (e) {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 : ''));+ const rateLimited = status === 403 && ((e as { rateLimited?: boolean }).rateLimited || /rate limit|abuse detection/i.test(e instanceof Error ? e.message : ''));+ const permanent = status >= 400 && status < 500 && status !== 429 && !rateLimited;return permanent ? { reason: failed(e) } : { reason: failed(e), transient: true };}try {diff --git a/test/scripts/ci-reuse.test.ts b/test/scripts/ci-reuse.test.tsindex 30885ebc4c..452126aafc 100644--- a/test/scripts/ci-reuse.test.ts+++ b/test/scripts/ci-reuse.test.ts@@ -483,6 +483,28 @@ describe('ci-reuse remote-gate decision', () => {} finally { rmSync(bin, { recursive: true, force: true }); }});+ test('#8370: a refused blob-storage redirect, a rate-limit 403 known only by its headers, and the abuse-detection wording all stay transient', async () => {+ const r600 = run('test.yml');+ const listing = JSON.stringify({ artifacts: [{ id: 7, name: 'executed-identities', expired: false }] });+ const token = (zip: (url: string) => Response) => {+ const real = globalThis.fetch;+ globalThis.fetch = (async (url: string) => String(url).includes('/actions/runs/') ? new Response(listing, { status: 200 }) : zip(String(url))) as typeof fetch;+ return gateDeps(restClient(REPO, 'token-example', async () => {})).executed(r600).finally(() => { globalThis.fetch = real; });+ };+ const blob = 'https://blob-example.invalid/zip?sig=expired';+ expect(await token(url => url === blob ? new Response('AuthenticationFailed', { status: 403 }) : new Response(null, { status: 302, headers: { location: blob } }))).toMatchObject({ transient: true });+ expect(await token(() => new Response('', { status: 403, headers: { 'x-ratelimit-remaining': '0' } }))).toMatchObject({ transient: true });+ expect(await token(() => new Response('', { status: 403, headers: { 'retry-after': '60' } }))).toMatchObject({ transient: true });+ expect(await token(() => new Response('You have triggered an abuse detection mechanism.', { status: 403 }))).toMatchObject({ transient: true });+ expect(await token(() => new Response('Resource not accessible by integration', { status: 403 }))).not.toHaveProperty('transient');+ expect(await token(() => new Response('Gone', { status: 410 }))).not.toHaveProperty('transient');+ const bin = mkdtempSync(join(tmpdir(), 'ci-reuse-gh-'));+ try {+ writeFileSync(join(bin, 'gh'), `#!/usr/bin/env bash\ncase "$*" in *"/zip"*) echo "gh: You have triggered an abuse detection mechanism. (HTTP 403)" >&2; exit 1;; esac\necho '${listing}'\n`, { mode: 0o755 });+ expect(await withEnv({ PATH: `${bin}:${process.env.PATH}` }, () => gateDeps(restClient(REPO, '', async () => {})).executed(r600))).toMatchObject({ transient: true });+ } finally { rmSync(bin, { recursive: true, force: true }); }+ });+/** 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 });