Skip to content

Reply drafts on a linked machine's thread - #3977

Merged
backnotprop merged 22 commits into
mainfrom
feat/linked-thread-reply-drafts
Nov 26, 2026
Merged

backnotprop merged 22 commits into
mainfrom
feat/linked-thread-reply-drafts

Conversation

@backnotprop

@backnotprop backnotprop commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

On a thread that lives on another linked computer, a reply draft now works the way it does on this computer's threads. Before, words typed there were kept only in this page and this browser (remoteWords, #4022's stopgap), never as a draft.

Rebuilt on main's reply-draft client (#4022). The window uses the same client for a far thread as for a local one: the conflict line, words that did not land kept and saved again, the keepalive as the page goes, and browser storage when a save does not reach this Inbox. Nothing is added to the window. The client knows nothing of linked machines: the Inbox hands it canPersist / onPersistenceChange / isRemote (replyDraftHost in packages/inbox/machineDrafts.ts); replyDraft.ts imports nothing of linked machines.

Mechanism. The draft is stored on the thread's own computer, as the thread is. Local drafts are already shared across windows (event: drafts), so every window of both computers, and a phone of that computer, sees one draft.

  • The window saves, reads and discards it through the forward: threads/:id/draft and threads/:id/draft/delete. These are door routes for a machine's token only, rule 8's draft kind (see Hardening).
  • Online: the save goes straight there, and the far answer is passed on (409 draft_conflict included).
  • That computer asleep, or a draft already held for that thread: the draft is held here in one file per thread (inbox/machine-drafts/<machine>/<thread>.json, 0600, overwritten by each save; packages/server/inbox-machine-drafts-held.ts), never in the outbox. It is never listed as waiting and never makes a notice. It is answered here as that computer will hold it, survives a restart of this Inbox, and lands once when the computer is back (its own small drain: what left first again under its key, then the saves folded behind it). A conflict at landing is never joined: the draft there stays, and the person's words are offered in every window with the existing conflict choice (Keep mine / Discard mine), through a restart, until they choose. A Discard, held or sent straight there, goes only for the version the person threw away (base): newer words typed there meanwhile stay, and every window reads the draft again.
  • Words a held conflict offers stay offered until the person chooses in some window (Keep mine or Discard mine) or the draft holds them. A save or Discard from another window that never showed them (straight there, or held here) does not settle them: a window opening the thread later still gets the offer (stillOffered in inbox-machine-drafts.ts). Keep mine of words edited since the offer lets the offered words go once its save is through (letOfferedGo in replyDraft.ts, the same Discard-mine call, not_landed: version). A window settles only the version it actually put in the box (packages/inbox/replyDraftHeldOffer.ts).
  • A window shows one choice at a time. Held words a read finds while another choice is waiting in that window (its own conflict, unsaved edits in the box, an offered draft) are offered there once that choice is settled, in the box, with the conflict line. Choosing on the window's own conflict never lets them go.
  • Offered words not chosen on yet are never written over: when another held save meets a newer draft there, its words are offered after the first (more on the held record), each in turn.
  • Saves held here follow the same rules as the store (checkReplyDraftConflict, replyDraftFilesAfter, projectReplyDraft, replyDraftPreview in packages/core/inbox-reply-draft.ts; store.ts saveReplyDraft runs them too, and the input is checked by checkInboxReplyDraftInput).
  • The far stream says when a draft changes (drafts=1). This Inbox reads that computer's list again and tells its windows. The box, the row's Draft mark, the Drafts page and a floating draft then move.
  • Send's clear_draft, Take back, files and quote all work there. A held Send settles the held draft (gone, or the files it did not carry) only once it is delivered; refused, its words are the draft again.
  • A file attached to a far draft uploads to that computer and joins its draft. While that computer sleeps, the upload is refused on its tile, as today; the words are still held.
  • A far draft save from a page an earlier run of this Inbox served is taken, as a local one is (follows).

Wire.

  • New list mark: reply-drafts.
  • New door routes, machine only: POST threads/:id/draft and POST threads/:id/draft/delete.
  • New stream ask and frame: drafts=1, event: drafts {thread_id}.
  • /api/inbox/drafts replies now includes a linked computer's rows, each with its machine.
  • MachineView.drafts_held (additive): drafts held for that machine, counted in Unlink's existing "N waiting to send will be lost". Never part of waiting, so the machine's line is unchanged.
  • The far draft read (GET threads/:id/draft through the forward) may carry not_landed (additive): { words, version, conflict?, files? }, the person's words the draft there does not hold (a conflict a held save met, or words that computer refused) and files a held save added that it did not take.
  • The forwarded Discard (threads/:id/draft/delete) takes base (only that version goes there) and not_landed (Discard mine after a held conflict: only those words go, the draft there stays). Both additive; an older page sends neither.
  • The mobile contract was regenerated; the two new routes and the new field are undecided.

