[PR #7737] feat(opencode): enhance TUI Thread Init & RPC error handling #12495

Closed
opened 2026-02-16 18:17:24 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/7737

State: closed
Merged: No


What does this PR do?

Closes #7693

When starting the TUI, thread.ts creates a worker and calls client.call("subscribe", { directory: cwd }). This triggers rpc.subscribe in the worker, which calls Instance.provide() → InstanceBootstrap() → Plugin.init() → Config.get() → Config.state() → loadAgent().

If loadAgent() throws an error due to a bad markdown:

Previously: Rpc.listen had no try/catch, so the error became an unhandled rejection caught only by the worker's process.on("uncaughtException"). No response was ever sent back. The client's promise from client.call() was never resolved or rejected, so it hung forever.

With PR: Rpc.listen catches the error, serializes it, and sends an rpc.error message back. The client receives this, rejects the promise, and the error propagates up to the catch block in index.ts where FormatError() displays it to the user.

How did you verify your code works?

Tested it with an agent MD file similar to the one the user had an error with in #7693 just adding an invalid trailing comma. Now the error is logged and the TUI is exited, rather than hanging previously. Ideally this should fix any other error that gets thrown on startup.

Screenshot 2026-01-11 at 03 33 28
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/7737 **State:** closed **Merged:** No --- ### What does this PR do? Closes #7693 When starting the TUI, `thread.ts` creates a worker and calls client.call("subscribe", { directory: cwd }). This triggers `rpc.subscribe` in the worker, which calls Instance.provide() → InstanceBootstrap() → Plugin.init() → Config.get() → Config.state() → loadAgent(). If loadAgent() throws an error due to a bad markdown: **Previously**: Rpc.listen had no try/catch, so the error became an unhandled rejection caught only by the worker's process.on("uncaughtException"). No response was ever sent back. The client's promise from client.call() was never resolved or rejected, so it hung forever. **With PR**: Rpc.listen catches the error, serializes it, and sends an rpc.error message back. The client receives this, rejects the promise, and the error propagates up to the catch block in index.ts where FormatError() displays it to the user. ### How did you verify your code works? Tested it with an agent MD file similar to the one the user had an error with in #7693 just adding an invalid trailing comma. Now the error is logged and the TUI is exited, rather than hanging previously. Ideally this should fix any other error that gets thrown on startup. <img width="798" height="197" alt="Screenshot 2026-01-11 at 03 33 28" src="https://github.com/user-attachments/assets/e82b90e4-1ec3-4886-aa90-5bf73ffe132d" />
yindo added the pull-request label 2026-02-16 18:17:24 -05:00
yindo closed this issue 2026-02-16 18:17:24 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12495