Skip to content

feat(opencode): single-process shared opencode serve for all conversations (opt-in) - #984

Open
leehom0123 wants to merge 1 commit into
iOfficeAI:mainfrom
leehom0123:feat/opencode-shared-server
Open

feat(opencode): single-process shared opencode serve for all conversations (opt-in)#984
leehom0123 wants to merge 1 commit into
iOfficeAI:mainfrom
leehom0123:feat/opencode-shared-server

Conversation

@leehom0123

Copy link
Copy Markdown

Problem

Every opencode conversation spawns a dedicated opencode acp child — N conversations means N full bun runtimes (memory, startup, port pressure; the backdrop of the USER_AGENT_STARTUP_FAILED reports).

Change

Opt-in (AIONUI_OPENCODE_SHARED_SERVER=on; default OFF leaves the ACP path byte-identical) single-process mode: all opencode conversations attach via the existing AgentInstance::Session(Arc<dyn SessionBackend>) seam to ONE pooled opencode serve over its HTTP/SSE v2 API.

  • opencode_shared module: process pool (registry-backed adopt-or-spawn, watchdog, lease-counted teardown that only ever kills its own pid), v2 client, durable per-session SSE with cursor reconnect, event translator, permission/question poll-discovery, active-map turn closure.
  • Factory: toggle-gated branch ahead of the ACP table (route table + its tests untouched); build_opencode_instance follows the antigravity third-backend template.
  • Documented shared-mode limits: fork refused, MCP stays config-file based, no per-conversation spawn env (AIONUI_CONVERSATION_ID stripped).

Testing

  • cargo test -p aionui-ai-agent: 984 pass (incl. 16 new unit tests for the translator/client/SSE parser; the 5 terminal::tests failures are pre-existing Windows env issues unrelated to this change).
  • Workspace cargo check + clippy --all-targets + fmt --check clean.
  • Live E2E (tests/opencode_shared_e2e.rs, gated behind AIONUI_OPENCODE_E2E=1): one server process hosts >=2 conversations (single registry record, independent streams, full turn translation), resume across backend instances from the ses_ anchor, bash-permission approval round-trip via poll-discovered Permission events, and server kill -> Detached -> automatic respawn. All green on Windows against opencode 1.18.30.

…ode serve process (opt-in)

Every opencode conversation spawns its own \opencode acp\ child today; a
few conversations mean several full bun runtimes. With
AIONUI_OPENCODE_SHARED_SERVER=on, all opencode conversations instead attach
to ONE pooled \opencode serve\ over its HTTP/SSE v2 API (durable per-session
events, poll-discovered permission/question pendings, active-map turn
closure), as a Session(Arc<dyn SessionBackend>) like codex/claude.

- new module aionui-ai-agent/src/opencode_shared (pool/client/backend/translate)
- toggle-gated factory branch: default OFF keeps the ACP path byte-identical
- build_opencode_instance mirrors the antigravity third-backend template
- lease-based server lifecycle: last lease down => server down (own pid only)
- 16 unit tests + live E2E (single server hosts >=2 conversations, permission
  approval round-trip, crash => Detached => respawn) gated behind
  AIONUI_OPENCODE_E2E
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