Skip to content

fix: add timeout to opencode connection testing#261

Merged
dimavedenyapin merged 1 commit intomainfrom
fix/opencode-connection-timeout
Apr 20, 2026
Merged

fix: add timeout to opencode connection testing#261
dimavedenyapin merged 1 commit intomainfrom
fix/opencode-connection-timeout

Conversation

@dimavedenyapin
Copy link
Copy Markdown
Contributor

@dimavedenyapin dimavedenyapin commented Apr 20, 2026

Summary

The OpenCode server (TypeScript, not Go) lazily initializes InstanceState (providers, models, auth) on the first request that touches instance routes — not at server startup. The SDK's createOpencode resolves as soon as the server prints "listening", before providers are loaded.

Our adapter called config.update() (with noTimeoutFetch = infinite timeout) in three places, each triggering this lazy init:

  1. ensureServerRunning — config push with auth.json keys
  2. createSession — plugin registration
  3. resumeSession — plugin registration

The lazy init involves network calls (models.dev/api.json, plugin auth loaders for custom providers like routerai.ru, api.featherless.ai) that can block for minutes on slow networks. With infinite timeout on all SDK calls, both the Settings → Agents "Testing connection..." and the transcript session startup would hang indefinitely.

Changes

  • Add quickClient with 15s timeout for health checks, provider listing, and config queries
  • Make all 3 config.update() calls fire-and-forget — they trigger the expensive lazy init but don't need to block session startup or connection testing
  • UI: treat null provider result as "connected" — health check already passed, provider counts show 0 until server finishes loading

Root cause confirmed from source

Test plan

  • Settings → Agents: "Testing connection..." resolves within ~15s (shows "Connected" even if providers still loading)
  • Start a new task with OpenCode agent: transcript appears quickly without minutes of empty spinner
  • Resume an existing session: loads without minutes of delay
  • Agent prompts still work correctly (they use the separate sharedClient with no timeout)
  • Secret injection plugin still works after fire-and-forget registration

🤖 Generated with Claude Code

…te hangs

The sharedClient used noTimeoutFetch (infinite timeout) for all operations
including config.providers() and config.update() calls during connection
testing. This caused "Testing connection..." to hang for minutes when the
opencode server was slow to respond. Add a separate quickClient with 15s
timeout for health checks, provider listing, and config push operations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dimavedenyapin dimavedenyapin merged commit 4a9c8fd into main Apr 20, 2026
1 check passed
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.

1 participant