An older Plannotator on the other computer, or one whose list is not read yet (this Inbox restarted while it sleeps). Its list has no reply-drafts mark, so the window sends no draft request for its threads: today's behaviour exactly. The words stay in the page and in browser storage (remoteWords), and the leave guard asks. Once its list carries the mark, those words are saved there once, on the draft this window knew, or the conflict shows (packages/inbox/remoteReplyWords.ts, remoteToDraft). An older Inbox here never asks for drafts=1.

The words are never dropped.

  • A held save that the other computer refuses with upload_not_found (a file it swept after a day) is sent again without that file. The words and the other files are kept.
  • A save refused for any other reason stays the draft shown here, through a restart. The thread's next save carries it.
  • A held save that added a file the other computer swept since lands without it (that computer skips it): the file is never dropped unsaid. Its tile in the reply box (and a floating box) shows refused with the words the reply box already uses for a file that could not be added, "Not attached: that file could not be added." (FILE_NOT_ADDED, the same string ComposeFiles.tsx shows today; packages/inbox/lostDraftFiles.ts). It stays until the person removes it; the leave guard asks while it shows, as for any refused tile.
  • A held conflict's words are kept on this Inbox (not only in the window that showed them) until the person chooses: another window's save or Discard never drops them.
  • Unlinked with a draft held (from either computer): every word, its files' names and its quote join the existing "Not sent" list to copy (the only time a draft's words enter the outbox: an entry written straight as dropped, never queued or sent).
  • Words typed in a far thread while its marks are not known (this Inbox restarted) are kept in browser storage beside, never over, words whose save failed; a new page takes both back.
  • Discard while the far computer's marks are not known also throws away the draft held here for it, so its words never come back when that computer wakes.
  • A save that goes straight there reads the held record again once it is answered, so a save held here meanwhile (or a Send's mark) is kept and lands after it.
  • Unlinked with more than one set of offered words held: every set joins "Not sent".
  • When that computer says its draft changed, this Inbox keeps the draft it last heard until it reads it again. A save held before that read keeps that draft's files and quote, and that computer still judges it against its newer draft as it lands.
  • A Send that carries words a conflict offered settles them on this Inbox, so they are never offered (and sent) again; if the reply is refused they are offered again, once.
  • A Send of a draft saved there, while that computer sleeps or before a window reads it again, hides those words here at once (the read, the row's Draft mark, the Drafts page) until the reply lands or is refused.
  • A Discard pressed while a save is still on its way, or after this Inbox restarted with a held save landed, goes for the words the window saved last even under their newer version. Newer words typed on the other computer still stay.
  • Offered words are settled only by a draft of exactly those words, and at most 8 wait behind the one offered.
  • Unlink writes "Not sent" before the held drafts go (they stay on disk if it cannot), and words a held reply carried appear there once.

What a person sees differently from main. On a far thread the box behaves as a local one: "Saved …", "Not saved", the conflict line with Keep mine / Discard mine, Restore draft, the Draft mark and the Drafts page. A file a held draft named that the far computer swept shows its tile as "Not attached: that file could not be added.". A held draft lost to Unlink is a "Not sent" line. When more than one set of the person's words waits on a choice, the box offers them one after another with the same conflict line. A Discard that finds newer words typed on the other computer leaves them, and the box shows them. Every one of these strings already exists on main; no new words.

Tests.

  • packages/server/inbox-machine-drafts.test.ts: held through a restart; 300 autosaves leave one small file (size bound) and land once; behind one that left without an answer (and the machine slept before answering); Discard after saves wins; a held Discard keeps newer far words; a held conflict offered, never joined, Keep mine / Discard mine; a held conflict's words still offered after another window saves and Discards (online and held, through a restart), settled only by Keep mine or Discard mine (fails without stillOffered: the read after the other window's save returned null); two held conflicts in a row, each offered in turn, Discard mine letting only its own go and both handed back on Unlink; a save held while a direct save waits for its answer is kept; a Discard (online, and held while away) never goes for a version the window did not show; a Discard naming the version shown for a held draft after it landed still goes; discarded there meanwhile; a swept file in a whole list; a swept file a held save added (named, not dropped); a long paste removed while away (never stuck); other refusal through a restart; held Send delivered, refused, and with a file left; a save held after that computer said its draft changed keeps the file and quote of the draft last heard; Unlink with long words, file and quote; and a table of saves run on the store and on the held draft giving the same drafts and refusals (mentions, base_files).
  • packages/server/inbox-machine-drafts-forward.test.ts: the real forward and link: an earlier run's page saving (another Inbox's page and its Discard refused); Unlink with a held draft (drafts_held, the Not sent line).
  • DOM: packages/inbox/farReplyDrafts.test.tsx (a swept file's tile refused and removable; words after a restart kept apart in storage and both taken back; Discard while marks are unknown; a held conflict's Keep mine and Discard mine with no joined text, Discard mine's server call failing first without it; a new window offers a held conflict after another window saved on the far draft, and Keep mine of edited words settles it for good, failing first without letOfferedGo in Keep mine; a window showing its own conflict when held words meet newer words there: after its Keep mine or Discard mine the held words are offered in the box, never let go unseen; two held conflicts in a row offered one after the other; a Discard after newer words were typed there that the window never showed leaves them there. Its stand-in far door honours a Discard's base, refuses a Discard without it, and answers a save sent again under its key as the real store does), packages/inbox/machineDrafts.test.ts (incl. hasMachineMark), the drafts frame in packages/server/inbox-peer-link.test.ts.
  • CI only:
    • packages/server/inbox-reply-drafts-linked.test.ts: two real Inboxes, both ways: held autosaves through a restart; the stuck-draft sequence (away, a long paste as a chip, autosave, chip removed and words deleted, back: lands, both sides agree); a held Discard sparing newer words typed there; a held save meeting newer words (offered, never joined; Discard mine) and meeting a Discard there (becomes the draft); two held saves meeting newer words in a row (offered in turn) and a Discard naming a version not shown refused; a held save naming a file swept there (not_landed.files); a reply held with the draft (settled only once delivered; a refused one gives its words back as the draft); Unlink from the other computer with a long draft, a file and a quote held (one direction: it ends the link). "Meanwhile there" is made by stopping this Inbox while that computer's own window writes.
    • tests/e2e/inbox-reply-drafts-machines.spec.ts: proof PNGs in .local/proof/reply-drafts-machines/.
  • Not covered by a test: saveRemote's refresh of the box after kept remote words are saved (replyDraft.ts, onPersistenceChange) and resetRemoteThreadsForTests (a test seam).

