Skip to content

[Bug]: ACP npx cache warm uses --prefer-offline with an outdated cache, hides npm's error, and startup fails with 'Connection closed' #6809

Open

Description

@DevinVinson

Is there an existing issue for the same bug?

  • I have searched existing issues and this is not a duplicate.

Related but different: #5466 (an outdated adapter on PATH replaces the pinned version). In this report the pinned version is used, but npm can't resolve it from the SDK's own npm cache.

Bug Description

ACP startup for npx-based providers can fail permanently on a machine whose ACP npm cache holds an outdated copy of a package's version list. When that happens, the log never shows the real cause.

  1. --prefer-offline makes npm trust an outdated version list. Both the cache warm (_warm_npx_cache in agent/acp_agent.py) and the provider launch command (npx_command() in settings/acp_install_catalog.py) pass --prefer-offline. With that flag, npm resolves versions from its saved copy of each package's version list without checking the registry. When the SDK pins an adapter version, or the adapter pins a dependency, that was published after npm last saved that list, npm reports ETARGET ("No matching version found") for a version that exists. Since every run uses --prefer-offline, nothing ever refreshes the list, so each conversation fails until someone refreshes the cache by hand.
  2. The real error is hidden. _warm_npx_cache sends npm's stdout and stderr to DEVNULL, so the warning only says cache warm failed ... (exit code 1). Startup then continues with the same --prefer-offline launch command, which fails the same way. The error you finally see is ConnectionError: Connection closed from conn.initialize(...). Neither message mentions npm, the missing version, or the cache path. That makes this hard to find, especially because the SDK sets npm_config_cache to its own directory (_acp_npm_cache_dir, next to the conversation store) instead of ~/.npm. Refreshing the user's normal npm cache doesn't help, and nothing in the logs says which cache was used.

Expected Behavior

  • A version list saved in an earlier run doesn't stop a provider from starting when the pinned version exists on the registry.
  • If the provider can't be installed, the error names the package and version and includes npm's error output.

Actual Behavior

Every Claude Code ACP conversation failed to start with Connection closed until I manually ran npx without --prefer-offline against the SDK's npm cache directory.

