Repository navigation
feat(acp): launch pinned pre-installed CLI binary instead of npx - #3490
Conversation
The SDK registry default and the explicit acp_command canvas sends are both `npx -y @<pkg>`, which downloads npm-latest at spawn time: non-reproducible, requires outbound npm, and drifts from the version the agent-server image pins. That image pre-installs the ACP CLIs at a fixed version and exposes wrappers on PATH (claude-agent-acp, codex-acp, gemini), but they were being ignored. Add a `binary_name` field to ACPProviderInfo (additive, defaulted → API non-breaking) and normalize the launch command in the single chokepoint, ACPAgentSettings.resolve_acp_command(): when the command is an `npx -y <provider-pkg>` invocation (the registry default OR an explicit acp_command) and the provider's binary_name resolves via shutil.which(), rewrite to `[binary_name, *extra]`, preserving trailing args like gemini's `--acp`. Falls back to the npx command unchanged when the binary is absent (local dev), for custom servers, and for unrelated packages. Done in resolve_acp_command (not acp_agent._start_acp_server) to avoid conflicting with the parallel #1019 edit there. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Python API breakage checks — ✅ PASSEDResult: ✅ PASSED |
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Coverage Report •
|
||||||||||||||||||||
all-hands-bot
left a comment
There was a problem hiding this comment.
✅ QA Report: PASS
Verified the SDK now prefers pinned ACP binaries when they are on PATH, while preserving npx fallback and custom commands.
Does this PR achieve its stated goal?
Yes. The PR set out to make ACP launch resolution use the pinned, pre-installed CLI wrappers instead of npx -y @<pkg> when those wrappers are available. I exercised the SDK settings path as a user would by importing ACPAgentSettings, creating fake executable ACP wrappers on PATH, comparing base vs PR behavior, and verifying create_agent() bakes the rewritten command into the agent.
| Phase | Result |
|---|---|
| Environment Setup | ✅ make build completed successfully. |
| CI Status | ⏳ At observation time: 18 successful, 1 skipped, 10 pending, 0 failing. |
| Functional Verification | ✅ Base kept npx; PR rewrote matching provider commands to pinned binaries and preserved fallback behavior. |
Functional Verification
Test 1: Provider default and explicit Canvas-style commands prefer pinned binaries
Step 1 — Reproduce / establish baseline (without the fix):
Checked out the merge-base commit 50bfa3ede2a759d54a1d051083104ca8b76d2e70, created fake executable wrappers at /tmp/qa-acp-bin/{claude-agent-acp,codex-acp,gemini}, prepended that directory to PATH, then ran:
uv run python /tmp/acp_command_qa.pyRelevant output:
default claude: ['npx', '-y', '@agentclientprotocol/claude-agent-acp']
default codex: ['npx', '-y', '@zed-industries/codex-acp']
default gemini: ['npx', '-y', '@google/gemini-cli', '--acp']
explicit canvas codex: ['npx', '-y', '@zed-industries/codex-acp', '--verbose']
explicit other package: ['npx', '-y', '@other/some-acp']
custom binary: ['/opt/my-codex', '--flag']
This confirms the old behavior ignored pinned wrappers even when matching binaries were present on PATH, continuing to use npx for built-in defaults and an explicit Canvas-style codex command.
Step 2 — Apply the PR's changes:
Checked out acp-prefer-pinned-binary at d91609a883e6fad078d6534f9ec17ad2aaea2f1c.
Step 3 — Re-run with the fix in place:
Ran the same command:
uv run python /tmp/acp_command_qa.pyRelevant output:
default claude: ['claude-agent-acp']
default codex: ['codex-acp']
default gemini: ['gemini', '--acp']
explicit canvas codex: ['codex-acp', '--verbose']
explicit other package: ['npx', '-y', '@other/some-acp']
custom binary: ['/opt/my-codex', '--flag']
This shows the PR achieves the core goal: matching built-in provider npx commands are rewritten to pinned wrapper names, Gemini's trailing --acp is preserved, and non-matching/custom commands remain unchanged.
Test 2: Agent construction, executable launch target, and fallback behavior
On the PR branch, I ran an additional SDK script that creates fake ACP wrappers, calls create_agent(), executes the resolved Gemini command, then switches to an empty PATH to verify local-dev fallback:
uv run python /tmp/acp_command_pr_edge_qa.pyOutput:
create_agent codex command: ['codex-acp']
launch resolved gemini: launched gemini --acp
absent binary codex command: ['npx', '-y', '@zed-industries/codex-acp']
custom server explicit npx: ['npx', '-y', '@zed-industries/codex-acp']
This confirms the resolved binary command is what create_agent() stores on the ACP agent, the resolved command can be launched from PATH with trailing args intact, and absence of the pinned binary or a custom server leaves the original npx command untouched.
Issues Found
None.
This QA review was created by an AI agent (OpenHands) on behalf of the user.
# Conflicts: # openhands-sdk/openhands/sdk/settings/acp_providers.py # tests/sdk/settings/test_acp_providers.py
Several tests defined `SecretSource` subclasses *inside* test functions. `SecretSource` is a `DiscriminatedUnionMixin`: every subclass auto-registers in a global registry and is never GC'd (pydantic caches its core schema). A function-local subclass has `<locals>` in its qualname, which `_get_checked_concrete_subclasses` rejects with "Local classes not supported!" the next time *any* discriminated-union model is validated in the same process. Under pytest-xdist this is order/worker-dependent: once a polluting test runs on a worker, a later `ConversationState.create()` on that same worker (e.g. tests/sdk/conversation/local/test_state_serialization.py) fails to deserialize its `secret_registry`. It's latent on main and was exposed on this branch because the added tests shifted xdist's worker distribution. Fix: define the throwaway `SecretSource` subclasses at module level (the supported pattern — importable, no `<locals>`). In test_secrets_manager.py this also removes two same-named function-local classes that would additionally trip the registry's "Duplicate class definition" guard. No production code change; deterministic repro (polluting test + a state-serialization test in one process) now passes, and the full sdk suite is green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Trim the verbose docstrings/notes added in this PR (binary_name field, resolve_acp_command/_prefer_pinned_binary, and the module-level SecretSource notes) to be more concise. Comment-only; no behavior change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
✅ Review complete. This review was performed through OpenHands Cloud Automation. You can log in and view the conversation here. |
all-hands-bot
left a comment
There was a problem hiding this comment.
Code Review: feat(acp): launch pinned pre-installed CLI binary instead of npx
Overview
This PR introduces a mechanism to prefer pre-installed CLI binaries (like claude-agent-acp, codex-acp, gemini) over downloading packages via npx at runtime. The agent-server image now ships these ACP CLIs at fixed versions as PATH wrappers, and this change enables resolve_acp_command() to use them when available, falling back to npx when not.
🟠 Strengths
-
Well-designed feature: The fallback behavior (npx when binary not on PATH) is correct for local dev scenarios while enabling the reproducible pinned binary path in the agent-server container.
-
Comprehensive tests: The test suite covers all edge cases:
- Registry default + binary on PATH → binary used
- Explicit
npx -y <pkg>+ binary on PATH → rewritten to binary - Binary absent → npx command unchanged
- Custom binary path → never rewritten
- Non-matching npm package → not rewritten
- Custom server → never rewritten
- Trailing args (e.g.,
--acpfor gemini) are preserved
-
Clean separation: The
_parse_npx_invocationand_prefer_pinned_binarymethods are well-named, properly documented, and handle their single responsibility well. -
Module-level SecretSource classes: The test refactoring (moving classes outside functions) prevents the "Local classes not supported" registry issue with xdist. This is a solid fix.
-
Proper use of
compare=False: Thebinary_namefield hascompare=Falsewhich avoids breaking existing equality checks in tests.
🔍 Minor Suggestions
-
Use
functools.lru_cacheforshutil.whichcalls (low priority): Ifresolve_acp_commandis called multiple times, caching thewhichresult could save some filesystem lookups. Though for typical single-agent-lifetime usage this is negligible. -
Consider a test for
acp_envoverride with pinned binary: The test suite verifies thatacp_envshadows registry lookups, but there is no test combining that with the pinned binary behavior. Not critical, but could provide additional confidence. -
Explicit None check for
info: Inresolve_acp_command, theget_acp_providerreturningNoneis handled, but the error message could be more helpful by suggesting valid server names.
📝 Documentation Note
The inline docstring on binary_name in acp_providers.py is thorough. Consider also updating the SDK documentation if there is a "Connecting to ACP servers" guide to mention the new behavior.
Conclusion
This is a well-implemented feature with solid test coverage. The design correctly handles both the production use case (pinned binary on PATH) and local development (fallback to npx). The test refactoring is a necessary and beneficial side effect.
Recommendation: Approve
This review was generated by an AI agent (OpenHands) on behalf of the user through OpenHands Automation. View conversation
all-hands-bot
left a comment
There was a problem hiding this comment.
🟡 QA Report: PARTIAL
Pinned-binary command selection works locally and through the PR-built agent-server API; a live ACP prompt round-trip was not verified because ACP CLI credentials were unavailable.
Does this PR achieve its stated goal?
Yes for the command-selection path that controls ACP launch. On base main, with fake claude-agent-acp / codex-acp / gemini wrappers on PATH, SDK settings still resolved to npx; on this PR the same user-facing ACPAgentSettings flow resolved to the pinned wrappers and preserved trailing args. In the PR-built ghcr.io/openhands/agent-server:082d832-python image, real POST /api/conversations requests stored acp_command as claude-agent-acp, codex-acp, and gemini --acp, including rewriting an explicit canvas-style npx -y @zed-industries/codex-acp --verbose command to codex-acp --verbose.
| Phase | Result |
|---|---|
| Environment Setup | ✅ uv environment available and PR image ghcr.io/openhands/agent-server:082d832-python ran locally on port 18000 |
| CI Status | ✅ Most checks green (sdk-tests, agent-server-tests, builds, API checks, etc.); qa-changes was still IN_PROGRESS; cleanup checks skipped |
| Functional Verification | ✅ Local SDK command resolution and running server API request-validation path verified; |
Functional Verification
Test 1: Local SDK command resolution before/after
Step 1 — Establish baseline without the fix:
Checked out origin/main at e253c5e2e7f7 and ran a small user-style script that put fake claude-agent-acp, codex-acp, and gemini wrappers on PATH, then called ACPAgentSettings(...).resolve_acp_command() / create_agent():
{
"defaults": {
"claude-code": ["npx", "-y", "@agentclientprotocol/claude-agent-acp"],
"codex": ["npx", "-y", "@zed-industries/codex-acp"],
"gemini-cli": ["npx", "-y", "@google/gemini-cli", "--acp"]
},
"explicit_canvas_codex": ["npx", "-y", "@zed-industries/codex-acp", "--verbose"],
"which": {"claude-agent-acp": true, "codex-acp": true, "gemini": true}
}This confirms the old behavior: even when pinned wrappers are available on PATH, the SDK resolves ACP providers to npx invocations.
Step 2 — Apply the PR's changes:
Checked out acp-prefer-pinned-binary at 082d832c33ea.
Step 3 — Re-run with the fix in place:
Ran the same script:
{
"defaults": {
"claude-code": ["claude-agent-acp"],
"codex": ["codex-acp"],
"gemini-cli": ["gemini", "--acp"]
},
"explicit_canvas_codex": ["codex-acp", "--verbose"],
"binary_absent_codex": ["npx", "-y", "@zed-industries/codex-acp"],
"custom_binary_codex": ["/tmp/.../my-codex", "--flag"],
"which": {"claude-agent-acp": true, "codex-acp": true, "gemini": true}
}This shows the fix works for the local SDK entry point: default providers and explicit canvas-style npx commands prefer pinned wrappers, Gemini keeps --acp, absent binaries fall back to npx, and custom binaries remain untouched.
Test 2: PR-built agent-server image API path
Step 1 — Establish server baseline for the changed path:
Started the PR image with Docker:
docker run --rm --name qa-acp-082d832 -p 127.0.0.1:18000:8000 ghcr.io/openhands/agent-server:082d832-pythonThen confirmed the API schema exposed POST /api/conversations with StartACPConversationRequest accepting workspace and agent_settings.
Step 2 — Exercise real API requests through the runtime image:
Posted minimal ACP conversation requests to http://127.0.0.1:18000/api/conversations for each provider, plus an explicit canvas-style Codex command.
Step 3 — Observed server responses:
{
"claude-code": {"status": 201, "acp_command": ["claude-agent-acp"]},
"codex": {"status": 201, "acp_command": ["codex-acp"]},
"gemini-cli": {"status": 201, "acp_command": ["gemini", "--acp"]},
"explicit_canvas_codex": {"status": 201, "acp_command": ["codex-acp", "--verbose"]}
}This verifies the server-side request-validation/runtime path described by the PR: conversations created in the PR-built image store the pinned binary command rather than npx, including the explicit acp_command shape that agent-canvas sends.
Unable to Verify
I did not verify a full live ACP model prompt round-trip. The available environment did not include ACP CLI credentials (Codex/Claude/Gemini auth), and a separate attempt to use fake ACP executables to observe subprocess launch hung in ACP initialization because the fake process did not speak the ACP protocol. Future QA guidance in AGENTS.md could include a safe local ACP stub command that completes initialization without external credentials.
Issues Found
None.
This QA review was created by an AI agent (OpenHands) on behalf of the user.
|
Closes: OpenHands/OpenHands#3487 |
Address review feedback (VascoSch92): - _parse_npx_invocation: use itertools.dropwhile to skip leading npx flags instead of a manual index loop. - _prefer_pinned_binary: merge the package-mismatch and which()-miss guards into one condition (which() still short-circuits to package matches only). Behavior-preserving; resolve_acp_command edge-case tests unchanged and green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
A second, identical module-level _FakeLookupSecret landed via a merge collision (the pinned-binary PR #3490 added one while another PR had already added one at the top of the file). pyright flags the redeclaration (reportRedeclaration), failing the pre-commit check on every PR. Keep the single definition near the top; the file-secret tests reuse it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…nHands#3357) The three built-in ACP providers launched with floating `npx -y <pkg>` commands, so on the native (no pre-installed binary) path the package version was resolved from npm `latest` at agent-launch time — after commit review and the `[tool.uv] exclude-newer` lock guardrail — and each provider runs under a permission-disabling default session mode. - Pin `default_command` for `claude-code`, `codex`, and `gemini-cli` via module-level constants matching the agent-server Dockerfile (the single source of truth): claude-agent-acp@0.30.0, codex-acp@0.15.0, gemini-cli@0.38.0. - Make `_prefer_pinned_binary` match the provider package by name (ignoring any `@version`) so the image binary rewrite from OpenHands#3490 still fires for the pinned default and for any npx command a client sends (bare or drifted), while only the native fallback carries the pin. - Fix the OpenAPI example in conversation_router_acp.py to use the scoped, pinned `@agentclientprotocol/claude-agent-acp@0.30.0` (the unscoped `claude-agent-acp` 404s on npm and is a dependency-confusion footgun). Supersedes OpenHands#3399. Co-authored-by: Sanjay Santhanam <51058514+Sanjays2402@users.noreply.github.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…nHands#3490) Co-authored-by: Simon Rosenberg <simon@openhands.dev> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
What
Make the SDK launch the pinned, pre-installed ACP CLI binary instead of
npx -y @<pkg>.The agent-server image (
openhands-agent-server/.../docker/Dockerfile) pre-installs the ACP CLIs at a fixed version and exposes wrappers onPATH:/usr/local/bin/{claude-agent-acp, codex-acp, gemini}. But both launch paths ignored them:default_commandis("npx", "-y", "@<pkg>", …), andacp_command=["npx","-y","@<pkg>"]in itsStartConversationRequest.Both run
npx→ download npm-latest at spawn time: non-reproducible, needs outbound npm, and drifts from the Dockerfile pin.How
settings/acp_providers.py— add abinary_namefield toACPProviderInfo(
claude-code→claude-agent-acp,codex→codex-acp,gemini-cli→gemini,Nonefor custom).Additive, defaulted (
field(default=None, compare=False)) → API-breakage check stays green.settings/model.py→ACPAgentSettings.resolve_acp_command()— the single chokepoint that handles boththe explicit
acp_commandand the registry default. Normalize the command: when it is an["npx","-y","<provider-pkg>", *extra]invocation and the provider'sbinary_nameresolves viashutil.which(), rewrite to["<binary_name>", *extra]— preserving trailing args (e.g. gemini's--acp).Falls back to the
npxcommand unchanged when:PATH(local dev),custom/ has no registry entry,npxinvocation (user-supplied binary), ornpxcommand is for a different package.Done in
resolve_acp_command, not inacp_agent.py:_start_acp_server— OpenHands/agent-canvas#2114 (now merged as OpenHands/OpenHands#3492) edits that path; this PR stays confined tosettings/to avoid conflicts. BecauseStartConversationRequestvalidation callscreate_agent()→resolve_acp_command()inside the runtime pod,shutil.which()resolves against the pod's pre-installed wrappers — so the rewrite takes effect for both the registry default and the canvas-sentacp_command.Tests
resolve_acp_commandunit tests (mockingshutil.which): default + binary on PATH →[binary, *args]; explicit npx + binary → rewritten; binary absent → npx unchanged; custom binary / unknown package / custom server → untouched;whichprobed withbinary_name; end-to-end viacreate_agent(). Pre-existing npx-asserting tests pinshutil.which→Noneso they're deterministic regardless of whether the binaries happen to be installed locally. Registry metadata tests assert the threebinary_namevalues.Real end-to-end validation (against a PR-built image)
Built the
pythonagent-server image from this branch and exercised the live path in-container:claude-agent-acp/codex-acp/gemini --acp, trailing arg preserved); custom/absent-binary fall back to npx.POST /api/conversationswithagent_kind=acpstores the resolvedacp_command(['codex-acp'],['claude-agent-acp']) — proving the rewrite runs at request-validation time in the pod.ACP server initialized: agent_name='codex-acp', agent_version='0.15.0'(the Dockerfile pin), 0 npx in logs.claude-agent-acpthrough a LiteLLM proxy viaANTHROPIC_BASE_URL; prompt "reply with exactly: ACP_E2E_OK" → genuine model responseACP_E2E_OK, launched via pinnedclaude-agent-acp@0.30.0.✅ ruff (check + format), pyright, api-breakage clean; full
sdk-testssuite green.Also in this PR
main— integrates Update README.md to acknowledge OpenDevin OpenHands#3492 (per-conversation CLI data-dir isolation);ACPProviderInfonow carries bothbinary_nameanddata_dir_env_var.test(sdk): hoist test-local SecretSource subclasses to module level) — several tests definedSecretSourcesubclasses inside test functions.SecretSourceis aDiscriminatedUnionMixin: such subclasses auto-register globally, are never GC'd (pydantic caches their schema), and a function-local one (<locals>in its qualname) makes the registry raise "Local classes not supported!" on the nextConversationStatedeserialization sharing that xdist worker. Latent onmain; this branch's added tests shifted xdist's worker distribution and exposed it (thesdk-testsfailures). Fixed by hoisting the throwaway subclasses to module level (the supported pattern) intest_acp_agent.py,test_secrets_manager.py, andtest_conversation_secrets_constructor.py— no production-code change.Notes
acp-providers.jsonmirror is intentionally not updated — canvas doesn't consumebinary_name. Will update only if a drift check fails.SecretSourcepattern still exists intests/cross/test_agent_secrets_integration.py(a separatecross-testsjob/process, not currently failing) — left for a follow-up to keep this PR scoped.🤖 Generated with Claude Code
Agent Server images for this PR
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdknikolaik/python-nodejs:python3.13-nodejs22-slimgolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:dd0edb8-pythonRun
All tags pushed for this build
About Multi-Architecture Support
dd0edb8-python) is a multi-arch manifest supporting both amd64 and arm64dd0edb8-python-amd64) are also available if needed