Skip to content

External-server mode: requests not bound to the invoking workspace; ownership not persisted, cancel can dispose a user's server #29

Description

@TheRealDinghyDog

External-server requests can target the wrong repo; teardown can kill a user-managed server (H-04)

Surfaced by the gpt-5.6-sol final review, verified locally against OpenCode 1.17.15.

OpencodeServerClient never appends the invoking directory to project-scoped requests or the /event subscription, yet the real OpenAPI document accepts a directory query on ~119 operations (all /session* routes, /config, /event, file routes). A session created without it inherits the server process's launch directory — only safe for plugin-owned servers spawned with cwd set.

Ownership is not persisted either: the job record stores serverUrl but not whether the server was external. interruptServerTurn() (opencode.mjs) recomputes serverExternal by comparing the recorded URL with the current process's OPENCODE_COMPANION_SERVER_URL; handleCancel (opencode-companion.mjs) then calls teardownServerSession whenever the flag is falsy. A cancel process without the env var will dispose/kill a shared, user-managed server.

Fix:

  • Make the client directory-aware; attach the canonical workspace directory to every project-scoped request and the event subscription.
  • Persist immutable ownership (owned vs external) in job and server-session records at job start; never infer historical ownership from the current environment.
  • Gate /global/dispose and PID termination on plugin ownership.

Tests: two-workspace test against one external server; cancel test whose environment differs from the job-start environment.

Source: gpt-5.6-sol final review H-04 (opencode-plugin-cc-analysis.md).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions