Repository navigation
feat: Add LLM retry mechanism with exponential backoff - #38640
fanzhidongyzby wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7906c394e8
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Greptile SummaryThis PR adds an exponential-backoff retry wrapper ( Issue found: The message-pattern regex in Confidence Score: 2/5
Last reviewed commit: 7906c39 |
There was a problem hiding this comment.
Pull request overview
Adds a framework-level retry/backoff wrapper for embedded Pi agent LLM calls to mitigate transient provider failures (notably HTTP 429 quota/rate limits) during concurrent subagent execution.
Changes:
- Introduces
withLlmRetry()helper using sharedretryAsync()exponential backoff logic. - Wraps
activeSession.prompt()in the embedded runner attempt loop with the retry handler. - Adds retryability heuristics (HTTP 429/5xx, some network/timeout signals) and
Retry-Afterextraction.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| src/agents/pi-embedded-runner/run/attempt.ts | Wraps the embedded session prompt() method with retry/backoff before prompting the model. |
| src/agents/pi-embedded-runner/llm-retry.ts | New retry helper: retryable-error classification, retry-after parsing, and retryAsync wiring. |
You can also share your feedback on Copilot code review. Take the survey.
- Add llm-retry.ts with 7-retry exponential backoff (1-32s) - Wrap prompt() method in attempt.ts with retry logic - Support HTTP 429/500/502/503/504 auto-retry - Extract Retry-After delay from headers and error messages - Configurable attempts, delays, and jitter
…fety - Add comprehensive unit tests for isRetryableLlmError() covering 429, 5xx, network errors - Add comprehensive unit tests for extractRetryAfterMs() covering ms/s parsing, statusCode formats - Fix regular expressions to support: - DEADLINE_EXCEEDED (underscore variant) - Whitespace in retry/reset patterns - Use type-safe wrapper for prompt method in attempt.ts (typeof activeSession.prompt) - All tests passing (31/31) Fixes review comments for PR openclaw#38640
2b06ec4 to
bb24a1a
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bb24a1a943
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
- Fix P1: Make unit capture optional in regex to handle messages without explicit units (defaults to seconds) - Fix P2: Reorder error checks - check status codes first, then only check timeout/message when not 4xx - Fix P2: Add comprehensive JSDoc comments for isRetryableLlmError and extractRetryAfterMs - Fix P2: Simplify type-safe prompt wrapper using Parameters<> and typeof
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a6951d27e7
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
This pull request has been automatically marked as stale due to inactivity. |
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close as superseded: the remaining LLM retry feature is already tracked by #49376 and the active provider-level retry PR #61443, while this branch retries at the prompt wrapper in a way that conflicts with current failover/auth-profile rotation and still has concrete correctness issues. So I’m closing this here and keeping the remaining discussion on the canonical linked item. Review detailsBest possible solution: Keep #49376/#61443 as the canonical path for configurable provider-call retry, and fold any useful retry-after parsing coverage into that design without adding a prompt-level wrapper that delays auth-profile rotation or model fallback. Do we have a high-confidence way to reproduce the issue? Yes for the proposed patch defects: static review shows the PR passes a signal that the retry primitive cannot honor, compares status values without string normalization, and retries same-session prompt failures before the current failover path can rotate profiles or models. Is this the best way to solve the issue? No, this is not the best way to solve the issue as-is. The retry policy should be coordinated with the existing provider/failover classifier and configurable retry surface being tracked in #49376/#61443. Security review: Security review cleared: The diff adds no dependencies, workflows, package scripts, lockfile changes, secret handling, or permission changes; the extra-call behavior is a functional retry/failover concern rather than a concrete supply-chain issue. What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 757af70bf7ca. |
Changes
llm-retry.tsimplementing exponential backoff retry logicprompt()method inattempt.tswith retry handlerMotivation
The API quota limit (HTTP 429) is triggered when the Subagent concurrently calls LLM. OpenClaw's pi-ai provider has no built-in retry and needs to be implemented at the framework layer.