e2e: inbox-reply-drafts-machines.spec.ts inbox-reply-drafts.spec.ts inbox-machines.spec.ts

Follow-ups (not in this PR).

  • drafts=1 on the events stream is not limited to linked computers. It carries ids only, no words.
  • forward() in inbox-machines.ts: a separate refactor.

Hardening.

  • Draft text never goes into a record of finished commands. The outbox and the door's command log keep finished commands for days, so that a retry gets the same answer. Draft text is the words a person is still typing, so it must not go into them. A reply draft route is now its own kind, draft, in the outbox's table (DOOR_WRITES) and on the door (carries: "draft"). The outbox throws for such a route and writes nothing. The door never writes its answer to the command log or keeps it in memory, whatever the answer; the not_after check and one request at a time per key still apply. A new route that carries draft text must use this kind. packages/server/inbox-draft-routes.test.ts fails when the two tables do not agree, when a POST route named for drafts is not the draft kind, or when a draft route writes to the outbox or the log. Each check failed first with the rule broken.
  • A save sent again is answered by the owner's store. The draft file keeps the key of the save that made it (last_key, never served). A save under that key answers the draft as it is: nothing is written and no window is told. The earlier rule that sent a held save again when its words were already there is gone. Such a save now settles on the draft there, so a file, a quote or recipients changed there are never written over. Tests in inbox-door-draft-log.test.ts and inbox-machine-drafts.test.ts, each failing first.
  • A Discard at the door must name the version it throws away (base, 422 without it), and the forward always names one. No Discard answer is kept either.
  • Unlink. The words go straight into "Not sent" (recordLostDraft). A save on its way when the link goes holds nothing for that machine, and its words go to "Not sent" too.
  • No words held for a draft that is already there. A record kept only to name files a landed save could not keep holds no words, and a list that names no draft for the thread clears it. The row's Draft mark follows that machine's list.
  • While the thread's computer sleeps, a draft last heard there is not shown once that computer said it moved on (sent, discarded or changed there), when its list could not be read again after it said the draft changed, or when a list read that started after the draft was heard names another version. A draft saved there just now still shows. Words typed here and held are untouched.
  • A delivered held reply's files are not carried into the next draft's save, so they are never said to be "not added". A held reply whose outbox entry is gone (settled long ago and compacted) is read as delivered, so sent words do not come back.
  • No released version records draft text in the door's log: the released door has only the read-only draft route, which is never recorded.
  • Follow-ups: held files left on disk if writing "Not sent" fails on Unlink; the clock-skew note on removals; the Unlink warning's wording; reply_at on the drafts frame, so a list that could not be read again need not hide the draft.

