Skip to content

fix(review): retry Codex model-capacity failures as provider throttling - #1969

Merged
steipete merged 3 commits into
mainfrom
fix/codex-model-capacity-retry
Oct 13, 2026
Merged

steipete merged 3 commits into
mainfrom
fix/codex-model-capacity-retry

Conversation

@steipete

@steipete steipete commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Reviews that fail because the model provider is temporarily out of capacity are recorded as permanent failures instead of being retried.

On 2026-10-13 between 12:00 and 14:00 UTC, failed exact reviews spiked to 11 and 10 per hour. In the five failure diagnostics I sampled, four carried the same provider error, across openclaw-enterprise, acpx and wacli:

Codex final output did not end with its newline frame.
ERROR: Selected model is at capacity. Please try a different model.

Their diagnostics manifests all read "classification": "codex_execution", "retryable": false, "reason_code": "unknown" (for example https://github.com/openclaw/clawsweeper/actions/runs/38409514528). The capacity matchers only knew rate-limit, TPM, 429, "temporarily unavailable", "overloaded" and "please try again in …" wording, so this message fell through to codex execution failed.

Change

  • src/codex-transient.ts defines the provider capacity pattern once (CODEX_PROVIDER_CAPACITY_ERROR) and adds the full provider diagnostic selected model is at capacity. A bare at capacity would be unsafe: failed-review retry eligibility scans report text that includes the item title, so an item titled "Service is at capacity" with a permanent failure would become retryable (ClawSweeper's P2 finding on the first head, also raised in fix(review): retry Codex model-capacity failures as provider throttling #1969 (comment)). isRetryableCodexTransportError uses it, so the error is retryable for CodexReviewError.retryable, record retry eligibility, and runCodex's in-process capacity retries.
  • failedReviewFailureDetail in src/clawsweeper-record-metadata.ts no longer scans the item title. Its raw-text fallback (first 8,000 report characters) drops the title and fixed_pr_title front-matter lines and the # [#N: title](url) heading, so contributor-written titles cannot make a permanent failure look like a retryable provider error. This resolves ClawSweeper's second P2 (fix(review): retry Codex model-capacity failures as provider throttling #1969 (comment)): even the full diagnostic used as a title was matched. Failure evidence such as review_failure_reason, the decision summary and the Summary/Evidence sections is still scanned.
  • codexFailureReason in src/clawsweeper-review-runtime.ts reuses the same pattern instead of its own inline copy, so the failure log kind is provider_throttle. The inline copy also picks up the decimal please try again in 1.5s form the shared list already had.
  • Terminal model-access detection ("The model X does not exist or you do not have access to it") is unchanged and still wins over transient matches.

Behavior proof

  • Claim: a review that failed with the provider's model-capacity diagnostic is retried through the durable failed-review retry boundary, while an unrelated permanent failure on an item whose title says "at capacity" is not.
  • Surface: the shipped CLI, node dist/clawsweeper.js retry-failed-reviews --target-repo openclaw/openclaw --items-dir <tmp> --item-number 4242 --max-attempts 2 --cooldown-minutes 45, with a mock gh (GH_BIN) that answers the item, PR head and workflow default-branch reads and records the repos/openclaw/clawsweeper/dispatches POST. The proof script lives under the ignored .artifacts/ directory.
  • Scenarios: (1) a failed PR report exactly as main recorded failures on 2026-10-13: summary Codex review failed: codex execution failed., detail containing ERROR: Selected model is at capacity. Please try a different model.; (2) the title trap: title Selected model is at capacity in both front matter and heading, permanent Codex execution failed.
Build Scenario Action Dispatch
main (44696e44b3) capacity as recorded skipped_non_infrastructure_failure none
this branch (878d26ca) capacity as recorded dispatched_failed_review_retry (retryable codex transport failure (capacity)) sent
main title trap skipped_non_infrastructure_failure none
previous head 9850d3ba title trap dispatched_failed_review_retry sent (the reported false positive)
this branch (878d26ca) title trap skipped_non_infrastructure_failure none

The real runCodex path is covered too: test/codex-review-runner.test.ts drives a fake codex binary that fails with the production text; it is handed to the durable queue as a retryable capacity failure with this change and not on main.

  • Limits: the mock gh stands in for GitHub; no live provider capacity event was triggered. The durable queue's backoff for retryable provider failures is unchanged.

Validation

  • test/repair/codex-transient.test.ts: the production text is retryable, not terminal, and not a context-limit error. Negative cases keep ClawSweeper's own "required filesystem capacity is unavailable" error and a bare "Service is at capacity" non-retryable at the matcher level.
  • test/failed-review-retry.test.ts: report-level regression. The provider diagnostic yields planned_failed_review_retry; titles Selected model is at capacity and Service is at capacity in front matter and heading, with a permanent failure, yield skipped_non_infrastructure_failure.
  • test/codex-review-runner.test.ts: the same text is classified provider_throttle, plus the runner row above. The new provider-diagnostic cases fail on main's source and pass here; the three suites total 94/94.
  • pnpm run check:static, pnpm run lint, build:all and git diff --check pass.
  • Codex /review (autoreview, P0–P2) is clean on the original change, the committed branch, the narrowed matcher, and the title exclusion.

OpenClaw Bay

Not affected. The failure taxonomy already includes provider_throttle; no status, lifecycle or projection contract changes.

OpenAI's 'Selected model is at capacity. Please try a different model.' matched none of the capacity patterns, so those reviews were recorded as non-retryable codex_execution failures with an unknown reason (4 of 5 sampled failures in the 2026-10-13 12:00-14:00 UTC spike). Define the provider capacity pattern once, add 'at capacity', and use it for both the retryable decision and the provider_throttle classification.
@clawsweeper

clawsweeper Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Current proof and validation for head 14c8cd4 are in the PR body.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T18:04:59.417402Z 878d26c New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper

clawsweeper Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 14c8cd4800

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/codex-transient.ts Outdated

// Provider rate limits and capacity errors, including "Selected model is at capacity".
export const CODEX_PROVIDER_CAPACITY_ERROR =
/rate limit reached|tokens per min|\bTPM\b|requests per min|\b429\b|temporarily unavailable|overloaded|\bat capacity\b|please try again in \d+(?:\.\d+)?(?:ms|s)/i;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Match the complete model-capacity diagnostic

When an item's title or other early report text contains a phrase such as "service is at capacity" and its review fails for an unrelated non-retryable reason, this bare at capacity alternative makes isInfrastructureFailedReview() treat the record as retryable because failedReviewFailureDetail() scans the first 8,000 bytes of the report, including user-controlled front matter. This can repeatedly requeue permanent failures; constrain the matcher to the provider diagnostic (for example, selected model is at capacity) rather than the generic fragment.

Useful? React with 👍 / 👎.

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The previous explicit request completed a review in https://github.com/openclaw/clawsweeper/actions/runs/38431373647 (rev 2), but a source_drift_requeue (rev 3, https://github.com/openclaw/clawsweeper/actions/runs/38431867802) superseded it as an automatic review and skipped this maintainer PR, so no review was published. Current proof for head 14c8cd4 is in the PR body.

@clawsweeper

clawsweeper Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 13, 2026
@clawsweeper

clawsweeper Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR classifies Codex model-capacity failures as retryable provider throttling while excluding item titles from failed-review retry classification.

Example: A failed review contains “ERROR: Selected model is at capacity. Please try a different model.”

  • Before: The failure is classified as non-retryable codex execution failure.
  • After: The failure is classified as provider throttling and becomes eligible for the existing bounded retry policy.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch is correct by source inspection and resolves both prior findings; supplied behavior evidence remains limited by mocked external boundaries.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its current-head CLI results exercise capacity and title-trap classification with mocked GitHub, while runner coverage uses a fake Codex executable.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Reviews that encounter temporary model capacity exhaustion can remain failed instead of receiving the existing recovery retries.
Reason: The maintainer-authored direction addresses a concrete operational failure with a narrow change and resolves the previously identified false-positive cases.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: current main still misses the provider diagnostic, both prior findings are resolved, and no new actionable defect was found.

Priority: P2
Reviewed head: 878d26cafb3a825e30e8f423288c45509574056e

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied CLI scenario mocks GitHub and the runner test substitutes Codex, so live provider-to-queue recovery is not demonstrated.
Agent review details

How this fits together

Codex diagnostics and stored failed-review reports enter shared failure classification, which supplies retry eligibility and failure taxonomy to the review runner and durable retry command.

flowchart TD
  A[Codex failure diagnostic] --> B[Shared transient matcher]
  B --> C[Review failure classification]
  D[Stored failed review] --> E[Failure text without titles]
  E --> B
  B --> F[Retry eligibility gates]
  F --> G[Bounded retry dispatch]
Loading

Technical review

Best possible solution:

Use the shared provider-diagnostic matcher with title exclusion and preserve the existing terminal-denial and bounded-retry safeguards.

Do we have a high-confidence way to reproduce the issue?

Current-main source excludes the reported provider diagnostic from both retry matching and capacity classification; the PR supplies corresponding runner and report regressions, but this review did not execute them.

Is this the best way to solve the issue?

The focused shared matcher and title exclusion address the observed classification failure without adding a competing retry owner or changing retry budgets.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 44696e44b329.

Provenance checked

  • Shared Codex transient matching keeps the original intent (3dec224: The creation diff introduced shared transport-error matching and retry-delay calculation for transient Codex reviews.)
  • Runtime failure classification and diagnostic trust keeps the original intent (fix(review): require opt-in for retained local output #1488: The earlier change retained bounded positive retry hints while keeping authoritative terminal denial separate from captured output.)
  • Failed-report fallback text changes intended behavior with a stated reason (unknown: The broad fallback was carried through the report-reader extraction and typed-reader migration; its original inclusion of titles was not explained by that history, and searching the earlier monolithic source encountered an unavailable historical blob. The current PR explains why titles must be excluded.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 64ea2d8 adds src/codex-transient.ts:12 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 64ea2d8564e6; files: src/codex-transient.ts)
  • Vincent Koc: Raw commit 0940b82 adds src/codex-transient.ts:76 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 0940b82e3c3a; files: src/codex-transient.ts)
  • Ayaan Zaidi: Raw commit c19101a adds src/clawsweeper-record-metadata.ts:517 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c19101a4e1ac; files: src/clawsweeper-record-metadata.ts)

Review metrics

Metric Value Why it matters
Introduced change size Production +19/-8; tests +71/-4; changelog +1 The small production change shares classification and removes title contamination; the test growth covers the observed failure and both prior regressions.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove merge-risk: 🚨 automation: Current PR review selected no merge-risk labels.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: The change restores recovery for a specific temporary provider failure without changing retry limits or the review policy.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-13T17:40:44.983Z sha 14c8cd4 :: needs changes before merge. :: [P2] Constrain capacity matching to the provider diagnostic
  • reviewed 2026-10-13T17:55:24.649Z sha 9850d3b :: needs changes before merge. :: [P2] Exclude item metadata from capacity retry classification

Reviewed October 13, 2026, 2:16 PM ET / 18:16 UTC (Revision 3).

Failed-review retry eligibility scans report text that includes the item title, so a bare 'at capacity' would make a permanent failure on an item titled, for example, 'Service is at capacity' retryable. Match the full 'selected model is at capacity' diagnostic and add report-level coverage for both the real diagnostic and the title trap.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9850d3ba89

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/codex-transient.ts
Comment on lines +8 to +9
export const CODEX_PROVIDER_CAPACITY_ERROR =
/rate limit reached|tokens per min|\bTPM\b|requests per min|\b429\b|temporarily unavailable|overloaded|selected model is at capacity|please try again in \d+(?:\.\d+)?(?:ms|s)/i;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restrict capacity matches to trusted failure evidence

When an issue or PR is titled exactly "Selected model is at capacity" and its review fails for an unrelated permanent reason, this pattern still makes the failure retryable because failedReviewFailureDetail() passes the report's first 8,000 bytes—including the user-controlled title—to isRetryableCodexTransportError(). Fresh evidence after the prior comment is that the new negative test covers only the shorter title "Service is at capacity", so it does not exercise the full diagnostic now accepted here. Match this diagnostic only in trusted Codex failure fields rather than report-wide text, otherwise such items consume durable retry attempts despite having no provider failure.

Useful? React with 👍 / 👎.

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Resolved the P2 finding: the matcher now requires the full provider diagnostic selected model is at capacity, with a report-level title-trap regression and a shipped-CLI proof in the PR body for head 9850d3b.

@clawsweeper

clawsweeper Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Oct 13, 2026
failedReviewFailureDetail scanned the first 8,000 report characters, including the contributor-written title front matter and heading, so an item titled with a provider diagnostic made a permanent failure look retryable. Drop the title and fixed_pr_title front-matter lines and the title heading from that raw-text fallback; failure evidence fields are unchanged.
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Resolved the second P2: failed-review retry classification no longer scans the item title (front-matter title/fixed_pr_title and the title heading), with a regression for the full-diagnostic title and a shipped-CLI proof in the PR body for head 878d26c.

@clawsweeper

clawsweeper Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 13, 2026
@steipete
steipete merged commit a24d8c1 into main Oct 13, 2026
30 of 31 checks passed
@steipete
steipete deleted the fix/codex-model-capacity-retry branch October 13, 2026 18:21
steipete added a commit that referenced this pull request Oct 14, 2026
… requeues (#1981)

An explicit `@clawsweeper re-review` on a maintainer-authored PR was silently lost when the PR changed while the review ran (on #1969 and again on this PR, another bot's PR review moved the review-activity cursor). Apply skipped publication for source drift, the queue requeued the generation in place as `source_drift_requeue`, and claim admission skipped that retry as an automatic maintainer review, leaving the command status at "Review in progress" and its review lease held for about an hour.

- `isExplicitReviewRequest` now accepts a `source_drift_requeue` that still carries the request's command status and verified command fields, so the queue's fenced in-place requeue continues the same request through claim admission and the hosted publication gate.
- The queue keeps request verification on a `source_drift_requeue` only when it requeued the generation in place (`direct-lifecycle-requeue:` admission provenance). The rule runs in the load-time normalizer and on `/enqueue`, so a finished or replaced request re-enqueued by a publisher, including rows persisted by the previous release, keeps its status but cannot authorize another review. `/enqueue` rejects caller delivery ids that use the queue-owned prefix (`reserved_delivery_id`).
- AGENTS.md, docs/scheduler.md, README, and a changelog fragment state the contract; deferred publications (batch publisher requeues) still need a new request and are tracked in the stacked #1984.

Proof: replay of #1969's real rev 2/rev 3 claim decisions through the compiled `live-item` admission step, real queue Durable Object lifetime and upgrade tests, final effects through the real apply owner on an owner-authored oversized PR (continuation writes; finished-request requeue zero writes), and a cross-version run where main persists an orphaned verified requeue and this change claims those bytes as non-explicit.
steipete added a commit that referenced this pull request Oct 14, 2026
…mission (#2001)

On a maintainer-authored item, a review generation that still carries an explicit command but lacks request authority (for example a fail-closed source_drift_requeue whose verification the queue stripped) is skipped at claim admission. The skip path never created the review job's write token, so "Mark unsuccessful re-review" never ran and the command status stayed "Review in progress" forever, as on #1969; no terminal-finalization driver answers a review generation's policy_noop either.

- "Create target write token" now also runs for exactly that case (semantic no-op, maintainer_request_required hold, command context). Every other token consumer stays gated on the review proceeding or on items without command context.
- "Mark unsuccessful re-review" answers that case as "Waiting" with a request to re-review. Waiting is deliberately non-terminal, so a later continuation of the same request (#1989's handoff) is not refused.
- Both existing queue fences stay: the step's lease heartbeat and the status CLI's authority fence before lookup and before write.

Proof: the real step script, heartbeat builder, and update-command-status CLI against a controlled queue and recording gh. A current owner writes Waiting; a superseded step fence, an owner lost before or during comment lookup, and a queue error all make zero status writes. Docs (scheduler maintainer contract) and a changelog fragment updated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant