anomalyco / anomalyco/opencode
tui: stale subagent sessions cause SessionNotFoundError unhandled rejection bursts
Open
@kommander is already working on this.
Since Sep 5, 2026.
2.0
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Summary
Multiple TUI clients spam SessionNotFoundError unhandled rejections for the same stale subagent session IDs, and concurrent session.json writes fail with Windows EPERM rename errors.
Environment
- opencode version: v0.0.0-beta-19151
- OS: Microsoft Windows NT 10.0.26200.0 (win32 x64)
- Terminal: Unavailable: terminal environment variables are not set
- Shell: C:\Windows\system32\cmd.exe
- Install/channel: beta
- Active plugins: local file
openrouter-retry-guard.tsunder~/.config/opencode/plugin/; nopluginentries in~/.config/opencode/opencode.json(providerorproxyconfigured)
Reproduction
- Open several
opencodeTUI clients with no args against the same background service. - View a session containing
Tasksubagent tool parts whosemetadata.sessionIdpoints to sessions absent fromsession_v2(deleted, never projected, or from another directory). - Each client calls
sync.session.sync(subagentSessionID), which usesthrowOnError: trueand throwsSession not found: ses_.... - The
Taskcomponent fires this asvoid sync.session.sync(sessionID)with no catch, producing oneunhandled rejectionper client per stale session. - At the same time, concurrent
session.jsonpinned-state writes collide on Windows rename.
Expected Behavior
Stale/missing subagent sessions should be pruned/ignored quietly: no unhandled rejections, no error burst across clients. Local session.json writes should tolerate concurrent writers.
Actual Behavior
Burst at 2026-09-05T11:11:49Z, one per CLI run ID per stale session:
unhandled rejection cause._tag=SessionNotFoundError cause.sessionID=ses_f8ebc4acdffeZcKq6Tl4hKag8F cause.message="Session not found: ses_f8ebc4acdffeZcKq6Tl4hKag8F" role=cli
Server returns 404 for the same IDs, e.g. GET /api/session/ses_f8ebc4acdffeZcKq6Tl4hKag8F 404, plus:
unhandled rejection cause="Error: EPERM: operation not permitted, rename '...\\session.json.<pid>.<uuid>.tmp' -> '...\\session.json'" role=cli
Additional Context
- Frequency: reproducible burst whenever stale subagent IDs are rendered; seen for
ses_f8ebc4acdffeZcKq6Tl4hKag8F,ses_f8ec43de4ffe0hEYUORBF4cIXU,ses_f8ec7b520ffe70bI7626Titf1k,ses_f8eccfda2ffeLJbQHoTfomFavs. - Checked
opencode.db:session_v2had 5 rows; the failing IDs were absent. - Suspected read-path gap (creation-race fixes do not cover reads):
packages/tui/src/context/sync.tsxsync()throws on 404;packages/tui/src/routes/session/index.tsxTaskonMountusesvoidwithout catch. - Local work in progress in fork checkout (not yet installed): tolerate 404 in
sync.session.sync+ V2data.session.refresh, swallow Task preview sync errors, retrywriteJsonAtomicrename onEPERM/EBUSY/EACCES. - Workaround tried: none; restarting service/CLI does not help because the stale IDs are re-requested.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.