Repository navigation
Inbox: typed words are never lost - #4022
Merged
Merged
Conversation
…aft waits A saved draft that arrived while the box was open (another window or device saved it, or the thread's first read answered late) stood behind Restore draft, and from then on nothing typed in the box was saved. Now an untouched box takes the draft, as it did before; a box the person wrote in offers it, and its next edit takes it in, the typed words after it, and saves both. A box is the person's once they type in it, not when it is focused.
In a thread with one agent the message's Reply arrow left focus on the arrow when the box was already open, so typed letters ran Inbox shortcuts. R focused a restored box with its caret before the words. Both now focus the box at once with the caret after the words, and a restored box's first focus by a key (Tab, Edit draft) lands there too. A thread opening still leaves focus where the person put it.
A save the Inbox refused or never answered kept the words only in the box: another thread and back showed the older draft, and a reload lost them. After an Inbox update a page left open had every draft save refused for its old session, so "Not saved" never cleared. Now the words are kept per thread, the box shows them when the thread opens again, the restart guard counts them, and they are saved again when the stream reconnects, the page is back online, the thread is opened again or a key is typed. The draft save route takes a page an earlier run of the same data folder served (it is a compare-and-set); every other write keeps its session guard.
A phone that backgrounds the tab or switches apps does not fire pagehide, and may end the page there: words typed inside the pause in typing were lost. The save that goes as the page goes now also goes when the page is hidden (keepalive), with words of the open thread whose save did not land, and is read back when the page shows again; words it did not land are saved again.
New message saved nothing until it was closed, so a reload, an update's
restart or a killed tab lost everything typed. It now saves to its own draft
after a pause in typing, and at once with keepalive as the page hides or goes;
the page's "Leave page?" asks only while words are not saved yet. Escape still
keeps the draft ("Draft saved"), a Send takes the draft a pause saved and no
save lands after it, and words emptied delete the draft the dialog made. The
skill picker's room moves to its own file to keep the dialog under its size.
A linked computer's thread keeps no draft on this Inbox yet, and the box emptied on a thread change: a reply typed there vanished with no warning when the person went to another thread. Until the draft is kept on the owning computer, the words are kept in the page per thread, come back in the box when the thread opens again, and the restart guard and "Leave page?" ask for them.
A save that does not land is now kept for its thread and shown again, so a save the pane made as a test ended, answered by the real fetch, came back in the next test's box.
…s that computer's
…ck; older words never land after newer; unsaved words are in the box before the read - reload: a read that is null or a different draft drops the offer and puts back the base this window knew before it. - the read-back after the page is shown skips its save when newer words of the box are queued or waiting. - a thread opened with words not saved here (a conflict's, a failed save's) shows them from the start, so a box opened before the read holds them. - DOM tests: each test starts on a fresh page state, and the afterEach fails when a save or unsaved words are left.
…when the save runs - The base is kept in a ref: the updated_at the dialog's last save landed (null once it deleted the draft it made), so typing again after emptying no longer gets a 409 that turned autosave off and showed "deleted in another window". - Each save's body is built when it runs, after the save before it answered: overlapping saves (a hide or Escape while a save is on its way) no longer refuse each other. Escape and Keep mine wait for that save first. - A refusal caused by the dialog's own save whose answer was lost is read back and saved on, never a conflict. - A keepalive's size is counted in bytes; a larger body goes as an ordinary request. - The compose DOM test's stand-in Inbox does the server's compare-and-set.
…im, not before The claim saves words whose save did not land. When that save landed, the Send now takes the draft as it is (its updated_at and files) and clears it, instead of sending the words alone and leaving the draft, with its files, behind.
…e; an offered draft merges an edit in its middle once - conflictWords, failedWords, remoteWords and Keep mine on its way are written to localStorage per thread (with the draft's updated_at), on every change of them, and removed where the page lets them go (a save or Keep mine landing, Discard mine, Send, Discard). A new page takes them back as the thread first opens; the read drops them when the draft holds them, saves failed words on an unchanged draft, or shows the conflict. Capped, quota errors ignored. - offeredWithTyped: a box that already holds the draft keeps its words; an edit in the middle of the words both went on from is made in the newer draft (no second copy of the text), and the caret stays where the person was typing. - Docs for the reply and compose guides.
… not saved, fails The afterEach wait in the reply-box DOM files gave up after a second without failing, so leftover state could carry into the next test unseen. The voice test for another machine's thread now discards its kept words. ComposeDialog.tsx shrank a line: its ceiling is lowered.
…esktop light and dark, a phone)
Into .local/proof/never-lose-words/: the dialog inside the pause, then as a Draft ("Draft · saved", Delete draft, the
sidebar's Drafts count) on a desktop, and "✓ Saved" on a phone.
…ore the real fetch is back Its Send test ends with the box's words waiting for the pause; the save sent as the pane unmounted went to the real fetch, did not land, and stayed as not saved. A new pane now compares those words with the draft this page last knew (gone), so the next test showed the conflict line instead of Reply.
…x-never-lose-typed-words
…y were typed over - A closed box's read no longer takes a newer draft in quietly while words wait unsaved: it is the conflict, and their retry sends the base they were typed over (and names only themselves as base_body), so it never lands over another device's draft. - The floating draft window shows words whose save did not land, as the thread's box does. - Words that did not land go only with a save that holds them or comes from the box that holds them. - Browser copy: one entry per page and thread; a page holds a Web Lock for its life and a new page takes back only a gone page's entry. 14 days, 20 entries and 200 KB at most, swept on load. An entry with no base waits for the person. Another computer's words come back once the thread is known as its. - The page hiding with a save on its way queues the newer words after it instead of a keepalive beside it. - New message: a Send after an autosave with no answer names the draft.
…a save on its way Only a hidden page (visibilitychange), which keeps running, queues the newer words after the save on its way; a page that goes has no after, so its words go as a keepalive as before.
…ithout Web Locks are never lost - The keepalive sent as the page hides or goes puts its words in the browser's keep first (cleared by a landed save or the read-back, as before), and names the last words SENT as base_body, not words queued behind a save on its way. A page that goes with words queued behind a save on its way sends those too. - Words taken back from a gone page are shown as soon as they are back; if the person typed in the box before they came back, the box takes them in first, the typed words after (failed and conflict words alike), and they are no longer marked as shown by a box that never showed them. - Without Web Locks (plain http on a LAN), a page keeping words keeps a heartbeat in localStorage (every 5 s and on visibilitychange, again after a back/forward-cache restore, removed as it goes for good); another page's words are taken back only once its heartbeat is gone or older than 30 s.
…ver older ones that did not land
…ved; proof and paste specs fixed - A desktop's Delete draft (there once a pause saved the draft) steps aside while a take runs, as the spacer and status do, so the level keeps its room (inbox-voice.spec.ts:1643). - A phone's top-bar Save draft stays, disabled, while dictated words are on their way, though a pause saved the draft (inbox-voice.spec.ts:1887). - The never-lose-words proof: desktop and phone are two tests; the phone opens New message from the Drafts page (an Inbox with no thread has none in its list header), clicks time out. - inbox-dictation-paste.spec.ts: the range test reloads its page first. Earlier tests saved the thread's draft from other pages, so this page's box offered it and the next edit took it in, as designed. The assertion is unchanged.
backnotprop
marked this pull request as ready for review
November 25, 2026 05:49
backnotprop
added a commit
that referenced
this pull request
Nov 25, 2026
… 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.
1 task
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.
The owner's rule for the Inbox: "The moment I start typing text, that's a draft." Words typed in the Inbox must never be lost. A hunt found six ways they were. Each fix below is its own commit, and each has a test that fails without it.
1. Typing was not saved while a saved draft was offered.
2. A reply typed in another linked computer's thread was lost on leaving the thread.
3. R and the Reply arrow left the caret at position 0.
4. A save that did not land was dropped.
5. New message kept its words only until the dialog closed.
6. A phone that hid the page could lose the reply's last words.
visibilitychange), and they are read back when the page is shown again.No person-facing words change: the existing lines and announcements are used again.
Tests:
packages/inbox/replyDraftNeverLost.test.tsxandpackages/inbox/composeAutosave.test.tsx.packages/server/inbox-reply-draft-session.test.ts.inbox-reply-late-draft-webkit.spec.tsnow covers two origins (127.0.0.1 and localhost, as an iPad and a Mac). Newinbox-compose-reload-keeps.spec.tscovers a reload inside New message's pause.Each case was also run before and after on a sandboxed Inbox with two origins and an update restart. Before, every case lost words; after, none did.
e2e: inbox-reply-late-draft-webkit.spec.ts inbox-compose-reload-keeps.spec.ts inbox-reply-drafts.spec.ts inbox-compose.spec.ts inbox-draft-after-send-webkit.spec.ts
Review fixes (an independent data-safety review found these from reading the code; each is reproduced in a DOM test against a stand-in server with the compare-and-set, failing before its fix):
dropOffer); a newer draft is offered in its place.updated_atthe dialog's last save landed (null after its delete), each body is built when the save runs, Escape and Keep mine wait for a save on its way, and a refusal after an unanswered save of its own is read back.replyWordsKept.ts), removed where the page lets them go; a new page takes them back once as the thread opens.post(New message).What a person sees differently from main: a reply box they typed in shows "A saved draft of this reply is waiting." when another device saves, and their next key takes it in; a focused box they did not type in takes another device's draft; New message shows "Draft · saved" and Delete draft (a phone: "✓ Saved"), its title "Draft", and a Drafts row and count, about 800 ms after a pause in typing. Whole-window shots:
inbox-compose-reload-keeps.spec.tswrites them to.local/proof/never-lose-words/.Third review (two silent-loss paths left, and the no-Web-Locks fallback). Each has a DOM test in
replyDraftNeverLost.test.tsxthat failed before its fix:base_body, so the Inbox refused it once the save on its way landed. Now the keepalive's words go in the browser's keep before it is sent (cleared by a landed save or the read-back, as before), itsbase_bodyis the last words sent, and a page that goes with words queued behind a save on its way sends those too.pagehidethat is not into that cache). Another page's words are taken back only once its heartbeat is gone or older than 30 s. happy-dom has no Web Locks, so the DOM tests run this path except those that install a stand-innavigator.locks.Known follow-ups (not in this PR):
offeredWithTypedcan join the same words twice in one edge case.