Bind requests to the invoking workspace; persist server ownership (#29)#37
Merged
TheRealDinghyDog merged 1 commit intoJul 10, 2026
Merged
Conversation
External-server mode had two workspace-safety gaps. First, the client never sent the `directory` query, so every project-scoped request (and the /event subscription) resolved against the server process's launch directory — a review could inspect, and a write task could edit, the wrong repository. Second, job records stored only serverUrl; cancel recomputed "external" by comparing against the CURRENT process's OPENCODE_COMPANION_SERVER_URL, so a cancel process without the job-start environment would send /global/dispose to a user-managed server. The client now appends the canonical (realpath) workspace directory to every non-/global/ route — all of them accept it per the 1.17.15 OpenAPI document, and live checks confirm session creation and listing scope to the query value. Job records persist `serverExternal` at job start (and via progress updates for foreground runs); cancel passes the persisted flag through interruptServerTurn, which no longer infers ownership from the environment. Teardown runs only when the job explicitly recorded plugin ownership; a recorded URL with unknown ownership (legacy records) fails safe and leaves the server running. The fixture now honors the directory query on session create/list and records the scope of event subscriptions. New tests: two workspaces sharing one external server get correctly-scoped sessions and event streams; cancelling a job whose environment differs from the job-start environment aborts the session but leaves the external server alive (the fixture exits on dispose, so a regression fails the health check); client unit coverage that project routes carry the directory and /global routes never do. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Fixes #29 (review finding H-04).
Problem
directoryquery parameter, so against an external server (OPENCODE_COMPANION_SERVER_URL) every project-scoped request — session create/list/resume and the/eventsubscription — resolved against the server process's launch directory, not the invoking repo. A review could inspect, and a write task could edit, the wrong repository. (Verified live: a session created without the query inherits the server's cwd; with the query it scopes to the given path, and listing filters by it.)serverUrlbut not ownership. Cancel recomputedserverExternalby comparing the recorded URL with the current process's environment — a cancel process without the job-start env var concluded "not external" and sent/global/disposeto a user-managed server.Fix
OpencodeServerClienttakes adirectoryoption and appends the canonical (realpath) workspace directory to every non-/global/route — all client routes accept it per the pinned 1.17.15 OpenAPI document./global/healthand/global/disposestay unscoped.getSessionRuntimeStatusnow distinguishes env-configured (external) from persisted plugin-owned servers; background jobs persistserverExternalalongsideserverUrlat job start, andrunServerTurnprogress events carry it so foreground job records get it too.interruptServerTurnaccepts the persisted flag and no longer infers ownership from the environment. Cancel teardown runs only when the job explicitly recorded plugin ownership (serverExternal === false); a recorded URL with unknown ownership (legacy records) fails safe and leaves the server running.Tests
directoryquery).directory,/global/*never does.POST /session?directory=Xand scoped listing behave exactly as coded.npm test: 92 passed, 0 failed, 0 skipped.Server-PID identity verification on teardown remains #31.
🤖 Generated with Claude Code