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
+5
View File
@@ -87,6 +87,11 @@ type ChatSession struct {
ParentID string `json:"parent_id,omitempty"`
CreatedAt int64 `json:"created_at,omitempty"`
UpdatedAt int64 `json:"updated_at,omitempty"`
// Busy marks a session another client currently holds (or one the server
// itself owns as an active run), so the phone can show it read-only instead
// of letting two clients silently write the same conversation. It is
// additive and optional: older peers ignore it.
Busy bool `json:"busy,omitempty"`
}
// ChatCreateRequest is the chat_create request body: a title and an optional
+1
View File
@@ -21,6 +21,7 @@ func chatSamples() []struct {
ID: "ses_1", Title: "demo", Agent: "build", Model: "deepseek-v4.1-flash",
Directory: "/work", ParentID: "ses_0", CreatedAt: 1792112366711, UpdatedAt: 1792112367999,
}},
{"session_busy", ChatSession{ID: "ses_2", Title: "held", Busy: true}},
{"create", ChatCreateRequest{Title: "demo", Directory: "/work"}},
{"query", ChatQuery{SessionID: "ses_1", Limit: 50}},
{"prompt", ChatPromptRequest{SessionID: "ses_1", Text: "hello", Model: "m", Agent: "build", Files: []string{"file:///tmp/a.png"}}},