Repository navigation
feat(opencode-plugin): register embedded sessions for discovery - #1567
Merged
backnotprop merged 8 commits intoOct 28, 2026
Merged
backnotprop merged 8 commits into
backnotprop merged 8 commits 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.
# Conflicts: # apps/opencode-plugin/commands.ts # packages/server/sessions.test.ts # packages/server/sessions.ts
…updates The embedded entries sat in sessions/ beside the binary's, so auto-update and the Inbox update dialog (and every released binary) would count a live OpenCode process as "another Plannotator is open" and defer the update for as long as OpenCode stays open. - Move them to sessions/opencode/<pid>-<port>.json, tagged host: "opencode". listSessions/listLiveSessions read only the top folder's *.json, as every released binary does, so no version ever sees them. - otherOpenSessions and the update dialog also skip any entry with host. - decideListed (review, annotate, last) and submit_plan's finally remove the entry on decision, throw, abort and timeout; process exit removes the rest. - listInProcessSessions drops and deletes an entry whose pid is dead, whose port no longer answers, or that cannot be read (signal deaths, missed removals). No signal listener is added to OpenCode's process. - plannotator sessions lists them with the rest, marked (in OpenCode). - Drop the id/sessionKey registry key: the subfolder makes it unneeded.
…process is gone A host killed by a signal left its entry until someone ran plannotator sessions; the next registration now deletes dead-pid entries (no port probe).
…uess for commands - decideListed removes the entry before server.stop(), so a stop that throws can't leave it behind (as the plan review already did). - listOpenCodeSession no longer runs project detection in OpenCode's cwd: a command passes the project it detected, or it is listed as unknown (a /plannotator-review <dir> was mislabeled). Only the plan review detects.
…ther user kill(pid, 0) answers EPERM for a process that exists under another user; the sweep now deletes only entries whose process does not exist. The test also checks that live entries survive a registration.
1 task
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.