-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Description
Plugins
None
OpenCode version
1.1.53
Steps to reproduce
No response
Screenshot and/or share link
n/a
Operating System
Fedora 43
Terminal
Bash
Description
I have been using opencode to create a wrapper for opencode (integrating into a tool I'm building) and was attempting to use event based processing of data in sessions, since generating can take a fair amount of time. (and running async was experiencing timeouts). I tested multiple approaches and the determination of claude sonnet 4.5 is that the /session/status is not returning values that align with the documentation. I had it write some test scripts which appear to confirm this.
System Information:
OpenCode 1.1.53
Development/diagnosis done within OpenCode
Running opencode serve
Opencode error:
^
TypeError: undefined is not an object (evaluating 'agent.model')
at createUserMessage (src/session/prompt.ts:830:34)
825 | }
826 |
827 | async function createUserMessage(input: PromptInput) {
828 | const agent = await Agent.get(input.agent ?? (await Agent.defaultAgent()))
829 |
830 | const model = input.model ?? agent.model ?? (await lastModel(input.sessionID))
^
TypeError: undefined is not an object (evaluating 'agent.model')
at createUserMessage (src/session/prompt.ts:830:34)
I'm not sure if the error above is related to what is described below, disregard it if it is not relevant.
Following is my AI agent's summary of the perceived bug. I can't personally guarantee that this is accurate, but it seems plausible and I haven't found any other resolutions.
--------- End User Generated Content -----------
(AI-Generated) Bug Report: OpenCode Server Loses Track of Asynchronous Sessions
Summary
When a client sends an asynchronous command to the OpenCode server (via the /session/{session_id}/prompt_async endpoint), the server appears to lose track of the session's state. The session's status is not correctly reported via the /session/status endpoint, and subsequent synchronous commands to the same session fail to execute correctly. This prevents clients that rely on the server's event and status system from working as expected.
Steps to Reproduce
- Create a new session: Send a
POSTrequest to/sessionto create a new session. - Send an asynchronous command: Send a
POSTrequest to/session/{session_id}/prompt_asyncwith a command to execute (e.g.,git status). - Poll for session status: Periodically send
GETrequests to/session/statusto check the status of the created session. - Send a synchronous command: After a short period, send a
POSTrequest to/session/{session_id}/messagewith a new command.
Expected Behavior
- After the asynchronous command is sent, the session status reported by
/session/statusshould bestreamingor a similar active state, and eventually transition toidleonce the command is complete. - The server should emit a
session.status_changedevent via its Server-Sent Events (SSE) stream, indicating the transition toidle. - Subsequent synchronous commands to the session should execute correctly and return the command's output.
Actual Behavior
- The status of the session, as reported by
/session/status, remainsunknownindefinitely. The server never reports the session asstreamingoridle. - No
session.status_changedevent is ever received for the session. - Subsequent synchronous commands sent to the session return an immediate, empty response instead of executing and returning the command's output.
Evidence
The following is the output of a test script that automates the reproduction steps:
'''
Creating session '''Bug Reproduction Test'''...
-> Session created with ID: ses_3c4d71dd0ffekqdJDOmP4F2CbK
Sending async command: '''git status'''
-> Async prompt sent (status: 204)
Polling session status every 2s for 30s...
[0.0s] Current status: '''unknown'''
[2.0s] Current status: '''unknown'''
[4.0s] Current status: '''unknown'''
[6.0s] Current status: '''unknown'''
[8.0s] Current status: '''unknown'''
[10.0s] Current status: '''unknown'''
[12.0s] Current status: '''unknown'''
[14.0s] Current status: '''unknown'''
[16.0s] Current status: '''unknown'''
[18.0s] Current status: '''unknown'''
[20.0s] Current status: '''unknown'''
[22.0s] Current status: '''unknown'''
[24.0s] Current status: '''unknown'''
[26.0s] Current status: '''unknown'''
[28.0s] Current status: '''unknown'''
Polling timed out. Session did not become idle.
-> Final status after timeout: '''unknown'''
-> CONFIRMED: Server lost track of the session status.
Attempting to send sync command: '''echo 'hello'''' (expecting a timeout)
-> Received a response unexpectedly:
--- Test Summary ---
The test successfully reproduced the bug.
- An async command was sent.
- The server lost track of the session's status, which remained 'unknown'.
- A subsequent synchronous command to the same session returned an immediate empty response.
This confirms the opencode-server is not correctly handling these sessions.