OpenCode Desktop V2: /goal >60s triggers false 'Timed out waiting for the server to respond' toast and restores input box while goal is running
Hi @danyel117! First of all, thank you so much for the super fast turnaround on #110 (PR #116) — that makes human-in-the-loop pauses on V2 so much smoother.
While running V2 /goal <objective> in OpenCode Desktop (macOS GUI / Web UI), we ran into a 100% reproducible bug where every /goal <objective> run that lasts longer than 60 seconds triggers a false-positive command failure toast and restores the /goal ... text back into the composer input box, even though the goal prompt was already admitted and the agent is actively executing tools in the background.
(Note: as with #110, this issue write-up and root-cause trace were drafted with the help of my AI coding assistant from our live session debugging, and I'm also opening a companion PR in case the proposed fix is helpful!)
Symptoms & Screenshots (OpenCode Desktop V2)
-
At the 60-second mark after sending
/goal <objective>, OpenCode Desktop pops up a red error toast:发送命令失败: Timed out waiting for the server to respond(Failed to send command: Timed out waiting for the server to respond)
-
The composer restores
/goal <objective>back into the input box as if the submission failed, while the session indicator right above it says工作中(Working...):
-
Meanwhile, in the session transcript, the expanded
/goalprompt was already admitted atT+0sand the agent has already executedget_goal,create_goal,Shell, etc.:
Because the /goal ...text is put back into the input box, users naturally think the message was intercepted/dropped and press Enter again, accidentally firing a duplicate/goalwhile the first one is mid-flight.
Root Cause (3-Layer Interaction between Plugin, OpenCode Server, and OpenCode Desktop)
We traced this across @prevalentware/opencode-goal-plugin (src/server.ts) and anomalyco/opencode (packages/app & packages/server):
1. Plugin layer (src/server.ts:3420-3438)
In setupV2, when pursue is true (/goal <objective>, /goal resume, or /resume_goal), command.execute first calls await context.session.prompt(...) (admitted = true), and then holds the command.execute Promise open across the entire multi-turn goal lifecycle via do { await context.session.wait({ sessionID: input.sessionID }, { signal }); ... } while (...).
- As documented in
README.md(Zed and ACP lifecycle boundaries) and PRs #65 / #67 (for #59) +anomalyco/opencode#53913, this was added soopencode acpkeepsturn.commandFinishedpending until all auto-continuations finish.
2. OpenCode Server layer (packages/server/src/handlers/session.ts:327-339)
POST /api/session/:sessionID/command awaits the plugin's command.execute callback before sending the 204 No Content response headers. (By contrast, OpenCode's built-in /init and /review commands only await session.prompt(...) and return 204 immediately.)
3. OpenCode Desktop / Web frontend layer (packages/app)
- 60s response-headers timeout + queue slot exhaustion:
packages/app/src/runtime/server/request-queue.ts:21, 150-158wraps all non-SSE requests in a 4-slot queue (requestQueueLimit = 4) with a hardrequestHeadersTimeoutMs = 60_000(60 seconds) timer (onlyPOST /api/worktreeis exempted). While/goalis running,POST /api/session/:sessionID/commandoccupies 1 of the 4 browser request slots and aborts at 60s withnew DOMException("Timed out waiting for the server to respond", "TimeoutError"). - Why
failSubmissionrestores the input box on/commandbut not/prompt: Inpackages/app/src/composer/submit.ts:229-231, 644-660:
Forfunction failSubmission(input, session, kind, error, restore, messageID) { if (messageID && session.admitted(messageID)) return restore() input.notify.failed(kind, error) }sendPrompt(POST /api/session/:sessionID/prompt), the client sends its generatedid(messageID), so once SSE confirms the message,session.admitted(messageID)istrueand any later timeout is ignored. However,sendCommand(POST /api/session/:sessionID/command) does not accept a clientidin its protocol schema, andcontext.session.prompt(...)inside the plugin generates a brand-new server-side message ID. Thereforesession.admitted(messageID)is alwaysfalsefor plugin commands, causingfailSubmissionto restore the composer input and show the failure toast at 60s.
4. Secondary hazard once anomalyco/opencode#53913 lands
Once anomalyco/opencode#53913 forwards the HTTP request abort signal to execution.signal:
- At 60 seconds,
request-queue.tsaborts the HTTP request withDOMException("Timed out waiting for the server to respond", "TimeoutError"). - In
src/server.ts:446-455,isTransportAbortReason(reason)matches/socket|disconnect|connection|closed|eof|reset|broken pipe|request aborted|client closed/i, which does not match"Timed out waiting for the server to respond"/"TimeoutError". - As a result, at the 60-second mark, the Desktop frontend timeout would be treated as an explicit user cancellation and kill the active goal!
Proposed Fix (Preserving Zed ACP 100% while fixing Desktop / Web / TUI)
Looking at how anomalyco/opencode spawns ACP vs Desktop/Web/TUI:
opencode acp(packages/cli/src/commands/handlers/acp.ts:24-25) setsprocess.env.OPENCODE_CLIENT = "acp"at entry and always spawns an isolatedserve --stdio --port 0subprocess (packages/cli/src/services/standalone.ts:17-33). It never shares the backgroundopencode serve --servicedaemon.- Desktop (
OPENCODE_CLIENT = "desktop"), Web, and TUI (OPENCODE_CLIENT = undefinedor"desktop") subscribe to/api/eventSSE streams directly and do not rely on holdingPOST /api/session/:sessionID/commandopen across auto-continuations.
So we can gate the command-level session.wait loop (while keeping the 1-second session.wait idle barrier inside runAutoContinue at src/server.ts:2714 intact for all clients):
function shouldHoldCommandExecution(options: GoalPluginOptions = {}): boolean {
if (typeof options.wait_for_command === "boolean") {
return options.wait_for_command
}
return process.env.OPENCODE_CLIENT === "acp"
}
And also include timeout|timed out|timeouterror in isTransportAbortReason so any proxy/client HTTP timeout never masquerades as a deliberate user cancellation.
I'll open a small PR shortly with this change and unit tests so you can inspect or tweak it however you see fit!
Hi, I’m a student and an independent DIY developer who enjoys experimenting with OpenCode. I’d love to contribute to the design, bug fixing, and optimization of this project. While building and testing some ideas of my own, I encountered a few issues when using /goal. I’d really appreciate any advice or guidance you could provide. I’d be happy to work on a PR to fix these issues, and if possible, I’d also appreciate it if you could review my changes. The PR linked above was opened by my AI coding assistant based on our debugging session. Please feel free to take a look when you have time. Thank you very much!
If you notice any problems, please feel free to point them out. And if you feel that my implementation could be improved, or if you would prefer to implement the fix yourselves, that’s completely fine as well. You can close this PR and leave me a comment with your feedback.