You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[WEB] Question tool is not available immediately #20514
When running opencode serve, the question tool is not exposed to web interface clients on initial connection. However, after attaching a TUI client (opencode attach), the tool becomes available to all clients including web.
Root Cause Analysis
Root Cause
The ToolRegistry in packages/opencode/src/tool/registry.ts evaluates the question tool's availability at cache initialization time (in the all() function) rather than at request time (in ids() and tools() methods).
The all() function uses Effect's InstanceState scoped caching mechanism. When the first web client connects, the tool list is cached with the Flag.OPENCODE_CLIENT evaluation occurring during this initialization. Due to how the web client's request context is established, this flag evaluation happens incorrectly or in an incomplete context, causing the question tool to be excluded from the cached tool list.
When a TUI client attaches via opencode attach, it triggers Instance.provide() with proper InstanceBootstrap, which refreshes or invalidates the cache. Subsequent requests then receive the correct tool list including question.
constall=Effect.fn('ToolRegistry.all')(function*(custom: Tool.Info[]){constcfg=yield*config.get();constquestion=['app','cli','desktop'].includes(Flag.OPENCODE_CLIENT)||Flag.OPENCODE_ENABLE_QUESTION_TOOL;// ^ Evaluated at cache init time, not per-request!return[InvalidTool,
...(question ? [QuestionTool] : []),// Cached incorrectly for web clients// ... other tools];});
Plugins
OpenCode version
v1.3.12
Steps to reproduce
Start OC in server mode opencode serve --port 1234
Open web interface in a browser (do not yet attach TUI)
Create a new session and ask: "Do you have the question tool available?" and verify no question tool available
Attach TUI to same server opencode attach http://localhost:1234
Ask same question in the same session and now question tool is magically available
constids=Effect.fn('ToolRegistry.ids')(function*(){consts=yield*InstanceState.get(state);consttools=yield*all(s.custom);// Evaluate at request time, not cache time!constquestion=['app','cli','desktop'].includes(Flag.OPENCODE_CLIENT)||Flag.OPENCODE_ENABLE_QUESTION_TOOL;returntools.filter((t)=>t.id!=='question'||question).map((t)=>t.id);});
3. Modify tools() function (around line ~173)
Add dynamic filtering at request time:
consttools=Effect.fn('ToolRegistry.tools')(function*(model: {providerID: ProviderID;modelID: ModelID},agent?: Agent.Info,){consts=yield*InstanceState.get(state);constallTools=yield*all(s.custom);// Evaluate at request timeconstquestion=['app','cli','desktop'].includes(Flag.OPENCODE_CLIENT)||Flag.OPENCODE_ENABLE_QUESTION_TOOL;constfiltered=allTools.filter((tool)=>{if(tool.id==='question')returnquestion;// Dynamic checkif(tool.id==='codesearch'||tool.id==='websearch'){returnmodel.providerID===ProviderID.opencode||Flag.OPENCODE_ENABLE_EXA;}constusePatch=model.modelID.includes('gpt-')&&!model.modelID.includes('oss')&&!model.modelID.includes('gpt-4');if(tool.id==='apply_patch')returnusePatch;if(tool.id==='edit'||tool.id==='write')return!usePatch;returntrue;});// ... rest of method});
Summary of Changes
Before:Flag.OPENCODE_CLIENT evaluation happens at InstanceState initialization → cached → wrong result for early web clients
After:Flag.OPENCODE_CLIENT evaluation happens at each API request → always fresh → correct result for all clients
NOTE: This was analyzed and generated by Kimi K2.5 without any manual cross checking
Activity
gund commentedon Apr 1, 2026
If you are interested: Suggested Fix
Suggested Fix
Move the
questiontool filtering from cache-time to request-time:File:
packages/opencode/src/tool/registry.ts1. Modify
all()function (lines ~119-148)Remove the conditional and always include
QuestionTool:2. Modify
ids()function (around line ~165)Add dynamic filtering at request time:
3. Modify
tools()function (around line ~173)Add dynamic filtering at request time:
Summary of Changes
Flag.OPENCODE_CLIENTevaluation happens atInstanceStateinitialization → cached → wrong result for early web clientsFlag.OPENCODE_CLIENTevaluation happens at each API request → always fresh → correct result for all clientsNOTE: This was analyzed and generated by Kimi K2.5 without any manual cross checking
rekram1-node commentedon Jun 23, 2026
Automated: closing question issues.
GitHub Issues are for bug reports and feature requests only — questions / support are no longer tracked here.
If this is a bug or feature request, please open a new issue with the appropriate template.
rekram1-node commentedon Jun 23, 2026
Reopening – this was incorrectly closed by automated question-issue cleanup. Sorry for the noise.
github-actions commentedon Aug 23, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.