ADR 0066: One thread store: every MCP thread saved, and resumed by a later server
Date: 2026-10-18. Status: accepted 2026-10-16 (the one-thread-store proposal, every recommendation taken); phase 1 built 2026-10-18 for 0.27.0; phase 2, chat on the store (D2, D11), built 2026-10-19 for 0.27.0; phase 3, the store for the person, built 2026-10-20 for 0.28.0 (the amendments below).
Context
An MCP server kept its respond threads in memory only. A reconnect, a new build, or a crash lost every one, and a
caller that named the old thread_id again silently got a new thread on the server’s defaults. On 2026-10-15 the
git thread git3 came back that way after each reconnect: on the default model, with every tool, and a 120 s
command limit, where AGENTS.md asks for ollama:granite4.1:8b, run_command alone, and 600 s. The caller had
no way to tell, since a start setting on an existing thread was refused and a new thread accepted any.
Chat already saved most of a thread: TranscriptStore.save(_: ThreadRecord, as:) writes the transcript (which
carries the instructions) and a ThreadRecord.Snapshot beside it, and WispThread.openAgent takes both back. What
the snapshot leaves out is what an MCP thread started with: its model, tools, thinking, and command limit, which
lived only in the server’s memory and in the audit’s session.start. The proposal mapped this on 2026-10-16 (at
bc763e8); its phase 0, four fixes found while mapping, shipped in 0.26.3.
Decision
Phase 1 of the proposal, for MCP threads:
- The store (D1). Every
respondthread is saved under~/.wisp/threads/<thread_id>/, a user-only directory:thread.json(format version 1: the owner; the start settings, model, tools, the caller’s instructions, think, andcommandTimeoutSeconds; created, last used, and turns; every audit session it has had, oldest first; the facts the person dropped for it; andopenorsaved) besiderecord.jsonandrecord.store, which are whatTranscriptStorewrites, unchanged in format. Each file is 0600, staged and renamed,thread.jsonlast, so a record withoutthread.jsonis not resumable and the id starts afresh. The proposal’s “instructions present” is kept as the instructions themselves, so equal settings can be told from different ones (D5). - When it is saved (D4). After every turn, inside the thread’s
TurnQueue, so a snapshot is never taken mid-turn; at eviction, once the turn under way ends; and at the client’s end, beforesession.enddisconnected. A resume also writesthread.jsonat once with the new opening’s session, so its resources find it even if the opening ends in a crash. Eviction drops a thread from memory only;close_threaddeletes it from the store, and its history stays in the audit log. - One process at a time (D6). An
flockonthreads/<id>/lock, taken when the thread is opened or resumed and released when it is closed, evicted, or saved at the client’s end; the kernel releases it when the process ends. The lock file records the pid and owner, and another process naming the thread is refused withthread git4 is open in another wisp (pid 4242, claude-code).flocklocks belong to an open file description, so two servers in one test process exclude each other as two processes do. - Resume (D5). A call naming a thread this server does not hold and the store has resumes it with its saved
settings. The call’s result has
resumed: trueandresumedTurns: NinstructuredContent(createdis false), and its text beginsresumed thread git4 (12 turns, saved 2026-10-16 09:12). Start settings the call gives are accepted when each equals the thread’s and refused naming the ones that differ (git4 was saved with model ollama:granite4.1:8b, tools run_command; these settings differ: model); settings it does not give are not compared. A live thread takes equal settings too (git4 is open with …), so a caller that always sends its own, asAGENTS.mdasks, either continues its thread or is told why not. A resume is checked as a new thread is: the model must be enabled and open, with no fallback; the tools must exist and the model take them; think must suit it; the command limit is cut to today’scommandMaxTimeoutSecondswhen a command runs. - Owner (D3). A thread’s owner is the MCP client’s
clientInfo.name. A caller resumes only its own client’s threads: another’s is refused (thread o belongs to codex, and this client is claude-code; only codex can resume it, so choose another thread_id), is not listed, and cannot be closed. The refusal names no command to hand a thread over, sincewisp threads handis phase 3. The name is self-reported, so this keeps agents from colliding, not from each other. - Audit (D7). A resume’s
session.startcarriesresume(the thread id) andcarriedFrom(the thread’s earlier sessions, oldest first);Session.threadtakes both instead of hardcoding nil. A thread deleted by the retention sweep is audited asthread.swept, a new kind. - Resources (D8).
wisp://threadslists this server’s threads and the client’s saved ones, withownerand astateofopen,saved,open elsewhere,closed, orevicted.wisp://threads/{id}, itsfacts,summary, andcontextread a saved thread from its files without a model; itsaudit,output, andreasoningread every session inthread.json, so they cover the thread’s whole life, andoutputandreasoningrows say whichsessioneach is from, since turns are numbered per opening. - What carries (D9): entries and references, thread facts and the task, summary versions, the start settings,
and the facts the person dropped (
FactKeeper.droppedFacts, restored on resume). Not carried: “This session” approvals, session facts, parked questions, continuity counters, token totals, and the frames and receipts of earlier turns, so a saved thread’scontextlists no turns andcontext/nextshows its record as a resumed turn’s request would carry it before its facts. - Retention and the output store (D4, D10). At every
Session.begin, a saved thread unused forthreads.keepDays(30 by default, 0 to 3,650, 0 keeping them until closed) is deleted with the stored outputs of every session it had, unless a process holds it; at most 16 a start within 100 ms, as the output sweep is bounded. The output sweep that follows spares every saved thread’s sessions, so a reference in a resumed thread still resolves. - Ids (D2). A
thread_idthat starts with a dot is refused, since it names a directory:SafeNameadmits.and...
Consequences
- An MCP thread survives its server: a restart, a reconnect, a new build, or a crash after its last turn. A crash loses at most the turn under way.
- The git3 trap is closed: a caller sending its settings to a thread saved with others is refused naming the difference, and one sending equal settings continues its thread.
respond’sThreadFactorytakes aThreadStart(the start settings, the opening’s audit session, and what was saved) instead of six arguments; every test factory changed with it.- Saved threads take disk until closed or swept: a record holds the thread’s tool output in its transcript, as the audit log does, and is user-only for the same reason.
- Reading a saved thread’s resources needs no model, but the contexts of its earlier turns are gone for good: the per-turn frames are not saved.
- Tested without the model (
ThreadStoreTests,ThreadResumeWireTests): a save and load round trip, modes, torn saves, the version check, the lock between two servers on one home, owner and settings refusals, a closed thread not resumed, an evicted one resumed, a disabled model failing the resume,resumeandcarriedFromon the newsession.start,disconnectedat the client’s end, the resources spanning both sessions, and the sweep. - Not built here: chat on the store (D11, phase 2: chat’s
/saveand--resumestill use~/.wisp/transcripts), andwisp threads(list, show, delete, hand), the sweep inwisp doctor, andwisp-tui’s picker (phase 3).
Amendment, 2026-10-19: chat on the store (phase 2)
Phase 2 of the proposal, D2 and D11, built for 0.27.0:
- Every chat is a thread. Plain chat and
wisp chat --json(and sowisp-tui) open their conversation as a thread in the store throughChatThread: a new one aschat-<8 characters>, owned bychat, its lock taken beforeSession.beginso the start-up sweep cannot take it and no other wisp opens it. It is saved after every turn, a failed one included, and after every command the person runs with!; at the end of the loop it is saved assavedand its lock released. A chat that never had anything to save (a record of instructions alone) leaves no directory behind. The chat’s audit session is the session’s own, sothread.jsonlists it as is, not as<id>-<suffix>. /save NAMErenames the thread: saved under the new id, locked there, deleted under the old. Refused for a name another thread has (a thread named 'git4' is already saved), one the store cannot take, and an agent’s thread, whose agent names it by its id. A bare/savesaves now.--save NAMEnames a new chat’s thread, or renames a resumed one of the person’s own; nothing writes to~/.wisp/transcriptsany more.--resume IDopens any thread from the store, an MCP agent’s included (D3), then falls back to~/.wisp/transcripts/<ID>.jsonand saves what it finds into the store under that name at once, leaving the transcript in place. A transcript whose name the store cannot take (over 48 characters, or starting with a dot) is saved under a generatedchat-id; the proposal did not say.- An agent’s thread keeps its settings in chat. Its model, tools, and instructions become the session request’s
(
ChatThread.Opening.applied), sosession.startrecords them, and its thinking and command limit go to the agent; flags that differ are refused naming them, as D5 refuses an MCP caller. Chat shows them first:git4: ollama:granite4.1:8b, tools run_command, instructions set (an agent's thread: claude-code's, 12 turns); its settings hold here, and /new starts a thread of your own. Each save writes its record, turns, and last use under its own settings and owner, so the agent resumes it afterwards with the person’s turns in it and its own settings still equal. Not in the proposal, and needed to keep that true:/model,/think, and/save NAMEare refused on it. /newstarts the chat’s own thread with the same instructions, tools, and command limit, the existing meaning of/new, which on an agent’s thread is a thread of the person’s own with that agent’s tools. The proposal’s “starts a fresh thread instead” does not say with which settings; carrying the conversation’s keeps/modelcorrect after it, since the session’s tools are the ones it began with.- A chat’s own thread resumes on the flags and configuration as given,
--modelincluded, as chat resumed a transcript before, and its saved model and thinking follow/modeland/thinkat each save. The proposal’s D5 (saved settings on resume) is for agents; the person’s own thread is theirs to change. A fallback tosystem(ADR 0056) applies to it as to any chat. - The lock between chat and agents (D6): while chat holds a thread an agent naming it is refused with
thread git4 is open in another wisp (pid 4242, chat), and chat refuses to open one another wisp holds the same way, naming its holder. A resumed chat’ssession.startcarriesresume(the id as typed) andcarriedFrom(the thread’s sessions fromthread.json, or a transcript’s store links’ sessions) (D7). /threadsandwisp chat --listlist every thread in the store, any owner’s, most recently used first: id, owner, model, turns, last used, and state (openhere,open elsewherefrom the lock,saved), then the transcripts in~/.wisp/transcriptsnot yet in the store. Chat’s commands reachwisp-tuias message lines and their answers asoutputandnotelines, so neitherChatProtocolnorwisp-tuichanged; the picker is phase 3.
Tested without the model (ChatThreadTests, ChatLoopTests, and ThreadResumeWireTests.chatAndAnAgentHoldAThreadInTurn):
every turn saved before the next prompt, /save renaming and its refusals, an agent’s thread opened with its settings,
refusing flags, /model, and /save NAME, and saved under its owner, /new on it, a transcript read and saved into
the store, the generated id for a name the store cannot take, /threads’ states, session.start‘s resume and
carriedFrom, and the lock refusing a server while chat holds a thread and chat while a server does, the server then
resuming chat’s turn. ContextEquivalenceTests’ chat snapshot was recorded again: its requests, events, and saved
contexts are unchanged but for the renumbering of ids, and only its /save and /new notes and the saved transcript
differ, as the change intends. Checked live on 2026-10-19 on system in a scratch home: a turn saved as chat-…,
/save first renaming, --resume first, --list, and a chat quit at once leaving nothing.
Amendment, 2026-10-20: the store for the person (phase 3)
Phase 3 of the proposal, built for 0.28.0, with the three choices the operator made on 2026-10-20 (the proposal’s answers 6 to 8):
wisp threads(ThreadAdmin,ThreadsCommand) has four subcommands, each with--json.list, the default, prints chat’s listing (ChatThread.listing), and--jsongives each thread’s id, owner, model, turns, last use, state, and holder (pid and owner from its lock).show IDgives the start settings with the instructions in full, the turns, the audit sessions, the dropped facts, the bytes the directory and its sessions’ stored outputs take, and when the sweep deletes it (lastUsedplusthreads.keepDays; never at 0).delete IDremoves the directory and the stored outputs of each of its sessions that no other thread names. That last condition is not in the proposal: chat’s/newcarries its session into the next thread, so both threads name it. A thread whosethread.jsoncannot be read is deleted too, with no outputs, which is how the person clears one.hand ID CLIENTsets the owner toCLIENTand changes nothing else. It says so and records nothing whenCLIENTowns the thread already, and refuses an empty owner, one over 64 characters, one with spaces at either end, and one with a control character.- Delete and hand are the person’s (choice 7). Each takes the thread’s lock first, so a thread a process holds is
refused with D6’s message naming the holder. Each runs only with a terminal on standard input, as
wisp approvals approvedoes (ADR 0046), anddeleteasks first unless--yes.CommandPolicy.defaultDenygainswisp threads delete|handin the same shape as the patterns for approvals, facts, and questions, so no agent takes another’s thread throughrun_command, quoted or by path.listandshowstay allowed. Each change is audited under a session of its own (entry pointthreads), asthread.deleted(thread,owner,turns,sessions,outputSessions,outputBytes) orthread.handed(thread,from,to). - The owner refusal names the command, as D3 has it:
thread o belongs to codex, and this client is claude-code; choose another thread_id, or the person gives it to you with wisp threads hand o claude-code. The advice for a thread that cannot be resumed nameswisp threads delete IDfirst, thenclose_thread. /resume IDin chat, plain andwisp-tuialike (choice 8: switch in place). The thread open now is saved assavedand its lock released, as at the chat’s end.IDis opened as--resume IDopens it at start (ChatThread.find, thenChatLoop.Context.openThread). An agent’s thread runs on its own model, tools, thinking, and command limit, and the session’s tools give way to the thread’s (Session.openAgent’s newtools). Any other thread runs on the model and thinking the chat has now. Asession.startwithreasonresume,resume, andcarriedFromrecords the switch under the chat’s audit session, which the opened thread adds to itssessions. The current thread stays open, with the reason given, whenIDis that thread, cannot be found, is held elsewhere, or fails to open; a thread that fails to open is let go./model’s opener now reads the command limit of the thread open at the time, not the one the chat started on.- The picker in
wisp-tui:/threads, and a bare/resume, ask through thechoiceline/modeluses, over the threads no other process holds, most recently used first, each with its owner, model, turns, and last use, and the current thread marked. Choosing one resumes it. The threads held elsewhere are named in a note, not offered, since a choice has no disabled rows. The plain chat, which has no chooser, prints the listing.wisp-tuidid not change: the picker is its existing choice dialog, and its status line takes the model from thestatusline before each prompt. - The store in
wisp doctor, athreadsfinding aftersaved transcripts: how many threads are saved and what the store takes on disk, which threads are open and who holds them, and how many the next session’s sweep deletes underthreads.keepDays. Athread.jsonthat cannot be read is a warning naming it,wisp threads show ID, andwisp threads delete ID;/threadsandwisp threadsadd the same line under the listing. - The sweep spares a shared session’s outputs, as
deletedoes. Phase 1’s sweep removed the outputs of every session a swept thread had, so a thread/newstarted, which names the same session, lost the whole outputs it reached throughmemorywhen the thread before it aged out. A session that a kept thread names, or a due thread later in the same sweep, now keeps its outputs; the last thread to name it takes them.
Tested without the model:
ThreadStoreTests.theSweepSparesTheOutputsOfASessionAnotherThreadNames: a session shared with a kept thread spared, and one shared by two due threads removed with the second.ThreadAdminTests:listandshowwith a holder, the sweep date and both byte counts, andshow’s lines;deletekeeping a session another thread names, and deleting an unreadable thread;handand its refusals; both refused while a lock is held; the policy; the owner refusal’s text; the doctor’s finding.ChatThreadTests:/resumeswitching from a chat’s thread to an agent’s, the first saved and unlocked and the second keeping its owner and taking the next turn, with itssession.start. Also its four refusals, a failed open letting the thread go, no opener, and the picker offering the free threads, naming the held one, and resuming the one chosen.ThreadResumeWireTests: another client’s thread refused over the wire, then resumed by this client afterhand.