Skip to content

feat(agent-registry): prefer globally installed agent binaries over npx#230

Open
ApolloS-Hub wants to merge 1 commit intoopenclaw:mainfrom
ApolloS-Hub:fix/prefer-global-binary-over-npx
Open

feat(agent-registry): prefer globally installed agent binaries over npx#230
ApolloS-Hub wants to merge 1 commit intoopenclaw:mainfrom
ApolloS-Hub:fix/prefer-global-binary-over-npx

Conversation

@ApolloS-Hub
Copy link
Copy Markdown

Summary

When a built-in agent adapter (e.g. claude-agent-acp, codex-acp) is globally installed and available on PATH, use it directly instead of falling back to npx package-exec.

Problem

The current agent resolution only checks:

  1. Local node_modules install
  2. npx package-exec bridge

In slow-network environments (high latency to npm registry, corporate proxies, China mainland, restricted networks), the npx download/cache-check during probe can time out, causing the acpx backend to stay at registered and never reach ready. This manifests as sessions_spawn(runtime="acp") hanging indefinitely.

Related: openclaw/openclaw#51345sessions_spawn(runtime="acp") hangs immediately

Solution

Add a new resolution step between local install and npx fallback:

1. Local node_modules install (existing)
2. Global PATH binary (NEW — via which/where)  ← added
3. npx package-exec bridge (existing fallback)

New resolveGlobalPathAgentLaunch() function uses which (Unix) or where (Windows) with a 5-second timeout to detect globally installed binaries.

Changes

  • src/agent-registry.ts: Added resolveGlobalPathAgentLaunch() and integrated it into resolveBuiltInAgentLaunch() resolution chain
  • src/acp/client.ts: Added spawn log message for global-path source
  • test/agent-registry.test.ts: Added 4 new tests covering the global PATH resolution

Benefits

  • Eliminates network dependency during agent spawn for users who pre-install adapters
  • Faster startup in all environments (no npx cache check overhead)
  • Zero breaking changes — existing behavior preserved as fallback
  • Cross-platform: works on Unix (which) and Windows (where)

Test Results

All 16 tests pass, including 4 new tests:

  • resolveGlobalPathAgentLaunch uses a globally installed binary from PATH
  • resolveGlobalPathAgentLaunch returns undefined when binary is not on PATH
  • resolveGlobalPathAgentLaunch ignores non-built-in commands
  • resolveBuiltInAgentLaunch prefers global PATH over package-exec when local install unavailable

When a built-in agent adapter (e.g. claude-agent-acp, codex-acp) is
globally installed and available on PATH, use it directly instead of
falling back to npx package-exec.

This eliminates the network dependency during agent spawn, which is
critical for:
- Slow-network environments (high latency to npm registry)
- Corporate proxies / restricted networks
- Regions with unreliable npm mirror access
- Faster startup in all environments (no npx cache check overhead)

Resolution order is now:
1. Local node_modules install (existing behavior)
2. Global PATH binary (NEW - via which/where)
3. npx package-exec bridge (existing fallback)

The new resolveGlobalPathAgentLaunch() function uses 'which' (Unix) or
'where' (Windows) with a 5-second timeout to detect globally installed
binaries.

Fixes openclaw/openclaw#51345
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