Steps to Reproduce

  1. Have an ACP npm cache (<persistence_dir parent>/npm-cache; for Agent Canvas dev that's ~/.openhands/agent-canvas/dev_conversations/npm-cache) whose saved version lists predate the currently pinned adapter. In my case it predated @agentclientprotocol/claude-agent-acp@0.99.1, and it was missing @anthropic-ai/claude-agent-sdk@0.3.312 (published 2026-10-27), which that adapter depends on.
  2. Start a conversation with the claude-code ACP provider.
  3. The cache warm fails with exit code 1, and startup fails with ConnectionError: Connection closed.

Running the same warm command manually shows the error the SDK hides:

$ npm_config_cache=~/.openhands/agent-canvas/dev_conversations/npm-cache \
    npx --yes --prefer-offline --package @agentclientprotocol/claude-agent-acp@0.99.1 -- node -e ""
npm error code ETARGET
npm error notarget No matching version found for @agentclientprotocol/claude-agent-acp@0.99.1.

The npm debug log for the same failure in another cache shows the dependency's version list read from the cache instead of the registry:

silly fetch manifest @anthropic-ai/claude-agent-sdk@0.3.312
http fetch GET 200 https://registry.npmjs.org/@anthropic-ai%2fclaude-agent-sdk 9ms (cache stale)
npm error notarget No matching version found for @anthropic-ai/claude-agent-sdk@0.3.312.

Workaround (refreshes the saved version lists; afterwards the --prefer-offline warm and launch both succeed, and the conversation starts):

npm_config_cache=~/.openhands/agent-canvas/dev_conversations/npm-cache \
  npx --yes --package @agentclientprotocol/claude-agent-acp@0.99.1 -- node -e ""

Acceptance Criteria

  • When the cache warm fails with --prefer-offline, it is retried once without --prefer-offline (or with --prefer-online), so an outdated saved version list is refreshed automatically and later runs succeed.
  • A failed warm logs the npm package spec, the npm_config_cache path, and the tail of npm's stderr (for example the ETARGET line), instead of only exit code 1.
  • If the warm still fails after the retry, startup fails with an install error naming the package, instead of launching the same failing npx command and reporting Connection closed.
  • A test covers a warm that fails offline and succeeds online, and one that fails both ways and keeps npm's error output.

Installation Method

Agent Canvas local dev stack: uvx --from openhands-agent-server==1.62.0 --with openhands-sdk==1.62.0 ...

SDK Version

1.62.0. I also checked current main: _warm_npx_cache still uses --prefer-offline with stdout/stderr sent to DEVNULL, and still logs "continuing with normal startup".

Python Version

3.14.5

Operating System

MacOS

Logs and Error Messages

WARNING  ACP provider npx cache warm failed: provider=claude-code; continuing with normal startup: ACP provider cache warm failed for claude-code (exit code 1)  acp_agent.py:3232
ERROR    Failed to start ACP server: Connection closed  acp_agent.py:2535
ERROR    Error during conversation run
Traceback (most recent call last):
  File ".../openhands/agent_server/event_service.py", line 1688, in _run_and_publish
    await conversation.arun()
  File ".../openhands/sdk/conversation/impl/local_conversation.py", line 2367, in _arun
    await asyncio.to_thread(self._ensure_agent_ready)
  File ".../openhands/sdk/conversation/impl/local_conversation.py", line 1732, in _ensure_agent_ready
    self.agent.init_state(
  File ".../openhands/sdk/agent/acp_agent.py", line 2533, in init_state
    self._start_acp_server(state)
  File ".../openhands/sdk/agent/acp_agent.py", line 3632, in _start_acp_server
    ) = self._executor.run_async(_init, timeout=self.acp_startup_timeout)
  File ".../openhands/sdk/agent/acp_agent.py", line 3346, in _init
    init_response = await conn.initialize(protocol_version=1)
  File ".../acp/connection.py", line 126, in send_request
    return await future
ConnectionError: Connection closed  event_service.py:1700

Evidence and Additional Context

  • npm 11.12.1, Node 24.21.0.
  • The same failure would hit any npx-based provider that shares this cache (codex, gemini-cli, pi, opencode, …) whenever a pin is bumped past what the user's cache has seen.
  • Why it's hard to diagnose: in my case, refreshing ~/.npm fixed the manual command but not the agent-server. The agent-server uses its own npm_config_cache, and nothing in the logs shows that path.

🤖 Generated with Claude Code

Activity

  1. added
    bug
    on Nov 13, 2026
  2. all-hands-bot commented on Nov 17, 2026

    @all-hands-bot
    Collaborator

    Verified the reproduction against current main (06f643c). Findings:

    1. --prefer-offline serves an outdated packument without revalidation — confirmed.
    Both _warm_npx_cache (openhands-sdk/openhands/sdk/agent/acp_agent.py, ~line 2762) and npx_command() (openhands-sdk/openhands/sdk/settings/acp_install_catalog.py, ~line 94) pass --prefer-offline. npm maps this to force-cache in make-fetch-happen (getCacheMode() in npm-registry-fetch): staleness checks are bypassed and the cached packument is served even when stale.

    I reproduced this with a local mock registry + a seeded npm cache whose saved packument for a dependency was missing a version that exists on the registry:

    npx --yes --prefer-offline --package @agentclientprotocol/claude-agent-acp@0.99.1 -- node -e ""
    → npm error code ETARGET
    → npm error notarget No matching version found for @mock/mock-dep@2.0.0.   (exit code 1)
    → npm http cache http://.../@mock%2fmock-dep 22ms (cache hit)
    

    The version does exist on the registry — the cached version list just predates it. Re-running the same command without --prefer-offline (default cache mode) revalidates the packument once stale, gets the updated version list, and succeeds — matching the workaround in the issue. So the failure persists across runs as long as --prefer-offline is always used, since revalidation never happens.

    One nuance vs. the report: --prefer-offline is not strictly equivalent to --offline; if the entry is absent npm still goes to the network. The failure mode needs a present but outdated packument entry, which is exactly the scenario described.

    2. The real error is hidden — confirmed.
    _warm_npx_cache pipes npm's stdout/stderr to DEVNULL (acp_agent.py ~2758-2761), so the only signal is "ACP provider cache warm failed for <provider> (exit code 1)". The caller at ~3185-3192 logs "ACP provider npx cache warm failed ... continuing with normal startup" and proceeds to launch the same doomed npx --prefer-offline command, which surfaces only as ConnectionError: Connection closed from conn.initialize(...) (acp_agent.py ~3303). Neither message mentions npm, the package spec, or npm_config_cache (which the SDK points at its own <persistence_dir parent>/npm-cache directory at ~3182, not ~/.npm) — consistent with the report.

    3. Line references in the issue (acp_agent.py:3232 / 2535 / 2533 / 3632 / 3346) differ slightly from current main due to drift, but the corresponding code paths are all present and unchanged in behavior.

    Acceptance criteria all look actionable and testable — in particular the retry-without---prefer-offline (verified above that a revalidation fixes the state) and logging the package spec + cache path + npm stderr tail. Marking ready for dev.

    🤖 Verified by an AI agent (OpenHands) on behalf of the requester.

  3. added
    ready-for-dev
    and removed on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugready-for-dev

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions