Repository navigation
Reply drafts on a linked machine's thread - #3977
Merged
Merged
Conversation
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.
… 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
…ft.ts and api.ts within their sizes
…ked-thread-reply-drafts
…r a restart, Discard while marks are unknown, and a held conflict's choice
…box tests for held drafts
…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
…, as the door now does
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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(replyDraftHostinpackages/inbox/machineDrafts.ts);replyDraft.tsimports 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.threads/:id/draftandthreads/:id/draft/delete. These are door routes for a machine's token only, rule 8'sdraftkind (see Hardening).409 draft_conflictincluded).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.stillOfferedininbox-machine-drafts.ts). Keep mine of words edited since the offer lets the offered words go once its save is through (letOfferedGoinreplyDraft.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).moreon the held record), each in turn.checkReplyDraftConflict,replyDraftFilesAfter,projectReplyDraft,replyDraftPreviewinpackages/core/inbox-reply-draft.ts;store.ts saveReplyDraftruns them too, and the input is checked bycheckInboxReplyDraftInput).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.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.follows).Wire.
reply-drafts.POST threads/:id/draftandPOST threads/:id/draft/delete.drafts=1,event: drafts {thread_id}./api/inbox/draftsrepliesnow includes a linked computer's rows, each with itsmachine.MachineView.drafts_held(additive): drafts held for that machine, counted in Unlink's existing "N waiting to send will be lost". Never part ofwaiting, so the machine's line is unchanged.GET threads/:id/draftthrough the forward) may carrynot_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) andfilesa held save added that it did not take.threads/:id/draft/delete) takesbase(only that version goes there) andnot_landed(Discard mine after a held conflict: only those words go, the draft there stays). Both additive; an older page sends neither.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-draftsmark, 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 fordrafts=1.The words are never dropped.
upload_not_found(a file it swept after a day) is sent again without that file. The words and the other files are kept.FILE_NOT_ADDED, the same stringComposeFiles.tsxshows today;packages/inbox/lostDraftFiles.ts). It stays until the person removes it; the leave guard asks while it shows, as for any refused tile.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 withoutstillOffered: the read after the other window's save returnednull); 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).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 withoutletOfferedGoin 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'sbase, 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 inpackages/server/inbox-peer-link.test.ts.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/.saveRemote's refresh of the box after kept remote words are saved (replyDraft.ts,onPersistenceChange) andresetRemoteThreadsForTests(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=1on 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, 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; thenot_aftercheck 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.tsfails when the two tables do not agree, when a POST route named for drafts is not thedraftkind, or when a draft route writes to the outbox or the log. Each check failed first with the rule broken.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 ininbox-door-draft-log.test.tsandinbox-machine-drafts.test.ts, each failing first.base,422without it), and the forward always names one. No Discard answer is kept either.recordLostDraft). A save on its way when the link goes holds nothing for that machine, and its words go to "Not sent" too.reply_aton thedraftsframe, so a list that could not be read again need not hide the draft.