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
Cross-process session concurrency: two processes can run loops on the same session simultaneously #49367
\packages/opencode/src/session/run-state.ts\ keeps its per-session Runner map in \InstanceState\ — in-memory, per-process. When two opencode processes share the same session database (e.g., a TUI and a headless \opencode serve, or two TUI windows), both can start agent loops on the SAME session concurrently, producing interleaved parts from two different message streams.
Reproduction
Open a TUI attached to session X
Start \opencode serve --port N\ on the same project
POST to /session/X/message on the serve port while the TUI is mid-turn
Both processes run loops on session X simultaneously — interleaved step-start/step-finish parts from different runs
Evidence
From opencode.log, two concurrent run IDs (3f40dbfe and 20413a5b) produced interleaved loop/process/stream lines on the same session for 16 minutes.
Proposed fix
Persist the runner state (a DB-level lease or advisory lock keyed by session ID) so only one process may run a loop on a session at a time. The second process should either join the running loop or queue until it finishes.
Impact
Interleaved parts from concurrent loops create confusing output, phantom assistant messages responding to partial state, and data corruption risk when both loops write to the same message rows.
If your issue is distinct from these (e.g. specific to the opencode serve + TUI combination or the interleaved parts symptom), please clarify the difference.
Thanks for the detailed report and the log evidence.
The code you point to (packages/opencode/src/session/run-state.ts) is OpenCode v1 (opencode-ai, versions 0.x/1.x). v1 now only gets fixes for critical bugs such as data loss, security problems or crashes with no workaround. Running two processes on the same session gives confusing interleaved output, but you can avoid it by sending prompts to a session from only one process at a time. So this is unlikely to be fixed in v1. That is also why your PR #50968 was closed.
We'd encourage you to upgrade to v2 (@opencode/cli). Note that v2 has a similar cross-process problem, already tracked here:
If you're seeing this on v2, please add your details to #43648. If you think the v1 behaviour is critical, for example because it actually loses data rather than just interleaving output, reply here and explain.
We haven't heard back, so I'm closing this as not planned. The report is about v1 (packages/opencode/src/session/run-state.ts), and v1 now only gets fixes for critical bugs. Here you can avoid the problem by sending prompts to a session from only one process at a time.
If you see the same thing on v2 (@opencode/cli), please follow #43648, which tracks overlapping runs on one session across processes sharing a database, and add your details there. Related: #53146 and #51411. If you think the v1 behaviour causes real data loss, reply here and explain.
Activity
github-actions commentedon Sep 16, 2026
This issue might be a duplicate of existing issues. Please check:
opencode run --continueinjects prompt into a session actively in use by another instance — same root cause, no in-use check existsSQLITE_BUSY— same two-process-on-one-DB scenarioIf your issue is distinct from these (e.g. specific to the
opencode serve+ TUI combination or the interleaved parts symptom), please clarify the difference.fix(opencode): run one session loop at a time across processes
fix(opencode): run one session loop at a time across processes
opencodejr commentedon Oct 28, 2026
Thanks for the detailed report and the log evidence.
The code you point to (
packages/opencode/src/session/run-state.ts) is OpenCode v1 (opencode-ai, versions 0.x/1.x). v1 now only gets fixes for critical bugs such as data loss, security problems or crashes with no workaround. Running two processes on the same session gives confusing interleaved output, but you can avoid it by sending prompts to a session from only one process at a time. So this is unlikely to be fixed in v1. That is also why your PR #50968 was closed.We'd encourage you to upgrade to v2 (
@opencode/cli). Note that v2 has a similar cross-process problem, already tracked here:opencode.dbcauseUNIQUE(seq)collisionsIf you're seeing this on v2, please add your details to #43648. If you think the v1 behaviour is critical, for example because it actually loses data rather than just interleaving output, reply here and explain.
opencodejr commentedon Oct 29, 2026
We haven't heard back, so I'm closing this as not planned. The report is about v1 (
packages/opencode/src/session/run-state.ts), and v1 now only gets fixes for critical bugs. Here you can avoid the problem by sending prompts to a session from only one process at a time.If you see the same thing on v2 (
@opencode/cli), please follow #43648, which tracks overlapping runs on one session across processes sharing a database, and add your details there. Related: #53146 and #51411. If you think the v1 behaviour causes real data loss, reply here and explain.