A thread's reply draft now lives on the thread's own machine, as the thread
does: the window saves, reads and discards it through the forward
(threads/:id/draft, threads/:id/draft/delete, door routes for a machine's
token only). Online it goes straight there; with that machine away it is held
here as an auto outbox entry (never "waiting", no notice), answered here, and
lands when the machine is back, a conflict keeping both words. The far stream
tells this Inbox when a draft changes (drafts=1), so the box, the row's Draft
mark, the Drafts page and a floating draft move in every window of both
machines. Machines list the new mark reply-drafts; an older peer has none and
the window keeps nothing for its threads, as before.
@backnotprop backnotprop added the ci:e2e Run the full browser suite (Inbox window e2e) on this PR label Nov 24, 2026
… keep any other refusal's words, hold a draft whole
…ply-drafts

# Conflicts:
#	apps/mobile/contract/generated/swift/Wire.swift
#	apps/mobile/contract/parity/ledger.json
#	packages/core/inbox-types.ts
… client

Main rewrote the reply-draft client (never-lost words, #4022). Its client is
the base here; the far-thread path is applied onto it:

- A linked computer's thread that keeps drafts (mark `reply-drafts`) saves,
  reads, discards and sends through the forward as a local thread does, with
  the same client (conflict line, words that did not land kept and saved
  again, keepalive, kept in browser storage when a save does not reach this
  Inbox). While that computer sleeps, this Inbox holds the save in its outbox
  (one copy) and answers for it.
- `remoteWords` is now the fallback only for a thread whose computer keeps no
  draft from here (an older Plannotator, or its list not read yet): nothing
  is sent, the words stay in the page and the leave guard asks, as on main.
  Once that computer keeps drafts, the kept words are saved there once on the
  draft this window knew, or the conflict shows (remoteReplyWords.ts,
  `remoteToDraft`).
- DOM test farReplyDrafts.test.tsx: the pane over the real draft forward and
  a stand-in far door with the compare-and-set.
- Mobile contract regenerated.
… of draft rules

A draft held while the other computer is away is no longer an outbox entry:
each thread's held draft is one file, overwritten by each save, landed once
by its own drain when that computer is back. The outbox loses its three
draft-specific holes. Saves held here are checked and made by the same pure
rules as the store's (checkReplyDraftConflict, replyDraftFilesAfter,
projectReplyDraft, replyDraftPreview in core), so mentions and base_files
no longer drift. A held Send that leaves a file updates the draft; a save
from an earlier run's page is taken as a local one is; Unlink counts held
drafts and keeps their words in the Not sent list. The reply box client no
longer knows about linked machines: the Inbox hands it canPersist.
… joined, Discard only what was thrown away, settle on delivery
…r a restart, Discard while marks are unknown, and a held conflict's choice
…ice, queue a second conflict, Discard only the version thrown away, keep a save held meanwhile
… save held before the next read keeps its files and quote
…inked-thread-reply-drafts

# Conflicts:
#	apps/mobile/contract/parity/ledger.json
…let a Discard go for words a save on its way landed, bound and match offered words exactly, write Not sent before dropping held drafts
…moved on while its machine sleeps

- The reply draft's save and Discard through the door no longer record an answer holding the draft's words in
  inbox/device-commands.jsonl. Both are compare-and-set, so a save under a key already seen is applied again; one
  that already landed meets its own words and goes on on that draft. A Discard's plain answer is still kept.
- While the thread's machine is away, a draft last heard that it has since said moved on (sent, discarded or
  written over) is not shown, and words typed then stand on no draft.
- A delivered held reply's files are no longer carried into the next draft's save.
- A held reply whose outbox entry is gone is read as delivered, never as refused.
…ked-thread-reply-drafts

# Conflicts:
#	apps/mobile/contract/generated/swift/Wire.swift
#	apps/mobile/contract/parity/ledger.json
#	docs/agent-guides/inbox-machines.md
#	packages/core/inbox-types.ts
#	packages/inbox/inboxUrl.ts
#	packages/server/inbox-machines.ts
#	tests/e2e/slice-rules.ts
A reply draft route is now its own kind, "draft", in the outbox's table
and on the door (carries: "draft"). The outbox refuses to hold one, and
the door never records its answer, on disk or in memory. A table-driven
test holds the two tables together and checks that a draft route
writes nothing to either record.

With no kept answer, the owner's store answers a save sent again: the
draft file keeps the key of the save that made it (last_key), and the
same key again answers the draft as it is, with nothing written. The
equal-words re-send is gone. A Discard at the door must name base.

Unlink's rescue of words goes straight into "Not sent" (recordLostDraft),
and a save on its way when the link goes holds nothing for that machine.
A record kept only for files a landed save could not keep holds no
words, and the row's mark follows the list. While a machine sleeps, a
draft last heard is not shown once its list says it moved on or could
not be read again.
@backnotprop
backnotprop marked this pull request as ready for review November 26, 2026 14:09
@backnotprop
backnotprop merged commit 1df88dd into main Nov 26, 2026
95 of 97 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:e2e Run the full browser suite (Inbox window e2e) on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant