Registry Mirror
Skip to content

Conversation

@backnotprop

@backnotprop backnotprop commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Documents the Inbox thread-state model, checks it against the real store with a model-based test, and adds trace fixtures the phone apps replay. No product code changes.

What is in it

  • adr/implementation/inbox-thread-state.md: the six sections and Archived, the two list views (the default list with archived threads in Quiet; the window's ?archived=exclude view with GET /threads/archived), the events, a transition table (event by state), the invariants, the counts, what is window-only and never stored (folding, held order, the current visit's look boundary), and three known violations. Linked from CLAUDE.md's Inbox section in one line.
  • packages/shared/inbox/store.test.ts: the existing fast-check op harness is extended (not a second harness). Op gains seen, Mark read, Undo, the agent's read, the set-aside note and the Send that skips; run reports each outcome and records decisions as the Send route does. A new ThreadStateModel is an independent account of the rules: it predicts every op's outcome (written, nothing to do, a replayed key, or the refusal code), which thread each message lands in, every question's state, and each row's section, unseen count, read and came-back flags. After every step the store and the model must agree and every invariant must hold.
  • packages/shared/inbox/fixtures/thread-state/v1/: 15 hand-written and 24 generated traces, index.json and a README (format, events, generator, seeds, how to regenerate).

Invariants checked after every step

  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 plus the archived list hold every thread, never one twice.
  3. A question still waiting on the person keeps its thread in Stopped, Holding or Waiting.
  4. Mark read then Undo, back to back, gives the thread back exactly (section, unseen, questions, picks); Undo always clears the read fields.
  5. Archive then Unarchive loses no message, question, pick or decision; the row comes back identical.
  6. PR 1874's rules: an agent message after the archive line brings the thread back while something waits; Mark read on a came-back thread returns it to Archived; Unarchive clears a read made while archived.
  7. Counts: waitingCount (the sidebar) equals the rows in Stopped, Holding and Waiting, in both views and per project; the folders' unread equals the rows in Stopped, Holding, Waiting and New; an archived row never counts; waitingDecisionCount (the Decisions count) matches the model.
  8. Replay: a store reopened from disk gives the same rows and threads.
  9. Sort: fixed section order, newest first by last_at, ties on the thread id; archived newest archived first.

Note on 7: the sidebar's count is Stopped, Holding and Waiting only (waitingCount in packages/inbox/held.ts); New is bold (unread) but not in that count. The test pins the code as it is.

Run time and seeds

bun test packages/shared/inbox/store.test.ts runs in about 4 to 9 s locally (the whole file, the existing properties included). Fixed seeds: 20261012 (300 generated sequences of 15 to 45 ops; about one step in four shares the previous step's clock time, so last_at ties in the sections, and the run fails if none was met); 20261015 (every open thread archived in one clock tick, so resolved_at ties in the archived list, 60 runs; reversing that tie-break turns it red), 20261013 (Mark read then Undo on every thread, 100 runs), 20261014 (Archive then Unarchive on every thread, 100 runs).

How the phones consume the fixtures

Each trace is the event sequence and, after each step, the expected sections in both views, the archived list, the counts, and each thread's row and question states, plus known_violations (the steps where the Inbox breaks a rule today, with what the rule wants). A phone kit feeds the events in order to its own list handling and compares after each step; index.json lists the files. The generated traces (seeds 1001 to 1024, each starting with a root) keep their events as data: the test replays them from the files and never resamples unless PLANNOTATOR_INBOX_TRACES=resample, so a fast-check upgrade changes nothing. PLANNOTATOR_INBOX_TRACES=write regenerates the expectations. A format change makes v2.

Violations found (kept as test.failing, product code untouched)

  • A. The Inbox's own notes (Mark read's set-aside note, a late Undo's reopened note) count as the person's reply and as a look. The model derives every row under two look rules: today's (the store's) and the intended one (notes are neither). The store must match today's rule exactly on every field after every step; the difference between the two rules is A, recorded and classified into six pinned shapes, each with its own test.failing case and a plain test proving the case shows its shape today. Forcing unseen to 0 on every thread with a note (the reviewer's mutation) turns the generated runs red. Includes: Mark read, news inside the Undo window, the note: Sent with nothing unseen instead of New (trace hand-04, step 4); Mark read, a new question, the note: Waiting but unseen 0; the late Undo: unseen 0 (trace hand-03, step 7).
  • B. News; archive; the agent asks (came back, Waiting); the person replies with Keep open; Mark read. The thread stays in the list (Quiet, Read) because the person's unread reply keeps back_from_archive; the rule (and the toast) says it goes back to Archived. Trace hand-09, step 5.
  • C. Ruled: Undo reopens only what its own Mark read closed. The agent asks; Mark read; the agent writes news; Mark read; Undo. Today Undo also reopens the first Mark read's question and the thread jumps to Waiting. Trace hand-14, step 5.

