@opencode-ai/sdk: Tools intermittently fail to load (0 tools) when using createOpencodeServer #4286

Open
opened 2026-02-16 17:43:17 -05:00 by yindo · 0 comments
Owner

Originally created by @kevoconnell on GitHub (Jan 6, 2026).

Originally assigned to: @thdxr on GitHub.

Description

When using @opencode-ai/sdk to spawn an OpenCode server programmatically via createOpencodeServer(), tools intermittently fail to load. The same deployment and code will sometimes load 120 tools successfully, and other times show 0 tools. There's no apparent pattern - it's a race condition. This might also be partly in due to the Trigger config, but thought I would flag here also.

Environment

  • OpenCode SDK version: 1.0.223
  • OpenCode server version: 1.1.3 (from health check)
  • Platform: Linux x64 (containerized environment)
  • Node version: 20.x

Steps to reproduce

  1. Use createOpencodeServer() to start the server (within a trigger.dev task)
  2. Call client.tool.ids() after server starts
  3. Run multiple times - some succeed, some fail

Logs

Successful run:

[OpenCode] Server started at http://127.0.0.1:4096
[OpenCode] Health check: {"healthy":true,"version":"1.1.3"}
[OpenCode] Listed 120 tools in 3ms
[OpenCode] Prompt completed in 4.2s

Failed run (same code, different execution):

[OpenCode] Server started at http://127.0.0.1:4096
[OpenCode] Health check: {"healthy":true,"version":"1.1.3"}
[OpenCode] Tools available immediately after start: 0
[OpenCode] Prompt completed in 0.1s

Workaround attempted

Added retry logic to poll client.tool.ids() with 300ms delays (10 attempts), but if tools don't load on first check, they never appear even after retrying.

Expected behavior

client.tool.ids() should consistently return all available tools after the server reports healthy.

Question

Is there an event or API to wait for tools to be fully indexed before querying? Or a known race condition during server startup?

Originally created by @kevoconnell on GitHub (Jan 6, 2026). Originally assigned to: @thdxr on GitHub. ### Description When using `@opencode-ai/sdk` to spawn an OpenCode server programmatically via `createOpencodeServer()`, tools intermittently fail to load. The same deployment and code will sometimes load 120 tools successfully, and other times show 0 tools. There's no apparent pattern - it's a race condition. This might also be partly in due to the [Trigger](https://trigger.dev/) config, but thought I would flag here also. ### Environment - **OpenCode SDK version:** 1.0.223 - **OpenCode server version:** 1.1.3 (from health check) - **Platform:** Linux x64 (containerized environment) - **Node version:** 20.x ### Steps to reproduce 1. Use `createOpencodeServer()` to start the server (within a trigger.dev task) 2. Call `client.tool.ids()` after server starts 3. Run multiple times - some succeed, some fail ### Logs **Successful run:** ``` [OpenCode] Server started at http://127.0.0.1:4096 [OpenCode] Health check: {"healthy":true,"version":"1.1.3"} [OpenCode] Listed 120 tools in 3ms [OpenCode] Prompt completed in 4.2s ``` **Failed run (same code, different execution):** ``` [OpenCode] Server started at http://127.0.0.1:4096 [OpenCode] Health check: {"healthy":true,"version":"1.1.3"} [OpenCode] Tools available immediately after start: 0 [OpenCode] Prompt completed in 0.1s ``` ### Workaround attempted Added retry logic to poll `client.tool.ids()` with 300ms delays (10 attempts), but if tools don't load on first check, they never appear even after retrying. ### Expected behavior `client.tool.ids()` should consistently return all available tools after the server reports healthy. ### Question Is there an event or API to wait for tools to be fully indexed before querying? Or a known race condition during server startup?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#4286