backnotprop/plannotator
tldr.page
Inbox Thread State

Plannotator Inbox: the thread-state model

Date: 2026-10-12. This is the model of where a thread sits in the Inbox list and why it moves. It is written from the code, and the code is checked against it: packages/shared/inbox/store.test.ts ("the thread-state model") runs generated and hand-written event sequences against the real store and an independent model of the rules below, and checks every invariant after every step. The phone apps replay the trace fixtures in packages/shared/inbox/fixtures/thread-state/v1/ (see "Trace fixtures").

Where the rules live: the store (packages/shared/inbox/store.ts: listRow, readAt, markSeen, markRead, markUnread, tellSetAside, markAgentChecked, resolveThread, sendMessage, sendReply, savePicks), the sections (packages/shared/inbox/list.ts), the routes (packages/server/inbox.ts), the counts (packages/inbox/held.ts waitingCount) and the wire (adr/implementation/inbox-mobile.md, section 2).

Terms

  • Thread. A row of the list. Its first message is the root; the root's record carries the thread's look, read, archive and agent-read fields.
  • Agent message. A message an agent sent (send_message, submit_guide). It may ask questions (:::question blocks).
  • Person message. The person's Send (a reply), or one of the Inbox's own notes: the set-aside note a Mark read sends to the asking agent, and the reopened note its late Undo sends. Notes are written as the person's messages, so they reach the agent like any reply (the wake, read_thread), but they are not the person's reply and not a look (isInboxNote in @plannotator/core/inbox-types). Everything the list derives reads past them: the look, unseen, sent (rule 7), "came back", waiting_on_person, and in the window the look boundary (packages/inbox/folding.ts), the "Saved for / Delivered to" line and the held list's agent activity (last_agent_at).
  • Seq. One counter across the Inbox. Every line has one; "after" and "before" below mean seq order.
  • The look. The person looked at the thread (POST /api/inbox/threads/:id/seen): the window records one when the thread opens, and again when an agent message that arrived while it was open has been seen on screen (seen on sight, packages/inbox/seenOnSight.ts). The root's person_seen_seq becomes the seq of the latest agent message, or, with the optional through_seq (the newest message the window showed), of the latest agent message at or below it: a message that landed after the window read the thread stays new. A look never goes back (a cap at or behind the recorded look writes nothing), and a cap past the newest message is the newest message. The person's own reply counts as a look at everything before it. The Inbox's notes are not the person's reply and not a look.
  • Mark read. POST /api/inbox/threads/:id/read. It writes person_read_seq and person_read_at on the root, counts as a look, and closes every question still waiting on the person (open, or picked and not sent) as a skip with set_aside, which names that Mark read (set_aside.read_seq, its person_read_seq). It stands while no message but its own set-aside notes came after it.
  • Undo. POST /api/inbox/threads/:id/unread. It clears the read fields, puts back the look Mark read counted, and reopens the questions that Mark read closed (the root's current person_read_seq), as they were (a saved pick included). A question an earlier Mark read closed stays closed (owner ruling 2026-10-12). A record older than read_seq is matched by time (set_aside.at equals the root's person_read_at). With no Mark read on the root (after an Undo, or an Unarchive that dropped it) Undo writes nothing.
  • Archive. Resolve (POST /api/inbox/messages/:id/resolve, resolved: true). The root's resolved_at is set. The archive line is the seq of the root line that set the current resolved_at; it is derived from the log, never written. Messages before the line are closed by the archive: their questions read closed, and picks and Send on them are refused (409 thread_resolved).
  • Came back. An agent wrote in an archived thread after the line (agent_after_archive), and something there still waits on someone (back_from_archive): an agent message after the line the person has not looked at, a live question open or picked, or the person's real reply after the line that no agent has read (notes do not count), unless a Mark read made after it still stands. A Mark read made after the latest post-archive agent message ends "came back": the thread is Archived again at once, even while the person's reply there waits on the agent. The thread stays resolved.
  • Agent read. read_thread read the thread. The root's agent_checked_seq becomes the seq of the latest person message it covered.
  • A thread the person started. Compose (POST /api/inbox/messages): the root is the person's message (started_by_person), addressed to one live session (to). Routing indexes agent roots only, so only a reply_to answer lands in it (or, once an agent named it, a send with that name). Its addressed session's delivery (the connection put it into the session as a turn) counts as an agent read up to it.
  • Unsent work (the row's unsent, approval "inbox-reply-drafts", 2026-10-20). What the person has not sent in the thread: words typed in its reply box (a reply draft, inbox/reply-drafts/<thread id>.json, outside the event log, so no line, no seq and nothing an agent sees), picks saved and not sent, and comments (on attached files, the guided review, the messages) waiting for a Send. Saved while the person types (a compare-and-set on updated_at); Discard and the Send that carries the words (clear_draft, naming the updated_at they were saved as, or a draft holding exactly the reply's words, so a newer, different draft from another window stays) delete the draft; a deleted thread takes its draft with it.
  • Waiting on the person (the summary's waiting_on_person, Workspaces' wire). The thread is not resolved, its last message (the Inbox's notes read past) is an agent's, and no Mark read stands: a standing Mark read means nothing waits on the person. The model checks it after every step.

Question states

Derived, never stored, in this order:

StateWhen
supersededA later agent message in the thread replaced it (superseded_by)
closedIts message is closed by the archive, or a Mark read set it aside (set_aside)
openNo answer
sentThe answer went out with a Send (sent_revision equals revision). A skip by the Send that skips is a sent answer
pickedAn answer is saved and not sent

Sections

The six sections, shown in this fixed order: Stopped on you, Holding up work, Waiting on you, New since you looked, Sent, Quiet. A thread is in exactly one. The first rule that holds wins:

#RuleSection
1Archived: resolved and not came backQuiet
2Mark read stands (made after the archive line when the thread is resolved)Quiet ("Read"); New while unsent work waits and no Re-ask note waits, or while Mark unread took the look back (unseen above 0)
2aEvery open question is listed in a Re-ask note that still waits (approval "inbox-reask"). A note waits until the session it went to (its to, else the asker) writes again, and only while a question it lists is still openSent
3An open question carries Stopped:Stopped on you
4An open question carries Holds up:Holding up work
5Any other open questionWaiting on you
6Picks saved and not sent, nothing openNew since you looked ("Answered, not sent")
7The last message is the person's and no agent read itSent
8Agent messages after the lookNew since you looked
9Unsent work: a reply draft, picks, comments waitingNew since you looked ("Draft · …")
10Anything elseQuiet

Rule 9 (and the exception in rule 2) is the approval's rule: a thread holding unsent work never sinks to Quiet. New, because New already holds rule 6's "Answered, not sent" (work that waits only for the person's Send) and sits above Quiet without claiming that a question waits. A row in New only for the person's own words or comments (no unseen agent message, no rule 6) is not bold, and it does not count as waiting on the person; the Drafts row counts it instead. Rule 1 wins over it: an archived thread stays archived with its draft kept, because archiving is the person's explicit "done" (the archive already closes the questions, and a comment cannot be added to it).

Inside a section, newest first by the thread's latest message (last_at), ties on the thread id. A row moves within its section only when the thread gains a message; looks, picks, reads, reply drafts and archives move it between sections.

Archived is the seventh place (six sections plus Archived): resolved and not came back. A came-back thread is placed by rules 2 to 10 like an open thread.

The two list views

ViewRouteArchived threads
DefaultGET /api/inbox/threads (archived=include)In Quiet, like any quiet thread. The phone's door forwards this route as it is, so a phone that draws the sections keeps every thread
The window'sGET /api/inbox/threads?archived=exclude plus GET /api/inbox/threads/archivedOut of every section; listed newest archived first (resolved_at, ties on the thread id) by the archived route, which Settings' Archived block reads

A came-back thread is in the sections in both views and is not in the archived list.

Events

EventRoute (window)What it writes
Agent message, new threadsend_message without reply_toA root. Routing: with a thread name, the newest open thread of that name in the project, else a new thread. Without one, always a new thread (the owner, 2026-11-08: joining the session's last unnamed thread put long-lived sessions' news into weeks-old, unrelated threads). An archived thread is never joined
Agent replysend_message with reply_toA message in that thread, archived or not. Archived: it lands after the line
Agent questioneither of the above, with :::question blocksThe message and one question record per block
Supersedesupersedes: [...] or a Replaces: lineThe message, then superseded_by on each named question that is open or picked. A named question no longer open is left as it is and the message still goes (2026-11-22, skipped in the result); an id that names no question of the thread refuses the whole send (invalid_supersedes)
Open (seen)POST /api/inbox/threads/:id/seen, optional through_seqperson_seen_seq when an agent message (at or below through_seq, when given) is unseen; else nothing
PickPOST /api/inbox/messages/:id/picksThe answer, revision + 1
Re-askPOST /api/inbox/messages/:id/reaskOne person note (reask: that session's open questions) as a reply to the message; that session's picks not sent marked sent with it. Refused with nothing of that session open (nothing_to_reask), on a person's message, before the archive line. Idempotent on its key (a reply's key: idempotency_key_reused). Rule 2a holds while every open question is in a note that waits: another session's new question, the last listed question answered, superseded or closed, or the noted session writing again ends it
SendPOST /api/inbox/messages/:id/replyThe listed picks as sent (on that message, or with message_id on another message of the same thread and session), then ONE person reply. Idempotent on its key
The Send that skipsthe same, skip: [keys]Also every listed question still open, as a sent skip (by_reply). Only what the person chose with "Skip them"; a Send skips nothing else, and skip_unanswered is ignored (approval "inbox-explicit-skip")
Mark readPOST /api/inbox/threads/:id/readThe read fields and the look on the root; set_aside on each waiting question
UndoPOST /api/inbox/threads/:id/unreadThe read fields cleared, the look put back while the read stood, the questions that Mark read closed restored; one reopened note per asking message for those of them the agent had been told about. Nothing when the root has no Mark read
Mark unreadPOST /api/inbox/threads/:id/mark-unreadThe look on the root set to just before the latest agent message (it is unseen again: New); nothing else, so a standing Mark read stays and Move back still reopens what it closed. A standing Mark read with unseen news is in New; the next look puts it back in Quiet, and Mark read gives the look back without a new Mark read. Nothing when no agent wrote, the person's real reply came after the latest agent message, or it is unseen already
Set-aside notethe server, 10 s after a Mark read (and after an Unarchive)One person note per asking message naming the questions a Mark read closed and no note named yet, whatever happened since. None for a message closed by the archive
ArchivePOST /api/inbox/messages/:id/resolve { resolved: true }resolved_at. No write when already resolved
Unarchivethe same, { resolved: false }resolved_at cleared; a Mark read made after the archive line is cleared in the same root line
Agent read your replyread_threadagent_checked_seq
Mark all as read (a project)POST /api/inbox/projects/:id/readMark read on every thread of the project single Mark read is offered on (open or come back, something waiting on the person): exactly the lines each single Mark read writes. Each thread's set-aside note goes on its own
Archive all (a project)POST /api/inbox/projects/:id/resolve { resolved: true }Archive on every listed open thread of the project; Mark read on one that came back. Exactly the single actions' lines
Their Undo…/unread { threads }, …/resolve { resolved: false, threads }Undo or Unarchive on exactly the threads the batch named, as the single actions write them
Person starts a threadPOST /api/inbox/messagesA person root with to and started_by_person; no question records, whatever the body says. Idempotent on its key. Refused (session_not_live) when the session is not live, nothing written
Deliveredthe bridge's delivered eventdelivery on the person's message, and agent_checked_seq up to it
Reply draftPOST /api/inbox/threads/:id/draft { body, base }; …/draft/delete; clear_draft on the SendThe draft's file (no line). An empty body deletes it. A stale base is 409 draft_conflict, nothing written

Transition table

Columns are the state before the event: Asks (Stopped, Holding or Waiting), New, Sent, Read (Quiet by Mark read), Quiet, Archived, Came back. A cell names the state after it. "Asks" means the section of the strongest open question. Archived covers two cases that answer the person's writes differently: no agent wrote after the archive line (every write is refused, 409 thread_resolved), and a thread that came back and returned to the archive once handled (its later messages behave as an open thread's; its earlier ones stay closed). An archived thread has no open or picked question, or it would have come back. The Archived cells are proved on a real store by "the Archived column" tests in store.test.ts.

EventAsksNewSentReadQuietArchivedCame back
Agent message, asks nothingAsks (moves up)NewNewNew; the questions it closed stay closedNewreply_to: Came back, New. Without it: a new thread starts; this one stays ArchivedCame back
Agent questionAsksAsksAsksAsksAsksreply_to: Came back, AsksCame back, Asks
SupersedeAsks if anything is still open, else NewAsks or NewAsks or NewAsks or NewAsks or Newreply_to: Came back, as an agent message; nothing in it is open or picked, so nothing is supersededas for an open thread
Open (seen)AsksQuiet, or New while picks waitSentReadQuietArchived (no change of place)Archived when only unseen news kept it back, else Came back
PickAsks while another question is open, else NewNewNew (a pick on a sent question makes it picked again; the window does not offer it)Refused for a question the Mark read closed (question_set_aside)as SentNo agent after the line: refused (thread_resolved). Came back and returned: a sent question of a later message takes a pick again (Came back, New); a question before the line is refusedafter the line: as for an open thread; before it: refused
Send (Keep open)Asks while a question stays open, else SentSentSentSent; the closed questions stay closedSentNo agent after the line: refused (thread_resolved). Came back and returned: a Send on a later message is taken (Came back, Sent); on an earlier one, refusedCame back, Sent (or Asks)
The Send that skipsSent, unless another message's question stays openSentSentnothing_to_send unless words or picks goSentNo agent after the line: refused. Came back and returned: as Send; with no words, nothing_to_send (nothing there is open)Came back, Sent
Mark readReadReadRead (the store takes it; the window does not offer it)No write unless a question waitsReadNo agent after the line: refused (thread_resolved). Came back and returned: taken, and it stays Archived (with the read)Archived, also while the person's reply there waits on the agent; a reply the person sends after it brings it back (Sent)
UndoAsks (only this Mark read's questions reopen)Clears the read; a question an earlier Mark read closed stays closedas NewWhat the messages and the restored questions say (often Asks)as NewNo agent after the line: refused (thread_resolved). Otherwise taken: when that Mark read had sent a came-back thread to the archive, it comes back as it was (for example Waiting, unseen put back); else it stays Archivedas New
ArchiveArchivedArchivedArchivedArchivedArchivedno writeno write (Unarchive, then Archive, archives again)
Unarchiveno writeno writeno writeno writeno writePlaced as an open thread; a Mark read made before the archive is kept (Read)Placed as an open thread; a Mark read made after the line is dropped
Agent read your replyAsksNewQuietReadQuietArchivedArchived when the unread reply was all that kept it back
Set-aside noteAsks (an open question still places it; unseen unchanged)New, unseen unchanged: the note is neither a reply nor a lookSentRead: the note never ends the readQuietArchived; a note goes only for questions asked after the lineas for an open thread
Person starts a threada new thread: Sent
DeliveredAsksNewQuiet (the delivery is the agent's read)ReadQuietArchivedas Agent read your reply
Reply draft savedAsksNewSentNew (the read stands; the row is not bold)New (not bold)Archived (the draft is kept)Came back, as for an open thread
Reply draft emptied or discardedAsksNew while news or picks wait, else QuietSentReadQuietArchivedCame back

Invariants

Checked after every step of every sequence, on the store's own output:

  1. Every thread is in exactly one section, in each of the two list views.
  2. No thread disappears: the default view holds every thread ever created; the window's view and the archived list together hold every thread, and never the same one twice.
  3. Every open question is either in a Re-ask note that still waits (its session has not written since), or keeps its thread in Stopped, Holding or Waiting. Checked against the questions and the notes themselves, never the row's flag.
  4. Mark read then Undo, back to back, gives the thread back exactly as it was (section, unseen, questions, picks), whatever an earlier Mark read closed. Undo always clears the read fields; afterwards a question is set aside exactly when an earlier Mark read closed it.
  5. Archive then Unarchive loses no message, question or pick; the row comes back identical.
  6. An agent message after the archive line brings the thread back into the list while something waits. Mark read on a came-back thread returns it to Archived. Unarchive clears a read made while archived.
  7. Counts. The sidebar's waiting count (waitingCount) equals the rows in Stopped, Holding and Waiting, in both views and per project; the bold rows are the rows in Stopped, Holding and Waiting with an unseen agent message (the owner, 2026-11-08: a thread the person has read stops being bold and keeps its section), and the rows in New less those in New only for the person's own unsent words (no unseen agent message, not "Answered, not sent"); an archived row never counts.
  8. Replay: a store reopened from disk gives the same rows and threads (reply drafts included: they are files the store reads at open).
  9. Unsent work (a reply draft, picks, comments waiting) never sits in Quiet unless the thread is archived.
  10. Sort: the sections in the fixed order; newest first by last_at inside each, ties on the thread id; the archived list newest archived first, ties on the thread id. About one generated step in four shares the previous step's clock time, so last_at ties happen in the sections; a second property archives every open thread within one clock tick, so resolved_at ties happen in the archived list. Each fails if it met no tie. The trace fixtures keep one clock step per event: a thread id ends in random characters, so the order of a tie is not the same from one run to the next.

Invariant 7's waiting count is circular: waitingCount counts the rows in Stopped, Holding and Waiting, so it checks the counting code rather than the rules. unread is defined from the section and unseen.

The model also predicts every event's outcome (written, nothing to do, a replayed key, or the refusal code), which thread every message lands in, every question's state and every row's section, unseen count, read and came-back flags, last_at and last_agent_at. The store must match it exactly on every field after every step. (Until A, B and C below were fixed, the model derived each row under two look rules, the store's and the intended one, and recorded the difference; they are one rule now.)

The project menu's batches (design record "inbox-project-menu", approved 2026-10-14; packages/shared/inbox/project-batch.ts) add no rule: each is a loop over the single actions above, run synchronously. store.test.ts ("the project menu's batches") has the model decide on its own which threads a batch takes, apply the single rules thread by thread, and check every invariant after every batch and every Undo between generated steps; a batch undone back to back gives the project's rows back exactly (invariants 4 and 5, per project). After Mark all as read nothing in the project waits on the person; after Archive all nothing of it is listed, which is what hides the project in the window's sidebar (derived from the folders' listed, never stored).

Snooze

Snooze (approval "inbox-snooze", 2026-11-02) adds no section rule and no store line. A snooze is { thread_id, until, at } in inbox/snoozes.json, outside the log, and inboxSectionOf does not read it: an agent, read_thread, the cursors and the twin model see the same thread with or without one. The server's list model applies it on top of the sections, by the clock when the list is read:

  • Before until: the window's view (snoozed=exclude) takes the row out of its section into the Snoozed band; the default view keeps it in its section with snoozed. Its question stays open (invariant 3 holds on the store's own rows).
  • After until, until the person reads it: the row is back in its own section, except that Quiet comes back as New; it is bold (unread), its last_at is the later of its own and until, and it carries snooze_back.
  • What ends it (the entry is deleted): the person's reply, re-ask or new message in the thread, Archive, Mark read, Unsnooze, and a look after until. No agent write ends it. The project batches skip snoozed threads.

store-snoozes.test.ts runs the twin property: generated histories on a store that snoozes and on a twin that never does give the same section, unread, unseen, questions, read and resolved for every thread (the snooze is never part of the log).

Counts

  • Inbox and folder counts in the sidebar: rows in Stopped, Holding and Waiting (waitingCount in packages/inbox/held.ts). New is bold but not counted there.
  • projects[].unread in the list response: the bold rows (unread): in Stopped, Holding or Waiting with an unseen agent message, or in New (not one there only for the person's draft). A thread the person has read that still waits is not counted, as on the tab.
  • Questions are never counted one by one in the badge.
  • A snoozed row counts nowhere (sidebar, projects[].unread, the tab count, the decision queue) until its snooze ends.

What is window-only and never stored

  • Folding (packages/inbox/folding.ts): which messages open, which fold to one line, and the "N earlier messages" runs. Decided when a thread opens, kept in memory.
  • The look boundary of the current visit (lookBoundary): read from the thread before the window records the look, kept until the person leaves the thread, so "New since you looked" marks last through the visit.
  • Seen on sight (packages/inbox/seenOnSight.ts): which messages that arrived during the visit have been on screen long enough (their first lines in the thread's view for 1 s, the window in front, nothing covering the thread). Only its result is stored, as a look capped with through_seq.
  • Held order (packages/inbox/held.ts): the rows on screen change only on the person's action; agent activity waits behind "N new". While a thread is open, the person's own writes show in place and never reorder the list. The open thread is never held: its row takes its state in place (bold on an arrival, not bold once seen), it is never in "N new", and when the thread closes it settles where its state puts it, an unseen arrival included (New, or Waiting when it asks).
  • Toasts, the sound's arming and burst state, the sidebar and list widths (cookies), the Grid or Clean look.

Stored, on disk: looks, reads, archives, picks, sends, annotations and settings. (Decisions were removed in 2026-10; an older store's decisions.jsonl is left on disk, kept only so sequence numbers are never reused.)

Fixed violations

Found by the model on main at 53a49c81e and fixed since. Each has normal tests in store.test.ts ("the thread-state model: fixed violations") with the minimal sequences, and the trace fixtures that met them were regenerated (every known_violations list is empty now).

  • A. The Inbox's notes counted as the person's reply and as a look. Rule: Mark read's set-aside note and a late Undo's reopened note are the Inbox's, not the person's: neither is a reply (rule 7) nor a look. The store still writes both as person messages (so the agent receives them exactly as before), and every derived field reads past them (isInboxNote). The shapes the generated runs met, each a test:
    • the agent asks; Mark read; the agent writes news inside the 10 s Undo window; the note goes: New, unseen 1 (it read Sent with nothing unseen; trace hand-04-mark-read-racing-agent-message, step 4);
    • the agent asks; Mark read; the agent asks a new question; the note goes: Waiting, unseen 1 (unseen dropped to 0);
    • the agent asks, never opened; Mark read; the note goes; Undo: Waiting with unseen 1, as before the Mark read (it read 0; trace hand-03-mark-read-and-undo, step 7);
    • after the news and the note, an agent reads the thread: New (it read Quiet);
    • the person opened the thread after the news, then the note goes: Quiet (it read Sent);
    • the agent asks again and the person picks before the note: New, unseen 1; and archived after the news and the note: unseen 1.
  • B. Mark read on a came-back thread could leave it in the list. News; archive; the agent asks (came back, Waiting); the person replies with Keep open; Mark read. Rule: a Mark read made after the latest post-archive agent message, while it stands, ends "came back", so the thread is Archived at once, as the window's toast says. The person's reply that no agent had read used to keep back_from_archive, leaving it in Quiet ("Read") until the agent read it. Trace hand-09-came-back-mark-read-with-unread-reply, step 5; hand-17-came-back-mark-read-then-reply shows a reply after the Mark read bringing it back as Sent.
  • C. Undo reopened more than its own Mark read closed. Ruled: Undo reopens only what its own Mark read closed. The agent asks; Mark read (the question closes); the agent writes news (New, the question stays closed); Mark read; Undo: New, the question still closed (it jumped to Waiting with the first Mark read's question reopened). Mark read again then Undo no longer reopens older set-aside questions: that path was accidental. Trace hand-14-undo-after-an-earlier-mark-read, step 5; hand-16-undo-reopens-only-its-own-mark-read shows the reopened note naming only the questions this Undo reopened.

Old stores replay unchanged: nothing already written is rewritten or read differently, except these derivations (A's look, sent, unseen and waiting_on_person; B's back_from_archive while a Mark read made after the agent's last message stands; waiting_on_person is also false while any Mark read stands). New fields are additive (set_aside.read_seq on a question record, last_agent_at on a list row).

Trace fixtures

packages/shared/inbox/fixtures/thread-state/v1/: one JSON file per trace and index.json. The folder's README gives the format, the event vocabulary, the generator, the seeds and how to regenerate. The files are generated by store.test.ts through the same checked steps, and the test fails when they differ from what the store does, so they cannot drift from the code. A generated trace's events were drawn from its seed once and are kept in its file as data; the test replays them, so a new fast-check version changes nothing. A change of the format makes v2; a change of behaviour (a fixed violation) regenerates v1 in place, as the fix of A, B and C did. The look's cap (through_seq) is additive: the seen event gained an optional through, hand-18-look-capped-by-through was added, and no existing trace changed; the format stays v1. Threads the person starts are additive the same way: the person_thread and delivered events and hand-19-person-started-thread were added (the property runs draw both; the generated fixtures were drawn without them), no existing trace changed, and the format stays v1.

Reply drafts (approval "inbox-reply-drafts") are not in the fixtures: a draft writes no line, so no trace event names it, and no existing trace changed. A phone draws a row's section from the server and its count slot from the row's unsent (contract 7.62); the property runs draw drafts (draft op) and check rule 9 and invariant 9 after every step.