mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-27 18:34:05 +01:00
fix: a Codex usage limit is quota_exhausted, a plain 429 is rate_limited, and only Codex's own error lines count (#3051 rework)
The probe's quota signature used to treat any rate limit, "too many requests" or 429 as quota, and read the whole output, which echoes the prompt. Now only Codex's trailing ERROR: / stream error lines are read. A usage-limit or insufficient_quota line is MODEL_QUOTA_EXHAUSTED (exit 4, cached 15 minutes; quota wins over a 429 that names insufficient_quota); a plain 429 is MODEL_PROBE_RATE_LIMITED (exit 0, state rate_limited, never cached), reported as CODEX_MODE: unverified (rate_limited) so the review still runs and decides. The quota HINT says how many minutes gstack skips Codex and how to retry now (GSTACK_CODEX_PROBE_RETRY=1 skips the negative cache for that probe, or delete <state root>/.codex-model-probe), with the full troubleshooting URL. classifyOutsideReview reads the same trailing lines: a mid-review quota is unavailable (quota_exhausted), a mid-review 429 unavailable (rate_limited). New gate row rate_limited and docs anchor codex-rate-limited; the quota row documents the retry. Tests cover each line shape, the echoed prompt, exit 0, timeout, retry recovery, probe/classifier parity, and two fresh-shell preflight blocks where the second makes no paid Codex call. Co-authored-by: venkatareddyg <venkatareddyg@users.noreply.github.com>
This commit is contained in:
1 parent
5884117c02
commit
3542322819
17 files changed
+314
-71
No files matched your search
@@ -65,8 +65,13 @@ export const GATE_OUTCOMES = {
|
||||
},
|
||||
quota_exhausted: {
|
||||
state: 'unavailable', anchor: 'codex-quota-exhausted',
|
||||
summary: "Codex refused the call for this account's usage or rate limit",
|
||||
fix: "wait for the reset time in Codex's message above, or add credits or a higher plan for that account; the model choice is fine",
|
||||
summary: "Codex refused the call for this account's usage limit",
|
||||
fix: "wait for the reset time in Codex's message above, or add credits or a higher plan for that account; the model choice is fine. To re-check before gstack's 15-minute cache expires, set GSTACK_CODEX_PROBE_RETRY=1 (https://github.com/garrytan/gstack/blob/main/docs/troubleshooting.md#codex-quota-exhausted)",
|
||||
},
|
||||
rate_limited: {
|
||||
state: 'unavailable', anchor: 'codex-rate-limited',
|
||||
summary: 'Codex rate-limited the review (HTTP 429), so it did not complete',
|
||||
fix: 're-run the review in a minute; if 429s persist, check the account rate limits on the provider dashboard (https://github.com/garrytan/gstack/blob/main/docs/troubleshooting.md#codex-rate-limited)',
|
||||
},
|
||||
helper_unavailable: {
|
||||
state: 'unavailable', anchor: 'sourced-helper-location',
|
||||
|
||||
@@ -44,11 +44,23 @@ const SANDBOX_FAILURE = /^\s*bwrap: \S.*$|^.*\bbubblewrap is unavailable\b.*$|^.
|
||||
/** Exact phrases a reviewer uses when it could not execute; the last fallback, used only without positive evidence. */
|
||||
const EXECUTION_FAILURE_PHRASE = /\b(?:commands? (?:could not|couldn't|cannot|can't) (?:be )?run|(?:could not|couldn't|was unable to|am unable to|unable to) (?:run (?:any )?(?:shell )?commands|execute (?:any )?commands|inspect the diff|read the diff|access the diff)|the diff could not be (?:read|inspected|accessed)|every (?:shell )?(?:command|invocation) failed)\b/i;
|
||||
/**
|
||||
* An account usage or rate limit (#3051). Codex states it plainly ("You've hit
|
||||
* your usage limit ... try again at <time>"); the line carries the reset time,
|
||||
* so it is relayed verbatim. Mirrors _QUOTA_SIG in bin/gstack-codex-probe.
|
||||
* Codex's own trailing error lines (`ERROR: ...`, `stream error: ...`), never
|
||||
* the whole stderr: it echoes the session prompt, which may quote any of the
|
||||
* phrases below. Mirrors the awk filter in bin/gstack-codex-probe.
|
||||
*/
|
||||
export const QUOTA_FAILURE = /^.*(?:usage limit|rate limit|rate_limit_exceeded|insufficient_quota|exceeded your current quota|too many requests|"status":\s*429|status:?\s*429).*$/im;
|
||||
const CODEX_ERROR_LINE = /^\s*(?:\[[^\]]*\]\s*)?(?:ERROR:|stream error)/;
|
||||
function codexErrorLines(stderr: string): string[] {
|
||||
let block: string[] = [];
|
||||
for (const line of stderr.split(/\r?\n/)) {
|
||||
if (CODEX_ERROR_LINE.test(line)) block.push(line.trim());
|
||||
else if (line.trim()) block = [];
|
||||
}
|
||||
return block;
|
||||
}
|
||||
/** The account's usage limit: Codex's line carries the reset time, so it is relayed verbatim. Same signature as the probe. */
|
||||
export const QUOTA_FAILURE = /usage limit|insufficient_quota|exceeded your current quota|quota exceeded/i;
|
||||
/** A plain HTTP 429 or rate limit: transient, so a separate reason from the quota. */
|
||||
export const RATE_LIMIT_FAILURE = /rate.?limit|too many requests|(?:^|[^0-9])429(?:[^0-9]|$)/i;
|
||||
/** `codex review` transcript on stderr: a command that ran prints " succeeded in Nms:". */
|
||||
const TRANSCRIPT_SUCCESS = /^\s*succeeded in \d+(?:\.\d+)?m?s:?\s*$/m;
|
||||
|
||||
@@ -78,8 +90,11 @@ function execution(input: OutsideReviewInput): OutsideReviewClassification['exec
|
||||
if (exit !== 0) {
|
||||
const detail = sandbox(stderr);
|
||||
if (detail) return { state: 'unavailable', reason: 'sandbox_unavailable', detail };
|
||||
const quota = exit !== 124 ? stderr.match(QUOTA_FAILURE)?.[0].trim().slice(0, 240) : undefined;
|
||||
if (quota) return { state: 'unavailable', reason: 'quota_exhausted', detail: quota };
|
||||
const errors = exit !== 124 ? codexErrorLines(stderr) : [];
|
||||
const quota = errors.find(line => QUOTA_FAILURE.test(line));
|
||||
if (quota) return { state: 'unavailable', reason: 'quota_exhausted', detail: quota.slice(0, 240) };
|
||||
const rateLimit = errors.find(line => RATE_LIMIT_FAILURE.test(line));
|
||||
if (rateLimit) return { state: 'unavailable', reason: 'rate_limited', detail: rateLimit.slice(0, 240) };
|
||||
const head = stderrHead(stderr);
|
||||
return { state: 'unavailable', reason: exit === 124 ? 'timeout' : 'execution_failed', detail: head ? `exit ${exit}: ${head}` : `exit ${exit}` };
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user