Repository navigation
Commit 8714a8e
authored
fix(mothership): keep a message the server never admitted instead of dropping it (#8674)
* fix(mothership): keep a message the server never admitted instead of dropping it
Two sends were lost without an error:
- A send whose POST got no response (offline, Wi-Fi drop, waking a laptop)
reconnected to the stream it would have opened. That stream does not exist,
so the 404 read as "finished", the turn finalized as a success, and the
refetched transcript no longer held the message. A queued follow-up was lost
the same way, since it had already left the queue.
- A send refused with 409 because another turn held the chat (started in
another tab, or one this surface lost track of) reconnected to that turn
under the new message's bubble, then vanished when it finished.
Both now hand the message back under its id. An unreachable send is held in
the queue, so it is not redispatched into the same failure, and goes out when
the browser is back online (or when the user sends it). A send that found the
chat busy waits in the queue behind that turn, which the chat shows as
running, and goes out when it ends. Reusing the id keeps a retry deduplicated
if the server did admit the first attempt.
* fix(mothership): keep held and busy-refused sends exactly once across remounts
- A first message held offline on the new-chat page sat under that mount's
queue key, which dies with the mount, so a reload or remount before the
network returned stranded it. Held sends on a chatless surface now carry the
surface they belong to, and the next chatless mount of that surface adopts
them.
- Held sends are released for every chat when the browser comes back online,
and on mount when it already is, so a send held in a chat the user is not
viewing (or one whose `online` event fired with no surface mounted) still
goes out.
- A send refused because the chat is busy is handed back only after the chat's
running turn has been read, so the queue cannot redispatch it before that
turn ends. A busy refusal that does not name the running turn no longer reads
as a deduplicated send, which reconnected to a stream that never existed and
lost the message.
* fix(mothership): send released held messages through the queue's own drain rules
Releasing held sends on mount kicked the queue dispatcher directly, which skips
the drain's guards. After a reload the chat history is not loaded yet, so a
follow-up queued behind a still-running turn went out at once and was refused as
busy. The release now only clears the hold; the drain effect, which waits for
the history and for the running turn to end, sends a released head, and now
also re-runs when the head's hold clears.
* fix(mothership): don't hold a send whose network returned while it was failing
An `online` event can fire while the failing POST is still pending, so the
release ran before the message was held and the message then waited for a
release that had already happened. A send now notes whether the browser came
back online while it was in flight, and if so goes back to the queue unheld,
for the drain to send under its usual rules.
* chore(mothership): name sign-out in desktop tool lease docs and say "not run" once
Follow-ups from the #8673 review: the lease docs now name sign-out
(`stopAllDesktopTools`) alongside the user's Stop as what cancels a desktop
tool, and the stale-observation message no longer says it was not run twice.
* fix(mothership): restore a withdrawn queued send even after the user switched chats
A queued send had already left the queue when its POST failed, and a dispatch
whose epoch changed meanwhile (the user switched chats) skipped restoring it,
so the message was lost. A withdrawn send was never admitted, so it now goes
back to its own chat's queue regardless of the epoch.
* fix(mothership): don't recreate a deleted chat's queue from a late restore
A withdrawn send restored after its dispatch outlived a chat switch could land
after the user deleted that chat, recreating a queue (and a message) for a
conversation that no longer exists. Clearing a chat's queue now leaves a
session tombstone that restores respect; a new enqueue for that key lifts it.1 parent 662bd70 commit 8714a8e
7 files changed
Lines changed: 592 additions & 42 deletions
File tree
- apps/sim
- app/workspace/[workspaceId]/home/hooks
- lib/mothership/tools/client
- stores/mothership-queue
Lines changed: 4 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
0 commit comments