Skip to content

tui: stale subagent sessions cause SessionNotFoundError unhandled rejection bursts #47516

Closed

Description

@rorshopping

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.

Activity

  1. github-actions commented on Sep 5, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of (or closely related to) an existing issue. Please check:

    • cli: concurrent session.json writes race on Windows → EPERM, TUI loses current session #47497: Covers the same Windows EPERM rename error on session.json from concurrent CLI writers — the secondary symptom you describe in this report overlaps significantly with that issue. The primary symptom here (SessionNotFoundError unhandled rejections for stale subagent session IDs) appears distinct, but you may want to confirm whether both should be tracked together or separately.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions