Repository navigation
feat(acp): carry the failover chain past its first hop - #13
Merged
Merged
Conversation
A usage-limit failover built its replacement agent from an explicit list of settings that did not include the fallback ones, so the runtime it switched to had nowhere left to go. claude-code to codex worked; the next exhaustion on codex ended the conversation in ERROR showing codex's own "you've hit your limit" — which reads as advice to switch to the runtime that had already been tried. The replacement now carries a chain. When it is itself the configured fallback the remaining hop is back to the runtime it replaced, so the chain is a cycle, and an ordered record of every runtime seen exhausted is what stops it going round. A custom runtime leaves the chain, since nothing could relaunch it from a registry key alone. When the chain does run out the failure says so and names the runtimes it tried, classified as a quota outcome, instead of forwarding the last refusal. Claude Code's notice carries the reset time and nothing read it, so `parse_reset_hint` does. A named zone resolves to an absolute instant at the next occurrence of that wall-clock time; a bare time is still read, in local time, and says `approximate` rather than pretending; a payload with no time at all comes back with no instant rather than raising, because "we could not read a reset time" and "there is no limit" are different statements and both callers and tests need to tell them apart. The only reliable signal that a runtime changed mid-conversation was assistant prose. `ACPRuntimeSwitchEvent` carries where it came from, where it went, why, and the reset hint, for failovers and for manual switches alike. The agent server needed nothing: the event reaches `/openapi.json` and the `Event` discriminator through the union the routers already return. The generated TypeScript client is pinned to a published agent-server image, so it picks the kind up when that pin is bumped after this release — contract first, then client. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`acp_fallback_server` and `acp_fallback_model` landed on both the ACP profile and the ACP settings, and `_build_acp_settings` copies them, but neither the launch field-ownership table nor the exported acp section listed them. Both tests assert a complete set, so both have been red since those fields landed. Registering them as PROFILE fields, and putting non-default values on the fixture profile, makes the copy itself covered rather than only tolerated: `test_resolve_copies_profile_fields_and_fixed_values` now proves a configured fallback survives resolve. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Failover now keeps control past its first hop. Today a second exhaustion ends
the conversation with the second runtime's raw refusal, because
_replace_acp_agentbuilds the replacement agent without carrying any fallbacksetting onto it: the chain is one hop by construction.
Three changes, in the order they matter:
1. The chain carries.
_next_acp_fallback(old_agent, acp_server)decides thereplacement's fallback: the configured one carries over verbatim when it differs
from the new runtime, and when the replacement is the configured fallback the
remaining hop points back at the runtime it replaced, making the pair a cycle. A
customruntime drops out — it is not inACP_PROVIDERS, so nothing couldrelaunch it from a key alone. The cycle terminates on
ACP_FAILOVER_TRIED_KEY, an ordered record of every runtime seen exhausted,written in
_replace_acp_agentbeside the existingACP_FAILOVER_FROM_KEY. Amanual switch clears it: the user is restarting the chain, and windows reopen
with time.
When every runtime is spent the conversation fails with
ACPUsageLimitChainExhausted, naming the runtimes tried and the reset time whenone is readable, keeping the raw refusal as trailing detail only. One line in
error_classification.pyputs the new code in the same QUOTA lane asACPUsageLimit, so a day of exhaustion still cannot auto-disable a program.2.
parse_reset_hintreads a reset time out of refusal text intoResetHint(at, source, confidence). A zoned time resolves to an absolute UTCinstant at the next occurrence of that wall clock; a zone-less time is read in
the host zone and says
approximate; anything unparseable returns the defaulthint rather than raising. The regex anchors on
resetand requires a colon or anam/pm, so "the retry counter resets 3 times an hour" is not read as 03:00.
Standard library only.
3.
ACPRuntimeSwitchEventmakes a mid-conversation runtime change a typedevent instead of a sentence inside assistant text:
from_server,to_server,to_model,reason(usage_limit|manual),detail,reset_hint. Emittedby
_fail_over_acponce the new runtime is live and byswitch_acp_serverwithreason="manual", so it covers any switch, which is what a scheduler readingback "which runtime actually ran" needs.
A second commit registers
acp_fallback_serverandacp_fallback_modelin thelaunch field-ownership table and the exported
acpsection. Both tests assert acomplete field set and have been red since those fields landed; the fixture
profile now carries non-default values, so the profile-to-settings copy is
covered rather than merely tolerated.
Why this shape
ResetHintis a pydantic model, not a dataclass, because it rides on theevent into the persisted log and the OpenAPI contract, which only serialise
pydantic models.
sourcekeeps the matched fragment verbatim so a client canshow the runtime's own words.
source="agent".run()skips its owngeneric error event only when the latest
ConversationErrorEventcame from theagent; without that the raw refusal would be appended after this one and
become the error clients show.
EVENT_VISUALIZATION_CONFIG. An unregisteredevent logs a warning and renders nothing, so
visualizewould have been deadcode plus log noise on every failover.
Scope that was checked and left alone
returns
Event, whose discriminated union is built from loaded subclasses;exporting from
openhands.sdk.eventwas enough, and/openapi.jsonnowcarries
ACPRuntimeSwitchEventandResetHintplus the discriminator entry.clients/typescript/src/generated/agent-server-schema.tsis generated from thepinned published image and regenerated by the release bump PR, so an
unreleased event cannot appear there yet. Contract first, then client.
acp_fallback_serveris a single value on the agent, the settings and the profile, and
_replace_acp_agentresolves no profile, so there is no source for a thirdconfigured runtime. What lands is (a) the conversation keeping control past the
first hop and failing with the chain named, and (b) real multi-runtime chains
when a manual switch is involved. A genuine N-runtime chain needs a
list-valued setting across settings, profiles, the server schema and the
Canvas UI — a separate change.
Testing
Full suite:
7497 passed, 7 skipped, 12 xfailed, with one pre-existing failureleft in place —
tests/sdk/plugin/test_agent_plugins_mcp.py::test_configured_headers_do_not_follow_a_redirect_off_origin,which fails on
maintoo and is unrelated to ACP.ruff check .clean;ruff format --checkreports one unrelated unformatted file that is unformattedon
main(tests/agent_server/test_soul_router.py).Both new failover tests fail on
main: the event class does not exist there,and a second exhaustion produces
ACPUsageLimitcarrying the raw refusal.Issue Number
None. Issues are disabled on this fork.
🤖 Generated with Claude Code