Skip to content

fix(opencode-plugin): isolate cross-process session state writes - #6777

Closed
r266-tech wants to merge 1 commit into
volcengine:mainfrom
r266-tech:codex/6775-session-state
Closed

r266-tech wants to merge 1 commit into
volcengine:mainfrom
r266-tech:codex/6775-session-state

Conversation

@r266-tech

Copy link
Copy Markdown
Contributor

Description

Fixes the cross-instance session-state save race reported in #6775. OpenCode can load the plugin once per location, so separate managers may share the same state path. Each manager now writes a unique temporary file before the atomic rename, preventing one instance from consuming another instance's .tmp file.

Human Involvement

  • A human participated in the implementation or review loop
  • This PR was generated entirely by AI agents without human participation in the loop

Related Issue

Fixes #6775

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • Test update

Changes Made

  • Add process, timestamp, and UUID components to each session-state temporary path.
  • Add a regression test with two managers sharing one state directory.

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

Validation: node --check passed for the changed modules; all 57 OpenCode plugin tests passed locally.

Checklist

  • My code follows the project's coding style
  • I have performed a self-review
  • My code generates no new warnings

@r266-tech

Copy link
Copy Markdown
Contributor Author

I compared the three proposals using the plugin's session manager, isolated state directories, and fresh managers loading the state after a restart. These runs used Node 24.22.3 on macOS arm64.

Revision Overlapping writes Two distinct sessions after sequential saves and restart
main at 674e07f2 Reproduced the shared-temp-file ENOENT from #6775 One session restored
#6777 at 1787301 Both temp-file renames succeeded One session restored
#6779 at fa0c491 Both temp-file renames succeeded One session restored
#7908 at 440ae87 Both temp-file renames succeeded Both sessions restored

On #7908, both rows also survived sequential and concurrent saves by separate Node processes. An existing v2 row with pending capture survived, and a new writer recovered the lock after the prior writer was killed before replacing the state file. The 63 plugin tests and npm run check passed. The checks ran at the plugin layer on macOS.

I'm withdrawing this PR so the overlapping fixes can be reviewed in #7908. The distinction matters for #6775 because a successful rename can still replace another location's session with a stale snapshot.

AI-only validation and follow-up.

@r266-tech r266-tech closed this Nov 18, 2026
@github-project-automation github-project-automation Bot moved this from Backlog to Done in OpenViking project Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: opencode-plugin 0.5.23 still hits ENOENT renaming session-state .tmp when multiple locations load the plugin

1 participant