Repository navigation
feat(acp): add backend provider failover for UNAVAILABLE errors - #69542
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5fc5ea1971
ℹ️ 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".
Greptile SummaryThis PR adds ACP backend failover support: a new
Confidence Score: 3/5Not safe to merge as-is — the primary advertised behavior (aggregated summary error on full backend exhaustion) is broken and never fires. There is a P1 logic bug: the 'All ACP backends failed' summary error is unreachable due to control-flow structure, meaning the feature's core failure-reporting semantics don't work. The failover itself partially works (intermediate backends are tried), but the final error surfaced to callers is the raw last-backend error rather than the intended multi-backend summary. The config plumbing (types, schema, help, labels) is fine. src/acp/control-plane/manager.core.ts — specifically the terminal catch path and the post-loop summary block in runTurn. Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/acp/control-plane/manager.core.ts
Line: 1039-1071
Comment:
**Summary error block is unreachable — aggregated "All ACP backends failed" message is never thrown**
The summary block (lines 1040–1071) can never execute. For the last backend, `isFailoverCandidate` is always `false` because `backendIdx < candidateBackends.length - 1` evaluates to `false`. So the last backend always takes the terminal path inside the catch block: it records stats, marks the task, sets state to `"error"`, and **throws `acpError`** directly at line 983. That throw propagates past the outer `for` loop, making this block permanently unreachable.
Concretely, with backends `[A, B]`:
1. A fails with "unavailable" → `break` inner loop, push to `backendAttempts`
2. B (last) fails → `isFailoverCandidate = false` → terminal path → `throw acpError`
3. The throw skips the summary block entirely
The intended "All ACP backends failed (N): A: err | B: err" message is **never surfaced**. Users only see B's raw error with no indication that A was also tried.
A minimal fix is to build the summary inside the terminal path when previous attempts exist:
```typescript
// In the terminal path (after line 961), before `throw acpError`:
const errorToThrow =
backendAttempts.length > 0
? new AcpRuntimeError(
acpError.code,
`All ACP backends failed (${backendAttempts.length + 1}): ${backendAttempts.map((a) => `${a.backend}: ${a.error}`).join(" | ")} | ${currentBackend}: ${acpError.message}`,
)
: acpError;
throw errorToThrow;
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/acp/control-plane/manager.core.ts
Line: 1030-1036
Comment:
**Dead code — these lines are never reached**
The `continue` and `break` after the try-catch-finally block are unreachable. Inside the catch block, execution always exits via one of:
- `continue` (line 929, when `retryFreshHandle` is true) — jumps directly to the next inner loop iteration
- `break` (line 952, when `shouldFailover` is true) — jumps out of the inner loop
- `throw` (line 983, terminal path) — propagates out entirely
None of these paths fall through to the code below. The comment "If we reach here, the inner retry loop exhausted without success" is incorrect. This block can be removed.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/acp/control-plane/manager.core.ts
Line: 932-954
Comment:
**Failover skips turn-failure observability recording for intermediate backends**
When a backend qualifies for failover (`shouldFailover = true`), the code pushes to `backendAttempts` and breaks without calling `recordTurnCompletion` or `recordErrorCode`. Only the final backend's failure (via the terminal path) is counted in `turnLatencyStats.failed` and `errorCountsByCode`.
If there are N backends and N-1 fail with failover conditions, N-1 turn failures are silently dropped from the observability snapshot exposed by `getObservabilitySnapshot`. This may make it harder to diagnose repeated rate-limit-induced failovers in production.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/acp/control-plane/manager.core.ts
Line: 933-935
Comment:
**Failover does not trigger for session initialization failures**
`isFailoverCandidate` requires `acpError.code === "ACP_TURN_FAILED"`. However, if `ensureRuntimeHandle` (or `applyRuntimeControls`) throws before `activeTurnStarted = true`, the fallback code is `"ACP_SESSION_INIT_FAILED"` (line 914), so `isFailoverCandidate` will be `false` and no failover is attempted.
If the intent is that quota/rate-limit errors during session initialization should also trigger failover, the condition needs to include `"ACP_SESSION_INIT_FAILED"`. If the current scope (turn execution only) is intentional, a brief comment would prevent future confusion.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "feat(acp): add backend provider failover..." | Re-trigger Greptile Re-review progress:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 76f93fc34b
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 09b9906f5c
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c1b9836da5
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4ece32ec13
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 67422fee34
ℹ️ 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".
|
CI all green, merge state clean. Ready for review + merge. |
|
Please don’t spam-ping multiple maintainers at once. Be patient, or join our community Discord for help: https://discord.gg/clawd |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1ac9f35879
ℹ️ 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".
|
Codex review: needs maintainer review before merge. Summary Reproducibility: not applicable. as a bug reproduction; this PR adds a new ACP failover capability. Source inspection plus the PR body's Blacksmith terminal proof provide a high-confidence way to exercise the new manager path with registered ACP runtime backends. Real behavior proof Next step before merge Security Review detailsBest possible solution: Land this PR or a maintainer-owned equivalent if ACP owners approve Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction; this PR adds a new ACP failover capability. Source inspection plus the PR body's Blacksmith terminal proof provide a high-confidence way to exercise the new manager path with registered ACP runtime backends. Is this the best way to solve the issue? Yes, conditionally. Keeping failover in Acceptance criteria:
What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 609187f5f6db. |
|
Maintainer prep pushed for the ACP fallback review findings. Addressed the clawsweeper items from #69542 (comment):
Real behavior proof:
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
Retry ACP turns on configured fallback backends only for pre-output backend availability failures while preserving stale-handle retry behavior and terminal event validation. Co-authored-by: Altay <[email protected]>
|
Merged via squash.
Thanks @kaseonedge! |
…claw#69542) Merged via squash. Prepared head SHA: 1d4c929 Co-authored-by: kaseonedge <[email protected]> Co-authored-by: altaywtf <[email protected]> Reviewed-by: @altaywtf
…claw#69542) Merged via squash. Prepared head SHA: 1d4c929 Co-authored-by: kaseonedge <[email protected]> Co-authored-by: altaywtf <[email protected]> Reviewed-by: @altaywtf
…claw#69542) Merged via squash. Prepared head SHA: 1d4c929 Co-authored-by: kaseonedge <[email protected]> Co-authored-by: altaywtf <[email protected]> Reviewed-by: @altaywtf
…claw#69542) Merged via squash. Prepared head SHA: 1d4c929 Co-authored-by: kaseonedge <[email protected]> Co-authored-by: altaywtf <[email protected]> Reviewed-by: @altaywtf
When the primary ACP backend fails with ACP_TURN_FAILED due to rate limiting, quota exhaustion, or UNAVAILABLE errors, automatically retry the turn with the next configured backend in acp.fallbacks.
Changes
Real behavior proof
acp.fallbackswhen the primary fails before output, then closes the cached fallback handle before a later turn returns to the configured primary backend.tbx_01krf5h9nzm5mwqnf43yq3cnmyvia Crabbox, GitHub Actions run https://github.com/openclaw/openclaw/actions/runs/25766413953, Linux 32-vCPU runner, OpenClaw checkout with the PR patch applied on the PR merge base.pnpm install --frozen-lockfile,pnpm test src/acp/control-plane/manager.test.ts, then ran apnpm exec tsxproof harness that drives the realAcpSessionManager.runTurnwith two registered ACP runtime backends (primary-proof,fallback-proof).primary-proofbefore output, closed the primary handle withbackend-failover, succeeded onfallback-proof, persisted fallback metadata, then the second turn closed the cached fallback handle withruntime-handle-replacedbefore returning toprimary-proofand completing successfully.