Registry Mirror
Skip to content

Conversation

@backnotprop

@backnotprop backnotprop commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Fixes the three bugs the thread-state model (#1882, adr/implementation/inbox-thread-state.md) found, in product code, and flips their tests. The model's "today's rule" and "intended rule" are now one rule, and the store matches it exactly on every field after every step.

A. The Inbox's own notes counted as the person's reply and as a look

Minimal sequence: the agent asks; Mark read; the agent writes news inside the 10 s Undo window; the set-aside note goes. The row read Sent, unseen 0. It should read New, unseen 1: the person wrote nothing, and has not seen the news.

The model found six shapes of this, each now a normal test:

  • news inside the Undo window, then the note: New, unseen 1 (was Sent, 0);
  • a new question before the note: Waiting, unseen 1 (unseen dropped to 0);
  • late Undo (its reopened note): Waiting, unseen 1 as before the Mark read (was 0);
  • after the news and the note, an agent reads the thread: New (was Quiet);
  • the person opened the thread after the news, then the note: Quiet (was Sent);
  • a pick before the note: New, unseen 1; archived after news and the note: unseen 1 (was 0).

Fix: the notes are still stored as person messages and reach the agent exactly as before (wake, wait_for_reply, read_thread). Every derived field reads past them through one predicate, isInboxNote (@plannotator/core/inbox-types, additive export):

  • the store's listRow (the look, unseen, sent, back_from_archive), threadSummary (waiting_on_person) and markSeen (it now writes the look a note no longer stands in for);
  • the window's lookBoundary and the visit boundary (packages/inbox/folding.ts, Thread.tsx), "since your last reply" for dropped picks, the "Saved for / Delivered to" line (stays on the reply before the note, never under a note), and the asker note's "last message is the person's" check;
  • held.ts: an agent message followed by a note before the next list read used to slip in without "N new", because the row's last message became the person's. Rows gain the additive last_agent_at, which the held list counts agent activity by. An older row without the field falls back to the old rule.

B. Mark read on a came-back thread could leave it in the list

Minimal sequence: news; archive; the agent asks (came back, Waiting); the person replies with Keep open; Mark read. The toast said "went back to Archived", but the thread stayed in the list (Quiet, Read) until the agent read the reply, because the unread reply kept back_from_archive.

Fix: a Mark read made after the latest post-archive agent message, while it stands, ends "came back". The unread-reply reason now counts only while no such Mark read stands. A reply the person sends after the Mark read ends the read and brings the thread back as Sent (new trace hand-17). Undo still brings it back as it was (Waiting).

C. Undo reopened more than its own Mark read closed

Owner ruling: Undo of a Mark read reopens only the questions that Mark read closed. Questions an earlier Mark read set aside (and told the agent about) stay closed.

Minimal sequence: the agent asks; Mark read (the question closes); the agent writes news; Mark read; Undo. It jumped to Waiting with the first Mark read's question reopened. It now stays New with that question closed. The other path, Mark read again then Undo to get older set-aside questions back, no longer reopens them. That path was accidental.

Fix: each question a Mark read closes records which one did it, as set_aside.read_seq (that Mark read's person_read_seq, additive). Undo reopens only questions whose read_seq equals the root's current person_read_seq. Records older than the field match by time (set_aside.at equals the root's person_read_at; both are the same stamp). Replay is deterministic: the identity is in the log. Reopened notes name only the questions this Undo reopened (new trace hand-16). With no Mark read on the root (after an Undo, or an Unarchive that dropped it), Undo writes nothing.

Compatibility

  • Append-only store, fields additive (set_aside.read_seq, row last_agent_at). Old stores replay unchanged except for the corrected derivations: A's look, sent, unseen and waiting_on_person, and B's back_from_archive while a Mark read made after the agent's last message stands.
  • Phone wire: shape unchanged. adr/implementation/inbox-mobile.md notes the row semantics (notes read past, B, C, last_agent_at).
  • Docs: the model doc ("Known violations" becomes "Fixed violations", transition table cells, invariant 4), CLAUDE.md ("every question a Mark read closed" becomes only that Mark read's, notes are not a reply or look), the fixtures README, and the marketing Inbox reference.

Fixture version: stays v1, regenerated in place

The README and model doc say a format change makes v2, and a behaviour change (a fixed violation) regenerates v1 in place. The format is unchanged. PLANNOTATOR_INBOX_TRACES=write regenerated the files: hand-03, hand-04, hand-09, hand-14, gen-seed-1010, gen-seed-1019, gen-seed-1024 and index.json changed. Every known_violations list is now empty (the field stays in the format), and hand-16 and hand-17 were added. A phone kit that skipped the listed steps can stop skipping them.

Tests

  • bun test packages/shared/inbox packages/server/inbox*: 325 pass. This includes the model's generated runs, with Mark read then Undo now checked even when an earlier Mark read's questions are set aside, and Undo checked to leave exactly the earlier ones set aside. The former test.failing cases are normal tests, plus new ones: B with a reply after the Mark read, C with notes and a second Undo, C on old records without read_seq, and A then markSeen.
  • DOM_TESTS=1 bun test --isolate packages/inbox: 212 pass. New tests: held.test.ts (an agent message plus a note still counts as "N new"; a note alone does not) and folding.test.ts (notes are not a look).
  • bun run typecheck: clean.
  • Playwright on a freshly compiled binary (--define __CLI_VERSION__="0.0.0-dev"): inbox-mark-read, inbox-archived, inbox-order and inbox-thread-folding, 20/20 pass. Temp data dirs only.

Review follow-ups (merged with main at 94c02b8, #1875)

  • Merge: held.ts combines last_agent_at with Inbox: the row you open stays put; the list settles when the thread closes #1875's openedHere exemption. In AGENTS.md, this branch's Mark read and "told once" paragraphs sit with main's "The window" paragraph.
  • Rows not yet on screen count as news only while their last real message is an agent's (sent === null; sent reads past the notes, so "agent message, then note" still counts). A thread unarchived on a phone or in another tab, whose last word is the person's (Sent, or Quiet after the agent read it), no longer shows "1 new" or stays out of the list on settle. Test in held.test.ts.
  • waiting_on_person is false while a Mark read stands, since nothing waits on the person then. The model now checks it after every step; dropping the clause fails the generated runs. The ADR is updated.
  • Fold plan: the last real message stays open when notes trail it (also under Fold all), so the reply's "Saved for / Delivered to" line is visible.
  • DOM tests (threadFolding.test.tsx): after a reply then a set-aside note, the line sits on the reply, never on the note. An agent message posted inside the Undo window still reads New, both by the thread's boundary and by the visit boundary (lookSeq).

Known pre-existing follow-up (not fixed here)

agent_checked_seq is per thread. A note delivered to session B (recordDelivery calls markAgentChecked up to the note) can therefore mark an earlier reply addressed to session A as checked/delivered.

Tests on the merged code (head after the merge)

  • bun test packages/shared/inbox packages/server/inbox*: 325 pass
  • DOM_TESTS=1 bun test --isolate packages/inbox: 234 pass
  • bun run typecheck: clean
  • Playwright on a freshly compiled binary: inbox-mark-read, inbox-archived, inbox-order, inbox-thread-folding, inbox-open-stays-put: 27/27 pass

CI fix: inbox-replaced.spec.ts ("a whole message withdrawn…")

Cause: for rows already on screen, the held list counted agent activity by last_agent_at alone. In the spec, the agent replaces a question in the thread the person has open, and then the person sends. That replacement became "1 new" when the thread closed. The spec then pressed that stale notice instead of the one for the new thread, and the new thread stayed held.

Fix: hasNewAgentActivity requires the row's last real message to be an agent's (sent null, notes read past) for rows on screen and off. Without notes this is exactly main's last_author === 'agent' rule. New held.test.ts case. The test itself is unchanged.

Tests at caddf93: shared/server inbox 325 pass; inbox DOM (DOM_TESTS=1 --isolate) 235 pass; typecheck clean; the whole inbox Playwright suite (bun run test:e2e:inbox) on a freshly compiled binary: 197 passed, 2 skipped (the run-by-hand tailnet test and a WebKit-conditional pinch test).

A. The Inbox's own notes (Mark read's set-aside note, a late Undo's
reopened note) are no longer the person's reply or a look. They are still
stored and delivered as person replies; every derived field reads past
them (isInboxNote): the row's unseen, sent, waiting_on_person and
back_from_archive, markSeen, the window's lookBoundary, the reply box's
"since your last reply", the Saved for / Delivered to line, and the held
list's agent activity (the row's additive last_agent_at).

B. A Mark read made after the latest post-archive agent message, while it
stands, ends "came back": a came-back thread goes back to Archived at
once, even while the person's earlier reply there waits on the agent. A
reply after the Mark read brings it back as Sent.

C. Owner ruling: Undo reopens only the questions its own Mark read closed.
set_aside gains read_seq (the Mark read's person_read_seq); records
without it match by set_aside.at = person_read_at. Reopened notes name
only what this Undo reopened.

The model's two look rules converge into one; the test.failing cases are
normal tests; fixtures/thread-state/v1 is regenerated in place (format
unchanged, every known_violations list empty, two hand traces added).
Conflicts:
- AGENTS.md: keep this branch's Mark read and "told once" paragraphs and
  main's "The window" paragraph.
- packages/inbox/held.ts: hasNewAgentActivity combines last_agent_at with
  #1875's openedHere exemption; a row not on screen counts only while its
  last real message is an agent's (sent null).
- held.ts: a row not on screen is news only while its last real message
  is an agent's (sent null; sent reads past the notes), so a thread
  unarchived elsewhere whose last word is the person's (Sent, or Quiet
  after the agent read it) raises no "1 new" and settles in. Test added.
- waiting_on_person is false while a Mark read stands; the model checks
  it after every step (a mutation dropping the clause fails), ADR updated.
- The fold plan keeps the last real message open when notes trail it, so
  the reply's "Saved for / Delivered to" line shows; Fold all does too.
- DOM tests (threadFolding.test.tsx): a reply then a set-aside note keeps
  the line on the reply; an agent message posted inside the Undo window
  still reads New, by the thread's boundary and by the visit boundary.
The held list counted agent activity by last_agent_at alone for rows on
screen, so an agent message the person answered afterwards (here: a
replacement in the thread they had open, then their Send) became "1 new"
when the thread closed. inbox-replaced.spec.ts then pressed that stale
notice instead of the one for the new thread, which stayed held.

hasNewAgentActivity now requires the row's last real message to be an
agent's (`sent` null, notes read past) on screen and off, which is main's
`last_author === 'agent'` rule with the Inbox's notes read past.
@backnotprop
backnotprop merged commit 032f318 into main Oct 12, 2026
32 checks passed
@backnotprop
backnotprop deleted the fix/inbox-thread-state-abc branch October 12, 2026 21:49
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