Skip to content

fix(acp): download npx adapters before timing the ACP handshake - #3755

Closed
sivenDev wants to merge 1 commit into
openBitFun:mainfrom
sivenDev:fix/acp-npx-adapter-download
Closed

sivenDev wants to merge 1 commit into
openBitFun:mainfrom
sivenDev:fix/acp-npx-adapter-download

Conversation

@sivenDev

@sivenDev sivenDev commented Nov 5, 2026

Copy link
Copy Markdown

Summary

Built-in ACP adapters (Claude Code, Codex) launch as npx --yes <package>@latest. Whenever a new adapter version is published, npx installs it inside the 60s initialize timeout. Claude Code's adapter pulls a ~140 MB native agent binary (@anthropic-ai/claude-agent-sdk-darwin-arm64, ~300 MB installed), so the install is killed halfway. Each retry starts the install over and fails the same way:

ACP startup timed out: client 'claude-code' exceeded 60s during initialize and was terminated.

The settings predownload cannot prevent this. It runs npm exec --package=<package> without the version tag, and npx keys its install cache by the exact spec text (sha512(spec)[..16] under ~/.npm/_npx). So it fills an entry the launch never reads:

Spec npx cache entry
@agentclientprotocol/claude-agent-acp@latest (launch) _npx/b555b4fead8494dc
@agentclientprotocol/claude-agent-acp (predownload) _npx/d820eb7d96bc2600

This PR:

  • Finds the adapter spec in the configured npx launch and uses it verbatim for both the settings predownload and a new pre-launch preparation step.
  • Before spawning a local or SSH-host npx adapter, runs npx --yes --package=<launch spec> -- <bin> --version under the adapter download timeout. The 60s cap then only covers the ACP handshake. The download timeout goes from 120s to 600s, because an uninterrupted first install measured 122s here.
  • Fails the launch only when the download itself times out. Any other preparation failure is logged and left to the launch, which reports it exactly as before.
  • Extends the wait for callers joining a starting connection so it covers both phases.

Custom clients and non-npx commands are untouched. The requirement probe keeps its "npx present ⇒ auto-installable" fast path from cffd5b3.

Type and Areas

Type: bug fix

Areas: Rust core (openbitfun-acp client), desktop ACP subagents / ACP sessions

Motivation / Impact

Users with the default Claude Code ACP configuration could not start Claude Code (as a session or as a Task subagent) after an adapter release until the download happened to finish some other way. With this change, the first launch after a release waits for the download and then starts. The "配置 / Configure" button in ACP settings now actually pre-warms what the launch runs.

With an up-to-date cache, the preparation step costs about 1.7s per client start (one registry round trip plus --version). That is once per client connection, not per prompt.

Verification

Commands (on this branch):

cargo check --locked -p openbitfun-acp --no-default-features --features client
cargo check --locked -p openbitfun-acp --no-default-features --features server
cargo test  --locked -p openbitfun-acp --no-default-features --features client,openbitfun-core/git --lib client::

New unit tests in client::requirements cover:

  • the built-in preset's preparation spec is the launch arg verbatim;
  • pinned versions and npx options (-y, --registry=…) are preserved;
  • bare specs and npx.cmd are matched;
  • non-npx commands, npm exec, look-alike packages and local paths are ignored;
  • only a download timeout fails the launch.

Manual, desktop dev build on macOS (arm64), driving the real UI to delegate a Task to acp:claude-code:

Scenario Before After
New adapter release, cold npx entry 2/2 attempts failed at 60s during initialize ACP adapter ready … duration_ms=16603, then ACP client started, subagent replied
Cold npx entry and SDK tarball evicted from ~/.npm/_cacache (real network download) — ACP adapter ready … duration_ms=74314 (> old 60s cap), initialize 2.5s, subagent replied

Remote scenarios: the SSH-host preparation path (prepare_remote_npx_adapter) mirrors the existing remote CLI install path, but I did not exercise it against a live SSH workspace. Mobile, IM bot, Peer Device and Detached Dispatch behaviour is not affected beyond inheriting the same launch path.

Reviewer Notes

  • No persisted shapes change; existing acpClients configs (including pinned @x.y.z args) work unchanged.
  • During a long first download the subagent card shows "running" with no "downloading adapter" hint. A UI status for that phase could be a follow-up.

Checklist

  • This PR is focused and does not include secrets, temporary prompts, generated scratch files, or unrelated artifacts.
  • Relevant verification is recorded above, or skipped checks are explained.
  • User-facing strings, docs, and locales are updated where applicable. (No new UI strings; the new error message is a backend Service error, like the existing startup timeout message.)

🤖 Generated with Claude Code

Built-in adapters launch as `npx --yes <package>@latest`. When a new
adapter version is published, npx installs it inside the 60s initialize
timeout; Claude Code's adapter bundles a ~140 MB native agent binary, so
the download is killed halfway and every retry starts over and fails the
same way.

The settings predownload could not prevent this: it ran
`npm exec --package=<package>` without the version tag, and npx keys its
install cache by the exact spec text, so it filled a cache entry the
launch never reads.

- Find the adapter spec in the configured npx launch and use it verbatim
  for both the settings predownload and a pre-launch preparation step.
- Prepare local and SSH-host npx adapters under the download timeout
  (raised from 120s to 600s) before spawning, so the 60s cap only covers
  the handshake. Only a download timeout fails the launch; other
  preparation failures are logged and left to the launch as before.
- Let callers waiting on a starting connection wait for both phases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sivenDev

sivenDev commented Nov 5, 2026

Copy link
Copy Markdown
Author

Closing: superseded by a different approach (OpenBitFun-managed adapter install), which will be proposed separately.

@sivenDev sivenDev closed this Nov 5, 2026
@sivenDev
sivenDev deleted the fix/acp-npx-adapter-download branch November 5, 2026 23:46
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