Repository navigation
Description
Sessions permanently stuck during normal use — survive reboots, cannot be recovered
Description
Multiple sessions became permanently "stuck" (refusing new messages) during normal use. The stuck state persists across full system reboots and cannot be cleared by restarting the opencode server. The sessions are visible in the API and database, but any attempt to send a message to them silently fails. This is not triggered by a crash or power outage — sessions worked normally for days after the last known interruption, then suddenly became unresponsive.
Environment
- OpenCode version: 1.17.3
- OS: Linux (Debian/Ubuntu)
- Installation:
/home/dwc/.opencode/bin/opencode(156 MB binary) - Server mode:
opencode web --hostname 0.0.0.0(port 4096 with auth) - Database:
~/.local/share/opencode/opencode.db(776 MB, SQLite 3.x) - Models used: deepseek-v4-flash-free, mimo-v2.5-free (via opencode provider)
Affected Sessions
| Session ID | Title | Last Assistant Response | Last User Message | Messages |
|---|---|---|---|---|
ses_08513899fffe1yQ0ScYtryRBXN |
TTS-Ebook | 2026-08-13 20:32 UTC | 2026-08-17 13:43 UTC | 842 |
ses_0bc91dc31ffeBCZdqPJ2s02vYY |
Web2Epub | 2026-08-10 15:16 UTC | 2026-08-17 13:43 UTC | 2258 |
ses_1494d504dffeekKczywChTegQc |
Local machine and NAS | 2026-08-08 19:02 UTC | 2026-08-17 19:56 UTC | 847 |
Note: A power outage occurred on August 11, but all sessions continued to work normally for several days afterward (TTS-Ebook received a response as late as August 13, Web2Epub on August 10). The sessions appear to have gotten stuck during routine use around August 15–17, with no obvious trigger.
Steps to Reproduce
- Start opencode server and use it for several days across multiple sessions
- Sessions work normally across multiple sessions and days
- At some point during normal use, certain sessions silently become unresponsive
- New sessions work normally, but affected sessions cannot accept new messages
- Sending messages via CLI (
opencode run --session <id> --attach) produces no output - Sending messages via API POST returns HTML (web UI) instead of processing
- Full system reboot does not resolve the issue
- Killing and restarting the opencode server process does not resolve the issue
Investigation Findings
Database state
- Sessions are present in the
sessiontable with normal metadata - No
metadatafield set (null) — no explicit "busy" flag session_inputtable has 0 pending entries for affected sessionssession_messagetable has entries (model-switched, agent-switched) but no user messages after the stuck point- Events in the
eventtable show normalsession.updated.1as the last event type - No locks in
~/.local/state/opencode/locks/(directory is empty)
Token counts (possible factor?)
- TTS-Ebook: 3M input + 260K output + 419K reasoning tokens
- Web2Epub: 8.2M input + 615K output + 887K reasoning tokens
- Local machine and NAS: 4.5M input + 120K output + 99K reasoning tokens
What does NOT fix it
- Full system reboot (confirmed — user rebooted entire Linux box)
- Restarting opencode server process (
kill+ restart) - Setting
time_compactingon affected sessions in database - Setting
time_updatedto current timestamp in database
What works
opencode export <session_id>reads the full session data from the database — data is not lost- New sessions work normally
- The API can list sessions (
GET /api/session) — stuck sessions appear in the list - The API can read messages from stuck sessions (
GET /api/session/<id>/message)
Workaround
Export the stuck sessions before they become unrecoverable:
opencode export <session_id> > session-backup.jsonThen start fresh sessions and reference the exported file for context:
"Read /path/to/session-backup.json for context on this project"
Suggested Fixes
- Add a per-session timeout — if a session has been "busy" for >N hours with no active process, automatically reset its state on server startup
- Persist a "crashed" flag — when the server shuts down ungracefully, mark affected sessions so they can be recovered on next startup
- Add a CLI command to force-reset a stuck session:
opencode session reset <session_id> - The compact endpoint (
POST /api/session/<id>/compact) returns "not available yet" — implementing this would provide a recovery path
Logs
The opencode log at ~/.local/share/opencode/log/opencode.log shows normal activity for affected sessions up to the point they got stuck, then no further entries related to those sessions. No error messages or timeout warnings are logged.
Activity
github-actions commentedon Aug 18, 2026
This issue might be a duplicate of existing issues. Please check:
GET /session/statuscan report a sessionbusyfor a short window (and occasionally indefinitely) after its prompt stream has already closed #35472:GET /session/statuscan report a sessionbusyindefinitely after its prompt stream has already closed — documents the server-side mechanism by which sessions can get permanently stuck in a busy state with no recovery path.Your report has a distinct and valuable angle — the stuck state survives full system reboots, which points to a durable/database-level issue rather than an in-memory state problem. That detail (combined with the thorough DB investigation showing no pending
session_inputrows and no lock files) makes this worth tracking separately even if the root cause overlaps with the above.MilkyWay008 commentedon Aug 18, 2026
The absence of locks and any pending
session_inputis a good clue, it points to the stuck state riding on thesessionrow itself rather than a queued message, so dumping every column on those three ids is worth a look. Also at 776MB with a couple multi-million-token contexts, a wedged WAL can silently hold the table, aPRAGMA wal_checkpointorVACUUMon a copy often clears it. Theopencode exportroute is the right call to protect the data meanwhile.dcon4 commentedon Aug 22, 2026
Additional stuck session (Aug 22)
Another session stuck, same pattern — no lock files, no pending inputs, session visible in API but refuses to process new messages.
ses_fd681eba8ffeYeWKfmV9veW8Yystatus?)This session was created after the previous three stuck sessions (which were from Aug 8–13). It worked normally for ~8 hours on Aug 22, then got stuck. Same behavior: no error logged, no recovery on reboot, data is intact but session won't accept new messages.
This suggests the issue is not related to long-running sessions or high token counts — this session had modest usage and still got stuck within the same day.
dcon4 commentedon Aug 22, 2026
Update: Attempted database fix made things worse
I tried to unstick the session by editing the database directly:
"status": "running"state"status": "completed"and added a fake outputResult: Session became corrupted. Now returns
"Invalid prompt: The messages do not match the ModelMessage[] schema"on every new message.The stuck tool call was:
{ "type": "tool", "tool": "bash", "state": { "status": "running", "input": { "command": "chmod +x /home/dwc/Desktop/web2ebook/start.sh ...", "timeout": 10000 } } }Lesson learned: Direct database edits break the session schema validation. The fix needs to happen in opencode's code, not in the database.
This suggests the root cause is: when a tool call gets stuck in "running" state (e.g. process crashes or times out), opencode has no recovery path and the session becomes permanently broken.
dcon4 commentedon Aug 25, 2026
Additional stuck session (Aug 25)
Same pattern — bash tool call stuck in
"status": "running"state.ses_fd44430f8ffetvFGC7uzp4xFBe"status": "running", no completionNote: This is the replacement session after the previous one (
ses_fd681eba8ffeYeWKfmV9veW8Yy) got stuck and was corrupted by my attempted database fix. The new session also got stuck within ~45 hours of creation.Pattern is consistent: sessions get stuck when a bash tool call crashes or times out mid-execution. No recovery path exists — the session becomes permanently unusable.
dcon4 commentedon Aug 30, 2026
New stuck pattern: session ignores user messages entirely
Different from the previous stuck sessions (which had stuck tool calls). This session shows no stuck tool calls, no errors, but completely ignores user messages.
ses_105f90312ffeY73bBj0zI9sVOYBehavior
session_inputtabletime_updateddid not changeDatabase state
session_input: empty (0 pending)session_message: only has model-switched/agent-switched entries, no user messages after the stuck pointeventtable: last event issession.updated.1from the model switch~/.local/state/opencode/locks/Summary of all stuck patterns observed
Both patterns have no recovery path other than starting a new session.
dcon4 commentedon Aug 31, 2026
Additional stuck session: Research Reports
Same pattern as RemoteFix — session ignores user messages, no stuck tool calls.
ses_0ea4144aeffe45blZXcAQ0w78OPattern across all stuck sessions
Sessions affected:
ses_08513899fffe1yQ0ScYtryRBXN(old TTS-Ebook) — stuck Aug 17, tool call stuckses_0bc91dc31ffeBCZdqPJ2s02vYY(old Web2Epub) — stuck Aug 17, tool call stuckses_1494d504dffeekKczywChTegQc(old Local machine and NAS) — stuck Aug 17, tool call stuckses_fd681eba8ffeYeWKfmV9veW8Yy(old Web2Ebook - Linux) — stuck Aug 22, tool call stuckses_fd44430f8ffetvFGC7uzp4xFBe(Web2Ebook- Linux - new) — stuck multiple times, tool call stuckses_105f90312ffeY73bBj0zI9sVOY(RemoteFix) — stuck Aug 30, message ignoredses_0ea4144aeffe45blZXcAQ0w78O(Research Reports) — stuck Aug 31, message ignoredKey observations:
Log evidence
RemoteFix session shows "loop" and "exiting loop" events — opencode tried to process it but exited immediately without sending the message to the model:
This suggests the session enters a state where opencode detects it needs processing, starts a loop, but immediately exits without completing the work.
dcon4 commentedon Sep 7, 2026
Workaround found for stuck tool calls
The "tool call stuck in running" pattern has a root cause and a fix.
Root cause
A bash script used
execto start a daemon:exec /path/to/daemon.pyexecreplaces the shell process with the daemon. Since opencode's bash tool waits for the command to complete, and the daemon runs forever, the bash tool hangs forever. The session becomes permanently stuck.Fix
Replace
execwith background execution:This runs the daemon in the background and detaches it, so the bash tool exits cleanly.
Verification
After applying this fix:
Suggestion for opencode
Consider adding a timeout to bash tool execution, or detecting when a command uses
execand warning the user that it may cause the session to hang.dcon4 commentedon Sep 10, 2026
Update: Fix for exec not fully resolved
After fixing the
execissue in start.sh (replacing with&anddisown), the command still gets flagged as stuck by opencode's bash tool.What was fixed
What still happens
The command:
timeoutPossible causes
Suggestion
The bash tool should either:
setsidto create a new process group for background commands&anddisowndcon4 commentedon Sep 13, 2026
New stuck pattern: glob tool stuck in running state
A third stuck pattern has been observed — the
globtool (file pattern matching) stuck in"status": "running"state.ses_fac65f4ebffe8AZ7nFgr3oPkVsglob(file pattern matching)Behavior
Fix attempted
Deleted the stuck glob part from the database. Session structure was not corrupted (unlike previous bash tool fix attempts).
Updated summary of stuck patterns
execin scripts causes bash tool to hang forever (3+ sessions)All three patterns have no automatic recovery and require either server restart or database intervention.
dcon4 commentedon Sep 13, 2026
Custom Linux session also stuck ("session ignores user messages" pattern)
The Custom Linux session (
ses_fac65f4ebffe8AZ7nFgr3oPkVs) is now stuck with the second pattern.Timeline
globtool callUpdated pattern count
execto&anddisown)The glob tool issue may be a trigger for the "session ignores messages" pattern — once the session gets into a bad state from a stuck tool, it never recovers even after the stuck tool is removed.
dcon4 commentedon Sep 13, 2026
Update: Completed bash commands stuck in "running" state
Additional finding — commands that completed successfully are still shown as "running" by the bash tool.
Evidence
This session (`ses_fed9937acffevoWSMgWVkObvfJ") has 6 stuck bash tool calls, all of which were completed by the agent during this conversation:
kill -9 1090— server restart attempt (completed)pkill -f "opencode web"— server restart attempt (completed)3-6. Multiple restart and database check commands (all completed)
All commands produced output and the session continued working. But the bash tool still shows them as "running".
Key insight
This is not just about
execor background processes. Any bash command can get stuck in "running" state after completion. The bash tool's completion detection is broken.Impact
Affected interface
User is using OC Remote interface app. May be relevant to how the interface detects command completion.
dcon4 commentedon Sep 13, 2026
Update: Custom Linux session stuck again
Same session (
ses_fac65f4ebffe8AZ7nFgr3oPkVs), third time stuck.Pattern confirmed
Workaround
Run this to delete stuck parts:
Then restart the opencode server.
Note
This workaround only works if the session hasn't been corrupted by previous edits. If it returns "messages do not match ModelMessage[] schema", the session is permanently broken.
dcon4 commentedon Sep 13, 2026
Critical: Restarting opencode via bash tool requires full CPU reboot
Problem
When the agent tries to restart the opencode web server using the bash tool:
The command completes but opencode becomes unresponsive. A full CPU reboot is required to recover.
Reproduction
Affected sessions
Impact
Suggestion
opencode should:
dcon4 commentedon Sep 17, 2026
New stuck pattern: question and task tools
A fourth stuck pattern — the
questionandtasktools stuck in "running" state.ses_0df853b59ffe9fM31areg77Qr1questiontool andtasktoolBehavior
Fix
Deleted the stuck parts from the database. Session became responsive again.
Updated pattern count
execto&)Key finding
Any tool type can get stuck in "running" state — bash, glob, question, task. The issue is not tool-specific. The bash tool's completion detection is broken across all tool types.
thdxr commentedon Oct 11, 2026
Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (
opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