Skip to content

fix(app): namespace lastProjectSession by server origin#18305

Open
Skeptomenos wants to merge 1 commit intoanomalyco:devfrom
Skeptomenos:fix/multi-server-state-isolation
Open

fix(app): namespace lastProjectSession by server origin#18305
Skeptomenos wants to merge 1 commit intoanomalyco:devfrom
Skeptomenos:fix/multi-server-state-isolation

Conversation

@Skeptomenos
Copy link

Issue for this PR

Closes #18302

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When OpenCode Desktop connects to multiple servers (local sidecar + remote opencode serve), lastProjectSession is stored as a flat record keyed by directory path. Session IDs from one server persist after switching to another server, causing the Desktop to poll for sessions that only exist on the previous server — resulting in a "Session not found" error loop every ~4 seconds with audible chimes and red notification badges.

The fix namespaces lastProjectSession by server origin, matching the pattern already used by store.projects[origin] in server.tsx.

server.tsx: Expose the origin getter (derived from projectsKey(state.active)) so pages/layout.tsx can use it. Follows the existing key and name getter pattern.

pages/layout.tsx: Change lastProjectSession from { [directory]: route } to { [origin]: { [directory]: route } }. All reads go through a new originSessions() helper. All writes include server.origin as the first key. Migration wraps existing flat entries under the "local" origin key so no session history is lost.

The migration detects old vs new format by checking if the first value has an id field (old flat format) vs being a nested record (new namespaced format). This is idempotent — re-running migration on already-migrated data is a no-op.

How did you verify your code works?

  • Traced all 8 read/write sites for lastProjectSession across rememberSessionRoute, clearLastProjectSession, syncSessionRoute, navigateToProject, deleteWorkspace, and the route-change effect
  • Verified migration preserves existing session restore data under the "local" origin
  • Confirmed server.origin uses the same projectsKey() logic that already namespaces store.projects correctly

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

When connecting Desktop to multiple servers, lastProjectSession was
stored as a flat record keyed by directory path. Session IDs from one
server would persist after switching to another, causing a 'Session
not found' polling loop every ~4 seconds.

Changes:
- server.tsx: expose origin getter on server context
- pages/layout.tsx: change lastProjectSession from
  { [directory]: route } to { [origin]: { [directory]: route } }
- Add migration that wraps existing flat entries under 'local' origin
- All reads go through originSessions() helper
- All writes use server.origin as the first key

Closes anomalyco#18302
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multi-server: layout state not namespaced per server causes session loop after switching

1 participant