Restrict chat_sessions to server-owned sessions

chat_sessions now brokers GET /api/session but filters the global list to
the sessions this server recorded in run_steps, deduped by session id, and
fails closed to an empty list when no ownership source is configured. A
session another client holds (in-server claim, released on stream end or
disconnect) or an active run is marked busy; a second client's chat_prompt
for a held session is rejected before any OpenCode call. chat_create stays
unbrokered.
This commit is contained in:
2026-10-16 09:21:50 +01:00
parent dca72a09ee
commit 1818a06d2f
11 changed files with 711 additions and 38 deletions
+17 -6
View File
@@ -179,12 +179,23 @@ traversal, absolute paths, symlink escapes and unknown runs/steps.
The protocol declares the brokered `chat_*` surface (`chat_sessions`,
`chat_create`, `chat_prompt`, `chat_messages`, `chat_interrupt`, `chat_permission`,
`chat_reply`). The server dispatches `chat_prompt`, `chat_messages`, `chat_interrupt`
and `chat_reply`, answers the declared `chat_sessions`/`chat_create` with an explicit
protocol error because they are not yet brokered, and pushes `chat_event` frames
derived from OpenCode's global `/api/event` firehose, with retained
per-session/per-message state so a reconnecting client re-syncs instead of replaying
deltas.
`chat_reply`). The server dispatches `chat_sessions`, `chat_prompt`,
`chat_messages`, `chat_interrupt` and `chat_reply`, answers the declared
`chat_create` with an explicit protocol error because it is not yet brokered, and
pushes `chat_event` frames derived from OpenCode's global `/api/event` firehose,
with retained per-session/per-message state so a reconnecting client re-syncs
instead of replaying deltas.
`chat_sessions` is brokered but restricted: OpenCode's `GET /api/session` lists
every session on the machine, so the server filters it to the sessions recorded
in `run_steps` as owned by this server (deduped by session id), fills any missing
directory from the owning run's workspace, and fails closed to an empty list when
no ownership source is configured rather than exposing the operator's whole
environment. A session another client currently holds (an in-server claim,
released when the stream ends or the client disconnects) or that this server
records as an active run is marked `busy` so the phone can show it read-only; a
second client's `chat_prompt` for a held session is rejected before any OpenCode
call. `chat_create` remains unbrokered.
While a `chat_prompt` subscription is open the server also polls
`GET /api/permission/request` on a fixed small interval (first poll immediately) and