The Archived column of the transition table is proved on a real store by the "Archived column" tests: an archived thread refuses pick, Send, Mark read and Undo only while no agent wrote after the archive line.

Checks run

  • bun run typecheck: pass. The test file also type-checks under a throwaway config with bun types (the package config excludes tests).
  • bun test: store.test.ts (29 pass, about 4 s) and store-mark-read, store-supersede, store-archived, list.test.ts, tests/never-touch-the-real-inbox.test.ts, tests/package-bunfig.test.ts (85 pass).
  • Regenerating the fixtures is byte-identical.
  • gitleaks git . --config .gitleaks.toml --log-opts="<merge-base>..HEAD": no leaks. Semgrep was not run locally (not installed); the change has no request input, exec or digest for its rules to match.

…fixtures

- adr/implementation/inbox-thread-state.md: the sections, the two list
  views, the events, a transition table, the invariants, what is
  window-only, and three known violations.
- store.test.ts: the existing fast-check op harness gains seen, Mark read,
  Undo, the agent's read, the set-aside note and the Send that skips; an
  independent ThreadStateModel predicts every outcome, thread, question
  state and row, and the invariants are checked after every step in both
  list views, with a replay from disk. Hand-written edges, and
  test.failing cases for the three violations it found.
- fixtures/thread-state/v1: 15 hand-written and 24 generated traces
  (seeds 1001 to 1024) for the phone apps, regenerated and verified by the
  same test.

No product code changes.
- The doc's Archived column: an archived thread refuses pick, Send, Mark
  read and Undo only while no agent wrote after the archive line; one that
  came back and returned takes them (Undo brings it back as it was). The
  cells are proved by new "Archived column" tests on a real store.
- Seventh place, not eleventh; routing joins only the newest unnamed
  thread the session started, while it is open; invariant 7 called
  circular except decisions_waiting.
- The model's look rule is now the intended one, written independently:
  the Inbox's notes are neither the person's reply nor a look. Where the
  store differs (violation A) the check allows it only on a thread with a
  note, only in the look fields, and only in one of six pinned shapes,
  each with its own test.failing case (the new question variant and the
  late Undo included).
- Shared clock ticks in the generated runs exercise the sort tie-break;
  the run fails if no tie was met.
- Fixtures: generated traces start with a root and keep their events as
  data (replayed, never resampled unless asked), so a fast-check upgrade
  changes nothing; every trace lists its known_violations, detected per
  step (hand traces declare theirs and are compared).
- The model derives every row under two look rules: today's (the store's:
  the Inbox's notes count as the person's reply and as a look) and the
  intended one. The store must match today's rule on every field after
  every step; the difference between the rules is violation A, recorded
  and classified, never allowed for in the store check. Forcing unseen to
  0 on every thread with a note now turns the generated runs red.
- Section and archived-list ties are counted apart; a new property
  archives every open thread in one clock tick so resolved_at ties, and
  reversing the archived tie-break turns it red.
- asks>asks unseen- noted as covering two A cases.
@backnotprop
backnotprop merged commit 1fd161a into main Oct 12, 2026
32 checks passed
@backnotprop
backnotprop deleted the feat/inbox-thread-state-model branch October 12, 2026 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant