Repository navigation
[agent] Store and restore the agent's conversations - #262
Merged
Merged
Conversation
mcraveiro
force-pushed
the
feature/agent-sessions
branch
from
December 2, 2026 23:56
f42fc2f to
35067a3
Compare
The agent's session and its turns live in a new agent schema, retained by the conversation-record profile: a session belongs to the caller's environment, subject and view, and each turn is one exchange, its retrieval event stored metadata-only so a restore rebuilds it exactly. No route reads them yet. Co-Authored-By: Claude Code <noreply@anthropic.com>
A route that streams answers the response itself and is no MCP tool, but the session ask is a command: it writes the exchange it answers. The model now admits :stream: with :writes: on a POST and no response; the router records the stream in the catalogue, admits a streamed writing POST, and still refuses a stream that is a tool call or writes as another method. Co-Authored-By: Claude Code <noreply@anthropic.com>
…o thread The session routes create, list, read and delete a conversation, every statement filtered by the caller's environment, subject and view. The ask is a streamed POST that writes: the question and the exact passages event are inserted on the handler's worker thread before the stream opens, and a terminal sink enqueues the answer to one writer thread, which settles it in short transactions. A killed stream records stopped with its partial text, a restart turns every leftover streaming row into cut, and a partial snapshot is taken every two seconds. The stream's passages frame and the stored event are one object. Co-Authored-By: Claude Code <noreply@anthropic.com>
…context A session ask now loads the last eight done exchanges in the same snapshot as the session, neutralises their citations to [cited earlier], and keeps the newest whole exchanges inside the context-reserve byte budget, so the message list grows append-only for llama-server's prompt cache. A follow-up with no keywords searches with the previous question's, and with no current passages but a history the model is told to answer from the conversation. agent_settings.context_tokens is 65536 and start_command prints it. Co-Authored-By: Claude Code <noreply@anthropic.com>
The Agent screen names its conversation in the address as ?session=, the panel lists the caller's conversations and can start or delete one, and the provider rebuilds the transcript from the stored passages and done events, so a reload restores the answers, citations and timings. A stored streaming row shows as cut until the poll sees it settle, a conversation this tab streamed is never refetched under live turns, and a session the caller does not own shows the notice and the list rather than a new conversation. The shell test covers restore, history in the prompt, delete and an abandoned stream in Chromium. Co-Authored-By: Claude Code <noreply@anthropic.com>
Add the task that stores and restores the agent's conversations, its six delivery units, the measurements from the release build and the product calls still open, and list it in the story. The gateway tests prove a team session is invisible to the knowledge view and another subject, that a knowledge-view transcript names no sprint page, that the ask needs the gateway's CSRF headers, and that delete belongs to its owner. Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
The context test pinned the route template's old no_tool output. The streamed route now states stream() after no_tool(), so the test names it. Co-Authored-By: Claude Code <noreply@anthropic.com>
The writer and a flush wait on one condition variable. A notify_one after enqueueing could wake the flush, which has nothing to do while the queue is not empty, and leave the writer asleep. notify_all wakes both. Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
The struct check pins the ten conversation messages, which compass.db does not own. The binding check learns agent_turn_status and names the two reads that take the subject, since a conversation belongs to a person as well as a view. The task records the rule extension. Co-Authored-By: Claude Code <noreply@anthropic.com>
The panel's conversation list is per environment, so opening it beside a screen of another environment lists that one and leaves the conversation opened before. The Agent screen still names its conversation in the address and opens it after. Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
Prettier, which compass.web.format checks in CI, had not run over the new and changed files. Co-Authored-By: Claude Code <noreply@anthropic.com>
agent.agent_turn gains a thought column, defaulting to empty, so a restored turn shows the reasoning the person saw while it streamed. The generated row codec and schema carry it; migration 7 gains the column verbatim because it is unreleased. Co-Authored-By: Claude Code <noreply@anthropic.com>
Thinking is on and capped at 4,096 tokens, reasoning included. llama-server's reasoning_content delta (or a build's reasoning) becomes agent_thought_event, and the turn stores the reasoning beside its answer, snapshotted with it. The done event carries the context window, the history budget and bytes, and the done turns the window left out, so the panel measures the last answer from llama-server's usage chunk: the whole prompt, not only what the cache did not reuse. Co-Authored-By: Claude Code <noreply@anthropic.com>
… agent The Agent screen gets Gemini's sessions panel: New conversation at the top, the caller's conversations with the open one highlighted, and a delete for it; it stacks above the transcript at phone width, and the host's side panel keeps the compact bar. Each turn shows a collapsed Thinking element that opens to the whole reasoning, and the panel measures the context from the done event's counts and the history the prompt kept, naming the turns the window dropped. Co-Authored-By: Claude Code <noreply@anthropic.com>
…cision The task now carries the panel and thinking acceptance, the 4,096-token cap, the context indicator's exact measures, the very basic compaction the product owner asked for, and the model-written summary designed and deferred. The measurements hold the final test counts and the real Chromium pass against Qwen3.5-9B. Co-Authored-By: Claude Code <noreply@anthropic.com>
The delivery order now names the reasoning column, thinking, the panel and the documents by commit, and the status and result count the ten units. Co-Authored-By: Claude Code <noreply@anthropic.com>
A database that applied the earlier shape of migration 7, before the turn kept its thought, gains the column from migration 8 and keeps its conversations. The add is IF NOT EXISTS, so a fresh database, which builds the column in migration 7, changes nothing. The web reads an answer stored before the context fields as zeros, so it restores and shows no context meter for it. Co-Authored-By: Claude Code <noreply@anthropic.com>
document_summary carries an excerpt: the first non-empty section of the document's body, clipped to 320 characters with id-link markup reduced to its label. The documents screen draws it under the title, clamped to two lines, so a page of the list says what each document is about without opening it. The generated protocol carries the field; the document and backlink reads follow the shifted column. Co-Authored-By: Claude Code <noreply@anthropic.com>
A knowledge page states the six screens and what each offers: search with facets and snippets, the documents list with each document's first lines, the sprint board, charts and views, the step-by-step test runner, the WebGL link graph, and the agent with its server-owned conversations, collapsed thinking and context indicator. It also covers environments, the view isolation behind the gateway, and how compass serve delivers the app. The entry page links it. Co-Authored-By: Claude Code <noreply@anthropic.com>
Merging the search suggestions beside the sessions leaves the Agent screen with two ways in: the address's ?q= and its ?session=. The question now opens a conversation and asks in it, so a reload keeps it, and the tests say so. The panel keeps the question effect and the sessions panel's address, and the initial question is asked once. Co-Authored-By: Claude Code <noreply@anthropic.com>
The rebase that put this branch on the merged search suggestions kept one sentence per stacked commit, so the status row said the same thing three times. It says it once now, and search reads as merged. Co-Authored-By: Claude Code <noreply@anthropic.com>
mcraveiro
force-pushed
the
feature/agent-sessions
branch
from
December 3, 2026 00:52
6249daa to
b2f078c
Compare
This branch was previously deployed
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.
The compass agent forgets every question: the transcript lives in React state, a reload loses it, and a follow-up retrieves from the bare question. This branch makes conversations server-owned. A session belongs to the caller's environment, subject and view, and restoring it requires the same triple. The branch is not merged; the product owner's sign-off and the open calls below are outstanding.
What changed
The work is ten delivery units on the branch, each verified before the next, followed by fixes for what the final passes caught: the codegen test's stale pin, the writer waking every waiter, the service model checks learning the new messages and subject-scoped reads, the panel opening on its screen's environment, and the context counts coming from llama-server's usage chunk rather than the cache-aware timing. The last units are the turn's reasoning column, thinking and its context fields, the sessions panel, and the documents.
Database.
agent.agent_sessionandagent.agent_turnin a newagentschema, retained under the profileconversation-record, added by migration 7 with the generated DDL verbatim. The generated row codecs are in CMake. Migration 8 adds thethoughtcolumn only where a database applied the earlier shape of migration 7, so a development database keeps its conversations; on a fresh database, whose migration 7 already builds the column, it is a no-op. Nothing behavioural ships in this commit.Codegen. A streamed POST may now write, with no response. The parser admits
:stream:with:writes:on a POST, the router catalogue recordsstream, and the start-up gate admits it while still refusing a stream that is a tool or writes as another method. The statelessGET /v1/{environment}/agent?q=stays.Session routes and persistence.
POST/GET/DELETE /v1/{environment}/agent/sessionsand the ask asPOST .../sessions/{session}/ask(the question is in the body). Every statement filters by(environment, subject, view_name), and a mismatch is 404 or absent. The question and the exact passages event are inserted on the handler's worker thread before the stream opens; the answer is enqueued by a terminal sink to one writer thread, which settles it in short transactions off the io thread. The stream takes a partial snapshot every two seconds, recordsstoppedwhen the client leaves, and startup recovery turns a leftoverstreamingrow intocut. The live passages frame and the stored event are one object.History and prompt. Only done exchanges feed the model, newest eight and within the context-reserve byte budget, with citations neutralised to
[cited earlier]. A follow-up without keywords searches with the previous question's. With no passages but a history, the model is told to answer from the conversation.agent_settings.context_tokensis 65536 andstart_commandprints it.Web, sessions. Create, list, restore and delete conversations;
?session=in the address;turnsOfrebuilds the existingTurn[]from the stored passages and done or failure events; restore replaces rather than appends, so StrictMode does not duplicate turns; the unfinished-turn poll is bounded at 15 minutes. Strings are in en, fr and pt.Gateway and documents. View and subject isolation tests, the ask's gateway CSRF rule, and the task and story pages.
Thinking. The chat body sets
enable_thinking=trueand asks for llama-server's usage chunk. Thereasoning_contentdelta is parsed as a newagent_thought_event(a barereasoningdelta too). A newthoughtcolumn onagent.agent_turnstores it beside the answer, so a restore shows it, and the panel shows it in a collapsedThinkingelement: one line while it thinks, "Thought for N s" after, expandable to the whole reasoning. The completion cap rises from 400 to 4,096 tokens, reasoning included. The history prompt keeps questions and answers, never thoughts.Panel and context. The Agent screen draws the conversations as a right-hand sidebar, as Gemini's: New conversation at the top, the caller's conversations with the open one highlighted, and a delete for it; at phone width it stacks above the transcript, and the host's side panel keeps the compact bar. The context indicator shows the model's 65,536-token window, the last answered turn's prompt and generated tokens from llama-server's usage chunk (reasoning included), the bytes of history the prompt kept of the 24,000-byte budget, and how many older done turns the window left out.
Documents list excerpts.
document_summarycarries anexcerpt: the document's first non-empty section, clipped to 320 characters withid:link markup reduced to its label. The documents screen draws it under the title, clamped to two lines, so a page of the list says what each document is about. The generated protocol gains the field and the document and backlink reads follow the shifted column.Features page.
doc/knowledge/compass/compass_web_features.orgstates what compass.web can do, screen by screen, anddoc/compass.orglinks it.Compaction
The compaction in this slice is the history window: the newest eight done exchanges within the context-reserve byte budget, dropping whole exchanges oldest first. The indicator names how many older turns the window left out, so the loss is visible.
A model-written session summary is designed in the task page and deferred: it needs a second inference call on or beside the ask path,
agent_session.summary/summary_ordstate with a monotonic update, a failure policy that does not fail the question, and it changes the system prefix when a turn ages out.--context-shiftis not used because it truncates server-side without compass or the person seeing what was lost.Verification
From a release build in the worktree:
compass.db.tests "[migrations]": 144 assertions in 5 cases. Migrations 7 and 8 build the catalogschema.sqlbuilds; migration 8 adds thethoughtcolumn where the earlier shape of 7 ran. The development database migrated from 7 to 8 with its conversation intact, and its old answer restored in Chromium with zeros in the context fields and no thinking block.compass.db.tests "agent_*": 44 assertions in 6 cases for the row codecs; the fullcompass.db.tests: 1288 assertions in 174 cases.compass.model.tests "[masd]": 106 assertions in 15 cases. The streamed POST parses; a streamed PUT and a named response are refused.compass.http.tests: 388 cases, 9804 assertions. Covers thinking and its sink, the context fields, the session lifecycle and isolation, the writer and sink, the prompt and history, and the regenerated route counts (21 read routes, 31 write and tool routes).@compass/pagesvitest: 247 tests in 11 files;@compass/web: 3 tests;tsc --buildpasses.shell_test.shin real Chromium: 41 Playwright tests, including the sessions panel, the thinking element (also after reload), the context indicator, session create, restore, history in the llama body, delete, and an abandoned stream restored as stopped with its partial text.gateway_test.sh: 49 Playwright tests. A team session is invisible to the knowledge view and another subject; a knowledge-view transcript names no sprint page; the ask needsX-Ores-Requestand a matchingOrigin; delete is 204 twice for its owner and 404 for another.127.0.0.1:8081: a session on a throwaway cluster answered "How do I run compass serve?" after a 43 s thought, with 668 prompt and 2,338 generated tokens (reasoning included), so 3,006 used of 65,536 and 62,530 left. The Thinking element was collapsed, opened to the whole reasoning, and the panel made, restored and deleted conversations at 390 px with no horizontal overflow.The task page, with the measurements, the compaction design and the open calls, is
doc/agile/versions/v0/sprint_01/build_the_compass_web_front_end/task_store_and_restore_agent_conversations.org.Open product calls
These are recorded in the task, not decided:
view_digestis built.🤖 Generated with Claude Code