LoopForge icon indicating copy to clipboard operation
LoopForge copied to clipboard

[Bug]: Docker conversation workspace ignores mounted AGENTFLOW_RUNTIME_CLI_DIR and reinstalls on-demand npm CLIs

Open 77zane opened this issue 2 days ago • 1 comments

Component / host

Platform — runner / sandbox

Edition

Platform

LoopForge version

v0.4.3 (ghcr.io/tencent/loopforge:0.4.3), verified still present on main (96ed7da4)

What happened?

In a Docker Compose deployment using an on-demand npm agent CLI (such as opencode, claude-code, kimi, or pi):

  • The platform already installs and caches the CLI under $AGENTFLOW_RUNTIME_CLI_DIR (OnDemandCLIPath(provider)), and dockerSandbox already bind-mounts RuntimeCLIDir() read-only at the exact same path inside every Docker sandbox container (internal/runtime/sandbox_docker.go:1139-1144).
  • LOOP nodes reuse that mounted CLI immediately (sandbox_docker.go:467-486), and native conversation workspaces also reuse OnDemandCLIPath(provider) (internal/runtime/conversation_sandbox.go:150-152).
  • However, when entering a Docker conversation workspace, ensureDockerCLI (internal/runtime/conversation_sandbox.go:221-240) only probes dockerCLISharedPath (/opt/loopforge/conversation-cli/bin) + toolchainPathSetup, and when missing only checks a shared host copy for AgentCLICursor (L230-239). It does not check the already-mounted OnDemandCLIPath(provider) for npm-installed CLIs (opencode, claude-code, kimi, pi).

Actual behavior: Every new Docker conversation sandbox container triggers a full npm install --prefix /opt/loopforge/conversation-cli <pkg> from scratch (for opencode-ai this downloads >100 MB per container), stalling the first chat turn in workspace mode for several minutes (or timing out on slower networks), even though the exact same Linux binary is already bind-mounted read-only inside the container under $AGENTFLOW_RUNTIME_CLI_DIR.

Expected behavior: Just like the existing AgentCLICursor branch in ensureDockerCLI (conversation_sandbox.go:230-239), when the CLI is not already on the container's PATH, ensureDockerCLI should check OnDemandCLIPath(provider) on Linux, probe it inside the container via s.probeCLIVersion(ctx, provider, shared) (to ensure architecture/libc compatibility and execute permission for the task user), and reuse it (installMode = "reuse") instead of re-downloading via npm install.

Reproduction

  1. Deploy LoopForge with Docker Compose (ghcr.io/tencent/loopforge:0.4.3) where AGENTFLOW_RUNTIME_CLI_DIR is set to ${LOOPFORGE_DATA_DIR}/cli.
  2. Configure opencode (or claude-code / kimi / pi) credentials and pre-install the CLI via POST /api/assistant/cli-install (confirming GET /api/assistant/cli-install?engine=opencode returns installed).
  3. Run a LOOP node with opencode → observes instant startup reusing $AGENTFLOW_RUNTIME_CLI_DIR/opencode/current/node_modules/.bin/opencode.
  4. Open a chat session using opencode and enter a Docker conversation workspace (or attach to an existing LOOP workspace).
  5. Observe docker exec ... npm install --no-audit --no-fund --prefix /opt/loopforge/conversation-cli 'opencode-ai' running inside the container even though $AGENTFLOW_RUNTIME_CLI_DIR is already bind-mounted read-only inside that container.

Sanitized diagnostics

# Container mounts already include the shared CLI directory read-only:
{"Type":"bind","Source":"<LOOPFORGE_DATA_DIR>/cli","Destination":"<LOOPFORGE_DATA_DIR>/cli","RW":false}

# Yet ensureDockerCLI still executes a fresh npm install inside the container:
docker exec --user 0:0 --workdir / agentflow-run-<id> sh -lc ... \
  npm install --no-audit --no-fund --prefix /opt/loopforge/conversation-cli 'opencode-ai'

Relevant code references (main @ 96ed7da4):

  • internal/runtime/sandbox_docker.go:467-486 (onDemandCLIPath for LOOP runs)
  • internal/runtime/sandbox_docker.go:1139-1144 (mounts RuntimeCLIDir() read-only into Docker containers)
  • internal/runtime/conversation_sandbox.go:150-152 (resolveNativeConversationBinary uses OnDemandCLIPath)
  • internal/runtime/conversation_sandbox.go:221-240 (ensureDockerCLI only reuses shared host copy for AgentCLICursor)

Safety checks

  • [x] I removed credentials, private endpoints, internal identifiers, and personal data.
  • [x] I searched existing issues for duplicates. (Checked #892, #957, #988 — those cover earlier v0.3.8 platform-mode installation/detection, not Docker conversation workspace reuse of mounted AGENTFLOW_RUNTIME_CLI_DIR.)

If this is accepted, I'd be happy to submit a scoped PR with regression tests extending the probeCLIVersion reuse path in ensureDockerCLI to on-demand npm CLIs.

77zane avatar Dec 01 '26 15:12 77zane

Thank you for the report. We understand that a Docker conversation workspace runs a fresh npm install for on-demand CLIs such as opencode, even when that CLI is already mounted read-only from AGENTFLOW_RUNTIME_CLI_DIR, which delays or times out the first turn.

This has been noted and will be reviewed with the current issue queue.

cocofhu00 avatar Dec 01 '26 16:12 cocofhu00