[GH-ISSUE #222] Bug: Startup crash when OpenCode agent profile is auto-detected — cptr tries to JSON-parse opencode serve's plain-text stdout #134

Open
opened 2026-10-18 14:03:16 +00:00 by bsakaguchi · 2 comments
Owner

Originally created by @Rory-Lambert on GitHub (Aug 14, 2026).
Original GitHub issue: https://github.com/open-webui/computer/issues/222

cptr (installed via uvx cptr@latest run) crashes on startup with an unhandled JSONDecodeError when it auto-detects a locally installed opencode CLI and probes it as an agent profile. This kills the entire FastAPI app during lifespan startup, not just that one profile.

Environment:

  • Arch Linux
  • opencode installed via pacman/AUR, fully functional and logged in
  • cptr run via uvx cptr@latest run
  • Python 3.14 (via uv's resolved interpreter) — also reproduced when pinning --python 3.12, so not Python-version-specific

Traceback:
File ".../cptr/app.py", line 67, in lifespan
await warm_model_cache(app.state)
File ".../cptr/routers/chat.py", line 281, in warm_model_cache
await asyncio.gather(*tasks)
File ".../cptr/utils/agents/detection.py", line 690, in get_available_agent_model_entries
status = await get_agent_status(app_state)
File ".../cptr/utils/agents/detection.py", line 648, in get_agent_status
detected = await detect_profile(profile)
File ".../cptr/utils/agents/detection.py", line 267, in detect_profile
models = await _probe_acp_models(command, profile, auth_method_id="oauth-personal")
File ".../cptr/utils/agents/detection.py", line 589, in _probe_acp_models
await client.close()
File ".../cptr/utils/agents/acp.py", line 85, in close
await task
File ".../cptr/utils/agents/acp.py", line 183, in _reader_loop
extracted = _extract_json_message(buffer)
File ".../cptr/utils/agents/acp.py", line 261, in _extract_json_message
return json.loads(line.decode()), buffer[line_end + 1 :]
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Root cause (confirmed via manual reproduction):
For the OpenCode profile type, cptr spawns:
opencode serve --hostname=127.0.0.1 --port=
Running that exact command by hand shows opencode writes plain human-readable log lines to stdout on startup, not JSON:
Warning: OPENCODE_SERVER_PASSWORD is not set; server is unsecured.
opencode server listening on http://127.0.0.1:47645
cptr's _reader_loop/_extract_json_message appears to treat this subprocess's stdout as a newline-delimited JSON-RPC stream (the ACP convention used for other agent types), and immediately fails json.loads() on the first non-JSON line. This is reproducible even with a no-op stub binary named opencode on PATH that produces zero stdout output before exiting — json.loads("") throws the identical error, confirming this isn't about opencode's specific output but about cptr expecting JSON where serve mode never produces it.

Impact: Any user with opencode installed and discoverable on PATH cannot start cptr at all — a single bad profile probe takes down the entire app during lifespan startup (asyncio.gather(*tasks) in warm_model_cache has no per-task error isolation, and detect_profile/_probe_acp_models don't catch JSONDecodeError).

Suggested fixes:

  1. Catch and isolate per-profile detection errors in warm_model_cache/get_available_agent_model_entries so one broken agent profile can't crash app startup.
  2. For the OpenCode profile type specifically, don't reuse the ACP JSON-RPC stdout reader against opencode serve — its stdout is plain log text, not JSON-RPC; communication should happen over HTTP against the bound port instead.
Originally created by @Rory-Lambert on GitHub (Aug 14, 2026). Original GitHub issue: https://github.com/open-webui/computer/issues/222 cptr (installed via uvx cptr@latest run) crashes on startup with an unhandled JSONDecodeError when it auto-detects a locally installed opencode CLI and probes it as an agent profile. This kills the entire FastAPI app during lifespan startup, not just that one profile. **Environment:** - Arch Linux - opencode installed via pacman/AUR, fully functional and logged in - cptr run via uvx cptr@latest run - Python 3.14 (via uv's resolved interpreter) — also reproduced when pinning --python 3.12, so not Python-version-specific - **Traceback:** File ".../cptr/app.py", line 67, in lifespan await warm_model_cache(app.state) File ".../cptr/routers/chat.py", line 281, in warm_model_cache await asyncio.gather(*tasks) File ".../cptr/utils/agents/detection.py", line 690, in get_available_agent_model_entries status = await get_agent_status(app_state) File ".../cptr/utils/agents/detection.py", line 648, in get_agent_status detected = await detect_profile(profile) File ".../cptr/utils/agents/detection.py", line 267, in detect_profile models = await _probe_acp_models(command, profile, auth_method_id="oauth-personal") File ".../cptr/utils/agents/detection.py", line 589, in _probe_acp_models await client.close() File ".../cptr/utils/agents/acp.py", line 85, in close await task File ".../cptr/utils/agents/acp.py", line 183, in _reader_loop extracted = _extract_json_message(buffer) File ".../cptr/utils/agents/acp.py", line 261, in _extract_json_message return json.loads(line.decode()), buffer[line_end + 1 :] json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) **Root cause (confirmed via manual reproduction):** For the OpenCode profile type, cptr spawns: opencode serve --hostname=127.0.0.1 --port=<N> Running that exact command by hand shows opencode writes plain human-readable log lines to stdout on startup, not JSON: Warning: OPENCODE_SERVER_PASSWORD is not set; server is unsecured. opencode server listening on http://127.0.0.1:47645 cptr's _reader_loop/_extract_json_message appears to treat this subprocess's stdout as a newline-delimited JSON-RPC stream (the ACP convention used for other agent types), and immediately fails json.loads() on the first non-JSON line. This is reproducible even with a no-op stub binary named opencode on PATH that produces zero stdout output before exiting — json.loads("") throws the identical error, confirming this isn't about opencode's specific output but about cptr expecting JSON where serve mode never produces it. **Impact:** Any user with opencode installed and discoverable on PATH cannot start cptr at all — a single bad profile probe takes down the entire app during lifespan startup (asyncio.gather(*tasks) in warm_model_cache has no per-task error isolation, and detect_profile/_probe_acp_models don't catch JSONDecodeError). **Suggested fixes:** 1. Catch and isolate per-profile detection errors in warm_model_cache/get_available_agent_model_entries so one broken agent profile can't crash app startup. 2. For the OpenCode profile type specifically, don't reuse the ACP JSON-RPC stdout reader against opencode serve — its stdout is plain log text, not JSON-RPC; communication should happen over HTTP against the bound port instead.
Author
Owner

@owui-terminator[bot] commented on GitHub (Aug 14, 2026):

⚠️ Missing Issue Title Prefix

@Rory-Lambert, your issue title is missing a categorising prefix (e.g. bug:, feat:, docs:).

Please update the title to lead with one of:

  • bug: bug report or error
  • feat: feature request or enhancement
  • docs: documentation issue
  • question: usage question
  • help: support request

Example: bug: Login fails when the password contains special characters

<!-- gh-comment-id:5295713374 --> @owui-terminator[bot] commented on GitHub (Aug 14, 2026): # ⚠️ Missing Issue Title Prefix @Rory-Lambert, your issue title is missing a categorising prefix (e.g. `bug:`, `feat:`, `docs:`). Please update the title to lead with one of: - **bug**: bug report or error - **feat**: feature request or enhancement - **docs**: documentation issue - **question**: usage question - **help**: support request Example: `bug: Login fails when the password contains special characters`
Author
Owner

@owui-terminator[bot] commented on GitHub (Aug 14, 2026):

🔍 Related Issues Found

I found some existing issues that might be related. Please check if any of these are duplicates or contain helpful solutions:

  1. 🟢 #212 bug: opencode agent profiles never work — adapter requests OpenAPI operationIds as URL paths
    This issue is directly about opencode agent profiles failing in cptr. It shares the same subsystem and can be a downstream manifestation of opencode integration problems, though the failure mode here is prompt execution rather than startup detection.
    by ThalynLabs

💡 If your issue is a duplicate, please close it and add any additional details to the existing issue instead.

This comment was generated automatically. React with 👍 if helpful, 👎 if not.

<!-- gh-comment-id:5295715072 --> @owui-terminator[bot] commented on GitHub (Aug 14, 2026): <!-- terminator-bot:related-issues-reply --> 🔍 **Related Issues Found** I found some existing issues that might be related. Please check if any of these are duplicates or contain helpful solutions: 1. 🟢 [#212](https://github.com/open-webui/computer/issues/212) **bug: opencode agent profiles never work — adapter requests OpenAPI operationIds as URL paths** *This issue is directly about opencode agent profiles failing in cptr. It shares the same subsystem and can be a downstream manifestation of opencode integration problems, though the failure mode here is prompt execution rather than startup detection.* *by ThalynLabs* --- 💡 If your issue is a duplicate, please close it and add any additional details to the existing issue instead. *This comment was generated automatically.* React with 👍 if helpful, 👎 if not.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
open-webui/computer#134
No description provided.