Skip to content

fix(acp): bound ACP server startup with a timeout - #4126

Merged
neubig merged 1 commit into
OpenHands:mainfrom
rsd-darshan:fix/acp-startup-timeout
Jul 20, 2026
Merged

neubig merged 1 commit into
OpenHands:mainfrom
rsd-darshan:fix/acp-startup-timeout

Conversation

@rsd-darshan

Copy link
Copy Markdown
Contributor

HUMAN:

Picked this up from the open issue tracker, fix verified locally.


AGENT:

Why

ACPAgent._start_acp_server runs its spawn + initialize()/authenticate()/new_session()/load_session() coroutine (_init()) via self._executor.run_async(_init) with no timeout. If any of those ACP calls hang — e.g. codex-acp blocking indefinitely on authenticate() when the local id_token is expired — the coroutine never returns and never raises, so init_state() freezes forever. Because a silent hang never raises, the existing try/except in init_state() that emits a typed ConversationErrorEvent is never reached, and the client sees no error at all — just a spinner forever.

Summary

  • Added acp_startup_timeout: float (default 90s) to ACPAgent, mirroring the existing acp_prompt_timeout idle-timeout field.
  • Passed timeout=self.acp_startup_timeout to the existing run_async(...) call (it already supports a timeout kwarg via anyio.fail_after, already used elsewhere in this file for the prompt-turn idle timeout).
  • The resulting bare TimeoutError (anyio.fail_after raises one with no message) is caught and re-raised with a descriptive message, mirroring _idle_timeout_message()'s pattern for the turn-loop path.
  • Added an ACPStartupTimeout branch to _classify_acp_init_error() so init_state()'s existing cold-start error handler emits a typed ConversationErrorEvent instead of the generic ACPInitError.
  • Wired the new field through every place that already mirrors acp_prompt_timeout: ACPAgentSettings (+ its create_agent() pass-through), ACPAgentProfile, and the two settings↔profile conversion helpers (profiles/seed.py, profiles/resolver.py).

Issue Number

#3629

How to Test

Ran the full local test suite after the change:

uv run pytest tests/sdk/agent/test_acp_agent.py tests/sdk/test_settings.py tests/sdk/profiles/ \
  tests/agent_server/test_settings_router.py tests/agent_server/test_conversation_router.py -q
# 832 passed

uv run pyright openhands-sdk/openhands/sdk/agent/acp_agent.py openhands-sdk/openhands/sdk/settings/model.py \
  openhands-sdk/openhands/sdk/profiles/agent_profile.py openhands-sdk/openhands/sdk/profiles/seed.py \
  openhands-sdk/openhands/sdk/profiles/resolver.py
# 0 errors

make lint
# All checks passed!

Added two new regression tests that reproduce the reported hang directly: test_start_acp_server_bounds_a_hung_handshake_call makes conn.initialize() hang for 10s with acp_startup_timeout=0.05, and asserts _start_acp_server raises a descriptive TimeoutError well before the 10s would elapse (test runs in well under a second). test_init_state_surfaces_startup_timeout drives the same hang through the full init_state() path and asserts the client-facing ConversationErrorEvent carries code ACPStartupTimeout and the descriptive detail message. Also added test_timeout_error_is_startup_timeout for the classifier unit.

Pre-commit hooks (ruff format, ruff lint, pycodestyle, pyright, import-dependency rules, tool-subclass registration) all passed on commit.

Video/Screenshots

Not applicable — backend Python logic fix with no UI surface; verified via the tests above.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

New field defaults to 90s, within the 60-90s range suggested in the issue. No breaking changes — existing callers get the new timeout automatically with a sane default; no config migration needed.

ACPAgent._start_acp_server ran its spawn + authenticate + session-create
coroutine with no timeout, so a hung ACP call during startup (e.g.
codex-acp blocking on an expired id_token inside authenticate()) froze
init_state() forever with no error ever surfaced to the client.

Add acp_startup_timeout (default 90s) and pass it to the existing
run_async(timeout=...) support, converting the resulting bare
TimeoutError into a descriptive one and classifying it as a new
ACPStartupTimeout code in _classify_acp_init_error. Wired the new field
through ACPAgentSettings, ACPAgentProfile, and the settings<->profile
conversion helpers (seed.py, resolver.py) alongside the existing
acp_prompt_timeout field they already mirror.
@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: I have assigned @neubig as a reviewer based on the repository MAINTAINERS file. Thanks in advance for the help!

This comment was created by an AI agent (OpenHands) on behalf of the user.

@neubig neubig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

@neubig
neubig merged commit 68aa583 into OpenHands:main Jul 20, 2026
31 checks passed
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.

3 participants