anomalyco / anomalyco/opencode

Pinned sessions can be lost when multiple TUI instances write session.json

Open
#44,736 1 comment 0 reactions 1 assignee View on GitHub

@kommander is already working on this.

Since Aug 24, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

Each TUI reads the global session.json pin list once and keeps a private in-memory copy. Pinning, unpinning, or handling session.deleted rewrites the entire file without locking, rereading, merging, or serializing writes. A stale TUI can therefore erase pins added by another TUI.

Reproduction
  1. Start TUI A and TUI B with the same pin list.
  2. In B, pin a session. B writes the updated list.
  3. In stale A, pin/unpin another session or delete a session.
  4. Restart OpenCode.

The pin added in B is gone because A replaced the complete file with its stale snapshot.

Expected

Concurrent TUI instances should not erase unrelated pin updates.

Cause

createSession() loads the file once and each save() passes the full in-memory array to a fire-and-forget writeJsonAtomic() call:

Atomic rename prevents partial files but does not prevent stale writers. There is also no file watcher or close-time merge. Closing a TUI alone does not save; the last completed save wins.

I verified that the relevant persistence code is identical in v1.18.18, v1.18.19, v1.18.20, v1.18.21, and current dev.

Environment
  • macOS
  • Multiple OpenCode TUIs in WebStorm and system terminals
  • OpenCode v1.18.18 through v1.18.21

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.