Skip to content

feat(acp): carry the failover chain past its first hop - #13

Merged
tentpegbob merged 2 commits into
mainfrom
feat/acp-failover-chain
Oct 24, 2026
Merged

tentpegbob merged 2 commits into
mainfrom
feat/acp-failover-chain

Conversation

@tentpegbob

Copy link
Copy Markdown

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_agent builds the replacement agent without carrying any fallback
setting 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 the
replacement'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
custom runtime drops out — it is not in ACP_PROVIDERS, so nothing could
relaunch 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_agent beside the existing ACP_FAILOVER_FROM_KEY. A
manual 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 when
one is readable, keeping the raw refusal as trailing detail only. One line in
error_classification.py puts the new code in the same QUOTA lane as
ACPUsageLimit, so a day of exhaustion still cannot auto-disable a program.

2. parse_reset_hint reads a reset time out of refusal text into
ResetHint(at, source, confidence). A zoned time resolves to an absolute UTC
instant 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 default
hint rather than raising. The regex anchors on reset and requires a colon or an
am/pm, so "the retry counter resets 3 times an hour" is not read as 03:00.
Standard library only.

3. ACPRuntimeSwitchEvent makes a mid-conversation runtime change a typed
event instead of a sentence inside assistant text: from_server, to_server,
to_model, reason (usage_limit | manual), detail, reset_hint. Emitted
by _fail_over_acp once the new runtime is live and by switch_acp_server with
reason="manual", so it covers any switch, which is what a scheduler reading
back "which runtime actually ran" needs.

A second commit registers acp_fallback_server and acp_fallback_model in the
launch field-ownership table and the exported acp section. Both tests assert a
complete 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

  • ResetHint is a pydantic model, not a dataclass, because it rides on the
    event into the persisted log and the OpenAPI contract, which only serialise
    pydantic models. source keeps the matched fragment verbatim so a client can
    show the runtime's own words.
  • The chain-exhausted event is source="agent". run() skips its own
    generic error event only when the latest ConversationErrorEvent came from the
    agent; without that the raw refusal would be appended after this one and
    become the error clients show.
  • The event is registered in EVENT_VISUALIZATION_CONFIG. An unregistered
    event logs a warning and renders nothing, so visualize would have been dead
    code plus log noise on every failover.

Scope that was checked and left alone

  • No router or TypeScript-client change is needed. The conversation router
    returns Event, whose discriminated union is built from loaded subclasses;
    exporting from openhands.sdk.event was enough, and /openapi.json now
    carries ACPRuntimeSwitchEvent and ResetHint plus the discriminator entry.
    clients/typescript/src/generated/agent-server-schema.ts is generated from the
    pinned published image and regenerated by the release bump PR, so an
    unreleased event cannot appear there yet. Contract first, then client.
  • "Chain past one hop" is not three configured hops. acp_fallback_server
    is a single value on the agent, the settings and the profile, and
    _replace_acp_agent resolves no profile, so there is no source for a third
    configured 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

tests/sdk/conversation/test_acp_failover.py ....... (7)
tests/sdk/agent/test_acp_usage_limit.py ........................ (24)
31 passed

Full suite: 7497 passed, 7 skipped, 12 xfailed, with one pre-existing failure
left in place — tests/sdk/plugin/test_agent_plugins_mcp.py::test_configured_headers_do_not_follow_a_redirect_off_origin,
which fails on main too and is unrelated to ACP. ruff check . clean;
ruff format --check reports one unrelated unformatted file that is unformatted
on 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 ACPUsageLimit carrying the raw refusal.

Issue Number

None. Issues are disabled on this fork.

🤖 Generated with Claude Code

Leander Metcalf and others added 2 commits October 24, 2026 07:07
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>
@tentpegbob
tentpegbob merged commit b261b4a into main Oct 24, 2026
3 checks passed
@tentpegbob
tentpegbob deleted the feat/acp-failover-chain branch October 24, 2026 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant