Skip to content

Conversation

@shetty4l
Copy link

@shetty4l shetty4l commented Jan 11, 2026

What does this PR do?

Fixes #7789

Observations:

  • opencode run exits with error since it runs on the main thread
  • opencode runs the TUI on the main thread and spawns worker threads for the core business logic

Alternatives Considered

  • Fix RPC error propagation globally - Add try/catch to Rpc.listen() and introduce a new rpc.error message type. Rejected because it required changes to the RPC protocol and didn't seem like that was in scope
  • Validate config syntax on main thread before spawning worker - Parse config files early in TuiThreadCommand.handler() before the worker starts. Rejected because config loading is tightly coupled to Instance.state() which requires the worker context, and duplicating the file search logic would be heavy.
  • Move config loading to main thread entirely - Load config before spawning the worker. Rejected because the worker architecture exists for a reason (manages multiple instances, server, LSP, file watchers) and config is instance-specific.

Proposed Solution

Update the subscription logic for the TUI to handle the case where the worker returns result.subscribed = false instead of always returning true. If result.subscribed == false, we handle ConfigJsonError and ConfigInvalidError and propagate that error higher up the call stack.

How did you verify your code works?

  • Added a new "unit" test (is it really unit if it spins up the whole application?)
  • Manual testing:
$ opencode --version                                                                                                                                                                                                          1.1.13
$ timeout 5 ./opencode-7789; [ $? -eq 124 ] && echo "Bug: OpenCode hung and was killed after 5s"
Bug: OpenCode hung and was killed after 5s
$ timeout 5 ./opencode-7789; [ $? -eq 124 ] && echo "Bug: OpenCode hung and was killed after 5s" # Locally built binary
Error: Config file at /private/tmp/oc-7789/opencode.json is not valid JSON(C):
--- JSONC Input ---
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "example" : {
      "type": "local"
      "enabled": true,
      "command" : ["echo", "'Hello World'"]
    },
  }
}

--- Errors ---
CommaExpected at line 6, column 7
   Line 6:       "enabled": true,
                ^
--- End ---

@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

@shetty4l shetty4l marked this pull request as ready for review January 11, 2026 17:21
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.

Syntax error in opencode.json will cause opencode startup to hang indefinitely

1 participant