diff --git a/script/agent.agy-review.test.ts b/script/agent.agy-review.test.ts index 3bee8ea..00a63ed 100644 --- a/script/agent.agy-review.test.ts +++ b/script/agent.agy-review.test.ts @@ -345,6 +345,31 @@ describe("runLocal pipeline (stub agy)", () => { expect(result.classification).toBe("auth-required"); }); + it("quota-exhausted when agy reports RESOURCE_EXHAUSTED", async () => { + const stub = makeStub( + "quota.sh", + `cat >&2 <<'EOF' +error: Individual quota reached. Please upgrade your subscription to increase your limits. Resets in 2h37m14s. +AGY_ERROR: {"short_error":"RESOURCE_EXHAUSTED (code 429): Individual quota reached. Please upgrade your subscription"} +EOF +exit 3` + ); + const result = await runAgyReview({ ...base(), agyBin: stub }); + expect(result.classification).toBe("quota-exhausted"); + }); + + it("quota-exhausted wins over auth heuristic on mixed stderr", async () => { + const stub = makeStub( + "quotaauth.sh", + `cat >&2 <<'EOF' +RESOURCE_EXHAUSTED (code 429): quota reached; request unauthorized for this window +EOF +exit 3` + ); + const result = await runAgyReview({ ...base(), agyBin: stub }); + expect(result.classification).toBe("quota-exhausted"); + }); + it("protected path mutation is detected via git status", async () => { const repo = join(tmp, "repo"); mkdirSync(repo, { recursive: true }); diff --git a/script/agent/agy-review.ts b/script/agent/agy-review.ts index 06f1991..42861a2 100644 --- a/script/agent/agy-review.ts +++ b/script/agent/agy-review.ts @@ -711,6 +711,14 @@ function classify( if (run.code !== 0) { result.classification = "agy-error"; reasons.push(`agy exited ${run.code}: ${run.stderr.slice(0, 300)}`); + // Check quota exhaustion before auth: agy's 429 payload can contain + // tokens (e.g. "unauthorized") that would otherwise misfire the auth + // heuristic observed in Issue #226 eval runs. + if (/resource_exhausted|quota reached|individual quota|rate.?limit|too many requests|\b429\b/i.test(run.stderr + run.stdout)) { + result.classification = "quota-exhausted"; + reasons.push("agy reported quota exhaustion"); + return; + } const auth = /sign in|oauth|unauthorized|401|403/i.test(run.stderr + run.stdout); if (auth) { result.classification = "auth-required";