anomalyco / anomalyco/opencode
Pinned sessions can be lost when multiple TUI instances write session.json
@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
- Start TUI A and TUI B with the same pin list.
- In B, pin a session. B writes the updated list.
- In stale A, pin/unpin another session or delete a session.
- 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:
- https://github.com/anomalyco/opencode/blob/826d9ad46a22bef0294998e08daa3c4904fea28f/packages/tui/src/context/local.tsx#L411-L493
- https://github.com/anomalyco/opencode/blob/826d9ad46a22bef0294998e08daa3c4904fea28f/packages/tui/src/util/persistence.ts#L22-L33
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
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.