Skip to content

fix(tui): only adopt runtime origins from the current process - #74

Open
dhaern wants to merge 1 commit into
shekohex:mainfrom
dhaern:fix/tui-sidebar-origin
Open

dhaern wants to merge 1 commit into
shekohex:mainfrom
dhaern:fix/tui-sidebar-origin

Conversation

@dhaern

@dhaern dhaern commented Oct 5, 2026

Copy link
Copy Markdown

Summary

The sidebar finds its PTY server through the origin records that servers publish for a project. Any record for the same project directory qualified as long as its server answered /health, including one published by a different OpenCode process. This PR keeps only the records published by the current process.

In plain terms: with two OpenCode windows open in the same project, one sidebar could connect to the other window's PTY server and list that window's terminals. Now each sidebar uses the server of its own process.

Cause

healthyRuntimeOrigins() took every record from originsForProject(directory, worktree) and accepted the ones whose /health answered. The record carries the publishing pid, but nothing compared it with the current process, and the cache then kept the adopted server for as long as it answered.

Changes

healthyRuntimeOrigins() skips records whose pid is not process.pid, before any health check. Two comments describe the new rule.

Behavior changes

A TUI attached to a server that runs in another process no longer finds that server through the records. It falls back to the existing instance-scoped bootstrap, which means the panel needs to be expanded once per startup. The local TUI and its server run in the same process (worker threads share process.pid), so that case is unchanged.

Validation

One new test in test/tui-index.test.ts: a healthy origin published by another process for the same project is not adopted. It fails on main, and deleting the pid filter makes it fail again.

I also ran this change, together with my other PTY fixes, in a live local OpenCode. The record of the running server had the host's pid, and the sidebar listed that server's sessions.

bun test over test/*.test.ts, without the npm-pack and live suites, gives 185 passing. bun run typecheck, bun run lint and bunx biome format . are clean. The CI workflow passes on this tree in my fork, including the Playwright e2e. I did not try an attached TUI.

Diff

Production: +2 lines (+7/-5) in src/tui/index.ts.
Tests: +40 lines (+42/-2) in test/tui-index.test.ts.

Project-wide discovery could adopt a sibling instance's PTY server.
Filter runtime records by PID before health checks to isolate sessions.

Attached TUIs now require a panel expansion per startup to discover their
server through the existing instance-scoped bootstrap.
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.

1 participant