Repository navigation
Inbox: a Send always ends when its connection dies without a word - #4158
Merged
Merged
Conversation
A write the person waits on (the reply, Re-ask, New message, compose's Send to a live session, the reply draft's save and Discard, picks, action marks, comments) had no time limit, so a connection that died silently held Send dim for good. These writes now give up after 20 s with nothing arriving (every byte of the answer restarts the wait, so a slow answer is not cut off) and fail the way any unanswered write fails: the reply is looked for by its key, the words stay in the box, and Send again carries the same key, which the Inbox answers with the reply it already wrote. The small reads inside a Send get a 10 s limit. New message takes a new key when the words were edited after a failure, so a replay never swallows them.
…x-send-always-ends
…s a session has no limit A reply to the box's "New ... session" row waits for the Inbox to prepare the launch, as compose's start already did (withinUnlessLaunch). A write given up with no answer may still land, so its line is the existing "may not have gone" one, and when the read back does not find it yet the Send stays unconfirmed (late): a later thread read that shows the reply says it went and empties the box and its draft while the box holds the words sent; edited words stay. The record and the Send's keys outlive leaving the thread, so Send again of the same words is that reply, never a second. Also adds the new e2e spec's time to tests/e2e/shard-times.json.
…x-send-always-ends
backnotprop
marked this pull request as ready for review
November 28, 2026 04:10
This was referenced Nov 28, 2026
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.
What could happen
On 1 Nov the owner pressed Send on a phone. The button dimmed and never finished until they refreshed the page. The cause is still on main: a write had no time limit. If a connection dies without a word (a phone changing networks, a laptop waking, a proxy dropping the answer), the window gets no answer and no error, and Send waits forever. The box also looks empty while the words show as "Sending…" in the thread.
This is reproduced on main by a test (
packages/inbox/sendAlwaysEnds.test.tsx) and by hand against a compiled binary. Forty-five seconds after Send, the reply still says "Sending…" and Send is still a dim spinner.A hung save of the reply draft does the same thing. Send saves the box's words first and waits for that save, so one silent draft save holds Send forever too.
What a person sees now
The Send ends in a state that already exists. There are no new words. With a clean hang that is about 30 s after the press: the 20 s limit, then a read back of the thread of up to 10 s. When the draft save is stuck too, it can take about a minute: the save's 20 s, the draft read's 10 s, then the reply's 20 s and the read back's 10 s.
The window learns which of these happened by reading the thread back for the reply's key. Main already did this for a request that failed outright. It now also happens for one that never answers.
A reply that arrives after the window gave up (review finding M2). A timeout whose read back does not find the reply is kept as unconfirmed (
lateindata/actions/sendLanded.ts), so the existing watch runs. When a read of the thread shows the reply:Send again with the same words first looks for the earlier reply, then reuses its key. A
laterecord outlives leaving the thread, and keeps that Send's keys; the pane takes them back when the thread opens again (Thread.tsx, the thread-change reset). So a reply that lands after the person left and came back is still one reply. This is the smallest change: the keys ride the record that already exists. A record that is notlate(the Inbox could not be read) is still forgotten on leaving, as on main.New message (in a thread) and compose show their existing line: "The message was not sent. Send again to retry." Decision mode's answer Send has no read back (unchanged).
How double-sending is prevented
There are no automatic retries. Pressing Send again is the retry, and it carries the same idempotency key, because the window keeps the key while the words stay the same (now also across leaving the thread after a timeout). The Inbox answers a key it has already seen with the reply it wrote and writes nothing new. This is true for:
InboxStore.sendReply)sendNewMessage)startPersonThread)The server already behaved this way.
packages/shared/inbox/store-send-retry.test.tsnow guards it: each kind is sent twice under one key, the second time after the store reopens from disk and after the agent writes again, and only one message results.New message used one key for the whole life of its box. If the words were edited after a failure, a replay of the first request could swallow the edited words. It now takes a new key when the words change, as compose and the reply already do.
The limit
packages/inbox/apiWrite.tsaddsfetchWithin, which writes opt into withpost(…, WITHIN):getWithin). Every byte of the answer starts the 20 s again, so a slow answer that keeps coming is never cut off.Bounded writes: the reply, Re-ask, New message, compose's Send to a live session, the reply draft's save and Discard, picks, action marks, and comments.
A write that starts a session has no limit (review finding M1): compose's start, and now also a reply to the reply box's "New … session" row (
to: { launch }), here or on a linked computer (withinUnlessLaunch). The Inbox checks and prepares the launch before it answers (the agent's version and sign-in checks, the login shell, git): up to about 25 s before the first byte. Re-ask and New message cannot address a start row (they only name live sessions), so they keep the limit.Bounded reads inside a Send, at 10 s: the draft, the thread read in the revision-conflict retry (#4109), the skills catalog and a skill's text, and Decision mode's thread check.
Every other POST stays unbounded on purpose: update, restart, linking.
The #4109 conflict retry still goes with the same key. A conflict retry that never answers now ends as well.
Tested
All of these use fake networks and no real Inbox. "Previous head" is this PR before the review fixes (bf7539e).
packages/inbox/apiWrite.test.tspackages/inbox/sendFailure.test.tspackages/inbox/sendAlwaysEnds.test.tsx(DOM)packages/shared/inbox/store-send-retry.test.tssendAlwaysEnds.test.tsxcovers:Other checks:
tscpasses for packages/inbox.tests/e2e/shard-times.json(unit-3 failed without it). Its first case now expects the "may not have gone" line.New e2e spec
tests/e2e/inbox-send-always-ends-webkit.spec.ts: WebKit, iPhone 15, compiled binary, with the real 20 s limit. It covers a held reply, then Send again giving one reply, and a reply that reaches the Inbox but loses its answer. CI runs it; I did not run it locally.By hand (first round), in a sandboxed Inbox with the reply's request held by Playwright (Chromium, 390×844 and 1440×900), main stayed dim at 45 s. This branch showed the failure line at 20.4 s with the words kept, and Send again wrote exactly one reply. The review fixes were not driven by hand.
Not tested
Still open
inboxApi.view), only for comments on text files.Replaces #2459. That branch is four weeks behind; this is a fresh port of only the time limit, built on main's existing read back by key.