Repository navigation
feat(opencode-plugin): register embedded sessions for discovery - #1567
Open
TheRealAlexV wants to merge 1 commit into
Open
TheRealAlexV wants to merge 1 commit into
TheRealAlexV wants to merge 1 commit into
Conversation
Embedded plan/review/annotate sessions never reached the session registry: registerSession() is only called from the compiled CLI (apps/hook/server/index.ts), so `plannotator sessions` and any external discovery tool cannot see them.
The embedded runtime hosts several concurrent servers inside one OpenCode process, so a pid-only key would collide. Add an optional SessionInfo.id used as the registry file key (defaults to the pid, backward compatible) and key embedded sessions by <pid>-<port>.
- packages/server/sessions.ts: optional id + sessionKey(); unregisterSession accepts a string key.
- apps/opencode-plugin/session-registry.ts: register/unregister helpers.
- apps/opencode-plugin/{embedded,commands}.ts: register plan/review/annotate.
- packages/server/sessions.test.ts: coverage for id keying and concurrency.
Relates to backnotprop#899.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Sessions started by the
@plannotator/opencodeplugin's embedded runtime are invisible to discovery.registerSession()is only called from the compiled CLI (apps/hook/server/index.ts), soplannotator sessions— and any external tooling that wants to list or route live sessions (for example a self-hosted multi-session hub for remote/headless use) — cannot see embedded plan/review/annotate sessions. This is the discovery half of the multi-session problem tracked in #899.There is a second constraint: the embedded runtime hosts several concurrent servers inside the single OpenCode process, so a pid-keyed registration would be wrong even if it existed — every session would share one file, the last one would win, and one session's teardown would delete another's entry.
Change
packages/server/sessions.ts— add an optionalSessionInfo.idused as the registry file key (falls back to the pid, so CLI behavior is unchanged), asessionKey()helper, and letunregisterSession()take a string key.listSessions()is untouched: it already scans*.jsonand reclaims entries whose pid is gone.apps/opencode-plugin/session-registry.ts(new) —registerEmbeddedSession()/unregisterEmbeddedSession()helpers that key sessions by<pid>-<port>.apps/opencode-plugin/embedded.ts— register/unregister embedded plan reviews.apps/opencode-plugin/commands.ts— register/unregister embedded review, annotate, and annotate-last sessions.packages/server/sessions.test.ts(new) — id-vs-pid keying, two concurrent sessions in one process, targeted unregister, and stale-entry cleanup.Why
<pid>-<port>Each live embedded server listens on its own port, so
<pid>-<port>is unique per session, while the embeddedpidstill drives the existing liveness check (process.kill(pid, 0)inlistSessions) for stale-entry cleanup. No format change for CLI sessions — they pass noid, so the key staysString(pid).Testing
bun test packages/server/sessions.test.ts apps/opencode-plugin/commands.test.ts→ 16 pass, 0 failbunx tsc --noEmit -p packages/server/tsconfig.json→ cleanbun build apps/opencode-plugin/index.ts --target node --external @opencode-ai/plugin→ bundlesNo behavior change for CLI sessions; embedded sessions simply become discoverable.
Relates to #899.