@opencode-ai/sdk: Tools intermittently fail to load (0 tools) when using createOpencodeServer
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
- Use
createOpencodeServer()to start the server (within a trigger.dev task) - Call
client.tool.ids()after server starts - 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?