Skip to content

Inbox: a Send always ends when its connection dies without a word - #4158

Merged
backnotprop merged 4 commits into
mainfrom
fix/inbox-send-always-ends
Nov 28, 2026
Merged

backnotprop merged 4 commits into
mainfrom
fix/inbox-send-always-ends

Conversation

@backnotprop

@backnotprop backnotprop commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

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 reply may not have gone. Send again: it looks for this one first, so it is not sent twice." The write was given up with nothing arriving, or the Inbox cannot be read. A request given up may still be on its way (a slow Inbox, a phone's connection sending it again after a network change), so a timeout never says "was not sent". The words stay in the box and its draft, and Send works again.
  • "The reply was not sent. Send again to retry." (or the Inbox's own refusal) The Inbox definitely did not take the reply: a refusal (4xx), or a 5xx or a refused connection that the read back does not find.
  • The Send just finishes. The reply had arrived and only its answer was lost.

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 (late in data/actions/sendLanded.ts), so the existing watch runs. When a read of the thread shows the reply:

  • the box still holds exactly the words sent: "Your reply went.", the line goes, the box empties and its draft is cleared;
  • the person edited the words since: the edit stays in the box as the draft, and the line is the existing "Your earlier reply went; Send sends your edited words as another reply." (while it is not known yet: "Your earlier reply may have gone; …"). A Send then sends the edit as one new reply. I chose this because the edit is the person's newest work: clearing it would lose words, and the line says what Send will do.

Send again with the same words first looks for the earlier reply, then reuses its key. A late record 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 not late (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:

  • the reply route (InboxStore.sendReply)
  • New message in a thread (sendNewMessage)
  • compose (startPersonThread)

The server already behaved this way. packages/shared/inbox/store-send-retry.test.ts now 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.ts adds fetchWithin, which writes opt into with post(…, WITHIN):

  • What counts: time with nothing arriving, the same way reads are bounded (getWithin). Every byte of the answer starts the 20 s again, so a slow answer that keeps coming is never cut off.
  • Why 20 s: a forward to a linked machine waits 4 s and then holds the write; copying a reply's files takes time. 20 s covers both with room to spare and gives Send back while the person still cares. It matches the longest read limits already in the window.
  • The request body: fetch cannot see its own request body leave, so the wait also covers sending it. Write bodies are small (words and ids). Files are uploaded before the Send, with their own progress, and this change does not touch them.

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).

Test Previous head This branch
packages/inbox/apiWrite.test.ts the launch reply test fails 8 of 8 pass
packages/inbox/sendFailure.test.ts the timeout line test fails 9 of 9 pass
packages/inbox/sendAlwaysEnds.test.tsx (DOM) 7 of 16 fail 16 of 16 pass
packages/shared/inbox/store-send-retry.test.ts 3 of 3 pass (existing server behavior) 3 of 3 pass

sendAlwaysEnds.test.tsx covers:

  • a reply POST that never answers: "may not have gone", the words kept
  • a reply that landed but whose answer was lost and whose read back fails
  • a reply that landed late: Send again finds it and posts nothing; Send again before it lands carries the same key
  • a late reply noticed by a read of the thread: "Your reply went.", the line gone, the box and the draft empty, one reply
  • edited words after a timeout: the edit stays, the earlier reply is said to have gone, Send sends the edit once
  • leaving the thread and coming back: Send again carries the first key; a reply that lands while away is said to have gone on return
  • a 4xx and a refused connection: "was not sent", and nothing watches for that reply
  • a hung draft save; the conflict retry, on a good network and when it hangs; a good network; New message keys

Other checks:

  • These existing tests still pass: sendLanded, replyFootPhone, actionDraftSend, replyDraftNeverLost, paneFailureKeepsReply, inbox-structure, dom-test-allowlist, ci-e2e-shard.
  • tsc passes for packages/inbox.
  • The api.ts and Thread.tsx size ceilings are unchanged (both at their ceilings, not over).
  • The new e2e spec now has its time in 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

  • Real phones, real flaky networks and real proxies.
  • Safari / WebKit by hand. The new e2e spec runs WebKit in CI.
  • A linked machine's forwarded writes, and a real launch's preparation time.

Still open

  • A late draft save (known, not handled): a draft save with no base that lands after the Send cleared the draft could bring back a draft of the sent words. Rare.
  • A connection reset mid-request (a fetch error, not a timeout) while the Inbox is still writing the reply would still say "was not sent" if the read back comes first. Fetch cannot tell this from a refused connection.
  • Uploads use XHR with no limit. A silently dropped upload leaves its tile uploading, and Send refuses with "Wait for the files to finish uploading." That is a refusal, not a dim button. An inactivity limit there would need the upload's failure state checked.
  • Unbounded steps before or after a Send:
    • Take back.
    • A comment's file text read (inboxApi.view), only for comments on text files.
    • The list read and the attachments read that run after a reply has already gone. On this computer's own Inbox the reply's answer brings the thread, so the list read is skipped.

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.

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.
@backnotprop backnotprop added the ci:e2e Run the full browser suite (Inbox window e2e) on this PR label Nov 28, 2026
…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.
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