971e555ceb
Add a server-side close for operator chats, so finishing with a chat takes it out of the active list for every client without deleting anything. The brokered protocol gains chat_close and chat_reopen; chat_close stops a running turn by reusing the existing broker interrupt (its result carries an interrupted flag, so a stream is never left running into nothing) and then sets closed_at on the session's operator_sessions row. The session, its transcript and its history survive, and because the closed state lives in the registry chat_sessions reports it to every client, not just the one that asked. An id that is not a recorded operator session, including a pipeline-owned run session, is refused before anything is written. chat_reopen clears the state again, and simply prompting a closed session also clears it (the store clears closed_at on touch). The registry gains closed_at for a fresh database and an idempotent migration for one created before it existed. The app renders closed sessions under a labelled Closed section with a Closed chip, offers a Close action with a confirmation that says it stops a running turn, marks the chat closed on every device and deletes nothing, and a Reopen action on each closed row. The device-local hide is renamed Hide on this device, with a snackbar saying the chat stays on the server, so it is never confused with the real close. No new dependency, the installer and Docker files are untouched, and no run is started from the app. Checked before committing: the packaged templates carry no chat surface and need no update, and internal/author/install.go's managed inventory needs none either (this adds no reference file). The packaged authoring skill reference internal/author/skill/references/operations.md and the shared docs/cli.md and android/README.md are stale because of this change, but an item no longer edits a shared document: what is stale and what should change there is recorded in docs/notes/chat-close.md for the docs-fold writer, which is committed here with the change. Checks: gofmt clean, go build ./... and go vet ./... clean, and go test ./internal/protocol/... ./internal/pipeline/... ./internal/server/... ./internal/author/... pass. The app side is verified with :app:assembleDebug and :app:testDebugUnitTest (--offline --no-daemon, BUILD SUCCESSFUL); the on-device close, second-client and reopen check is deferred to visual review. Not deployed; deploying is the operator's step.
107 lines
6.4 KiB
Markdown
107 lines
6.4 KiB
Markdown
# Finishing a chat: a server-side close that keeps the history
|
|
|
|
## What this item changed
|
|
|
|
The Pipelines server and `android/`. Before this, the only way to get a chat out
|
|
of the list was the app's device-local hide (`ChatOverrides.hidden`): the session
|
|
stayed open on the server, other clients still showed it, and nothing recorded
|
|
that the operator had finished with it.
|
|
|
|
- `internal/protocol/chat.go` adds the `chat_close` and `chat_reopen` request
|
|
types, a `ChatCloseResult` (`session_id`, `closed_at`, `interrupted`) and
|
|
additive `closed`/`closed_at` fields on the chat session; `internal/protocol/message.go`
|
|
carries `ChatClose` on the outcome envelope (the requests themselves ride on
|
|
`chat_query`, like `chat_messages`/`chat_interrupt`).
|
|
- `internal/server/chat_close.go` (new) handles both: `chat_close` stops a turn
|
|
in flight by reusing the broker interrupt the session's room owns (recording in
|
|
the reply that a turn was stopped, so a stream is never left running into
|
|
nothing), then sets `closed_at`; `chat_reopen` clears it. Both take a
|
|
`chat_query` and echo the session plus its registry row. A session id that is
|
|
not a recorded operator session — including a pipeline-owned run session — is
|
|
refused before anything is written. Nothing is deleted.
|
|
- `internal/server/chat_sessions.go` marks a listed session `closed`/`closed_at`
|
|
from the registry, so every client sees the same state and a closed session
|
|
stays listed.
|
|
- `internal/server/chat_room.go` gains `turnInFlight`, so close only interrupts a
|
|
session that actually has a turn running.
|
|
- `internal/pipeline/operator_sessions.go` adds `closed_at` to
|
|
`operator_sessions` (for a fresh database and by an idempotent
|
|
`addColumnIfMissing` migration for an existing one), plus
|
|
`CloseOperatorSession`, `ReopenOperatorSession` and `OperatorSession`, and
|
|
clears the closed state on record and on touch, so simply prompting a closed
|
|
session reopens it.
|
|
- `android/`: `data/protocol/Chat.kt`/`Message.kt` (closed fields, the two
|
|
requests), `PipelinesRepository.chatClose`/`chatReopen`, `ChatStore` (closed
|
|
state, a `closedSessions` grouping, `setQueued`/`sessionReopened`),
|
|
`ChatFormat` (a closed status label), `ChatListPane` (a `Closed` chip and
|
|
section, Close/Reopen actions, a confirmation stating that close stops a
|
|
running turn, marks the chat closed on every device and deletes nothing),
|
|
`AppViewModel` (the close/reopen actions), and the rename of the local action
|
|
to **Hide on this device** with a snackbar saying the chat stays on the server.
|
|
- Tests: `internal/protocol/chat_test.go`, `internal/server/chat_close_test.go`,
|
|
`internal/pipeline/operator_sessions_close_test.go`,
|
|
`android/.../ChatCloseTest.kt` and the closed-state cases in
|
|
`android/.../ChatProtocolTest.kt`.
|
|
|
|
No new dependency (only the already-declared material-icons-extended), the
|
|
installer and the Docker files are untouched, and no run is started from the app.
|
|
State: committed locally only, not deployed; the on-device close/second-client/
|
|
reopen check is deferred to visual review.
|
|
|
|
## Shared documents this change makes stale
|
|
|
|
The note is written here rather than edited in place; the `docs-fold` writer
|
|
should update these when it next folds notes.
|
|
|
|
- `docs/cli.md:306` — the `## Chat sessions` bullet for `chat_sessions` lists each
|
|
session's `directory`, `tag` and recency and ends "A session is never marked
|
|
`busy`". It should add that a closed session is still listed, marked
|
|
`closed: true` with its `closed_at`, so a client groups or filters it as
|
|
history rather than losing it.
|
|
- `docs/cli.md:342` — after the `chat_adopt` bullet, add two bullets:
|
|
`chat_close` takes a `chat_query` (`session_id`), stops any in-flight turn
|
|
through the same interrupt `chat_interrupt` uses (the `chat_close` result's
|
|
`interrupted` flag records that a turn was stopped), then sets `closed_at` in
|
|
the operator-session registry; it answers with the closed session as
|
|
`chat_session`, its registry row in `chat_sessions` and the `chat_close`
|
|
result; an id that is not a recorded operator session — including a
|
|
pipeline-owned run session — is refused before anything is written, and
|
|
nothing is ever deleted. And `chat_reopen` clears the state again (the inverse,
|
|
same `chat_query`); prompting a closed session also clears it.
|
|
- `android/README.md:6326` — append a dated section recording the behaviour: the
|
|
server-side close and reopen, the session and transcript surviving a close,
|
|
the `Closed` chip/section and the `Closed` status line, the Close action and
|
|
its confirmation wording, the Reopen action, the two ways a session reopens,
|
|
and the rename of the local action to **Hide on this device** (device-only,
|
|
with a snackbar saying the chat stays on the server) so the two are never
|
|
confused. Include the verification evidence and the not-verified-on-device
|
|
boundary (implementation verification is the build and the unit tests; visual
|
|
review owns the device).
|
|
- `internal/author/skill/references/operations.md:268` — the "Brokered OpenCode
|
|
chat" preamble lists the declared `chat_*` surface; add `chat_close` and
|
|
`chat_reopen`.
|
|
- `internal/author/skill/references/operations.md:307` — the `chat_sessions`
|
|
paragraph describes the `operator_sessions` shape (`session_id`, `directory`,
|
|
`title`, `tag`, `created_at`, `last_used_at`); add `closed_at` and say that a
|
|
closed session stays in the list marked `closed`/`closed_at`. Add a paragraph
|
|
documenting `chat_close`/`chat_reopen` (interrupt a running turn, record the
|
|
closed state, refuse a non-operator session, keep listing as history, reopen
|
|
explicitly or by prompting), and add a dated evidence bullet naming
|
|
`internal/server/chat_close_test.go`,
|
|
`internal/pipeline/operator_sessions_close_test.go`,
|
|
`internal/protocol/chat_test.go` and the app's `ChatCloseTest`, marking the
|
|
on-device check as not run.
|
|
|
|
## Not stale
|
|
|
|
- No packaged template names the chat surface, so `internal/author/`'s templates
|
|
need no change.
|
|
- `internal/author/install.go`'s managed file inventory needs no change: this
|
|
item adds no reference file.
|
|
- `internal/author/skill/references/SKILL.md` stays a task-directed index; the
|
|
close/reopen detail belongs in `operations.md`.
|
|
- `android/AGENTS.md` already lists `ui/chat/` and its files, and
|
|
`internal/server/AGENTS.md` already points at `internal/server/chat_*.go` and
|
|
`internal/pipeline/`'s operator-session registry, so neither area map needs a
|
|
new entry.
|