anomalyco / anomalyco/opencode

tui: stale subagent sessions cause SessionNotFoundError unhandled rejection bursts

Open
#47,516 1 comment 0 reactions 1 assignee View on GitHub

@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.ts under ~/.config/opencode/plugin/; no plugin entries in ~/.config/opencode/opencode.json (provider orproxy configured)

Reproduction

  1. Open several opencode TUI clients with no args against the same background service.
  2. View a session containing Task subagent tool parts whose metadata.sessionId points to sessions absent from session_v2 (deleted, never projected, or from another directory).
  3. Each client calls sync.session.sync(subagentSessionID), which uses throwOnError: true and throws Session not found: ses_....
  4. The Task component fires this as void sync.session.sync(sessionID) with no catch, producing one unhandled rejection per client per stale session.
  5. At the same time, concurrent session.json pinned-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_v2 had 5 rows; the failing IDs were absent.
  • Suspected read-path gap (creation-race fixes do not cover reads): packages/tui/src/context/sync.tsx sync() throws on 404; packages/tui/src/routes/session/index.tsx Task onMount uses void without catch.
  • Local work in progress in fork checkout (not yet installed): tolerate 404 in sync.session.sync + V2 data.session.refresh, swallow Task preview sync errors, retry writeJsonAtomic rename on EPERM/EBUSY/EACCES.
  • Workaround tried: none; restarting service/CLI does not help because the stale IDs are re-requested.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.