Title: fix(mothership): close the remaining ways a chat send is lost, resent hot, or polled after unmount by waleedlatif1 · Pull Request #8695 · simstudioai/sim · GitHub
Open Graph Title: fix(mothership): close the remaining ways a chat send is lost, resent hot, or polled after unmount by waleedlatif1 · Pull Request #8695 · simstudioai/sim
X Title: fix(mothership): close the remaining ways a chat send is lost, resent hot, or polled after unmount by waleedlatif1 · Pull Request #8695 · simstudioai/sim
Description: Summary Follow-up to #8674, #8675 and #8676. It closes seven gaps in how a chat send survives deletes, busy refusals, returns, chat switches and unmounts. A deleted chat's queue no longer comes back. A direct send to a chat that was deleted while its POST was failing (unreachable or busy) was re-queued under the deleted chat. The message was invisible there and would go out by itself if the chat were restored. Only insertAt was guarded. The queue store now refuses every write to a cleared chat, including migrate from a new-chat surface that resolves to it. A delete seen through another tab's deleted event clears and blocks the chat there too. A restore lifts the block: reopenChat on Recently Deleted, the created event a restore publishes, or any server read of the chat (history load or recovery on return) that began after the delete. History written locally (such as the rollback after a refused send) does not count. Each delete carries a token, and a read or restore lifts only the delete it saw when it began, never one that landed while it was in flight. Busy refusals are retried with backoff. With Redis down, acquirePendingChatStream fails closed, so every send is refused with a 409 that names no turn. The re-queued message was then resent on each refusal, or stalled in the queue. A busy re-queue now records busyRetries / notBefore. The drain waits a jittered, growing delay (backoffWithJitter, 1s to 30s) before sending it again under the same id. On the new-chat surface, a busy first message stays in its own pending queue instead of being handed straight back to the surface's send listener. The server creates the chat before it takes the lock, so a refused first send can still leave an empty chat. That predates this PR; the backoff bounds how often it happens. Returning to the tab no longer aborts a send waiting on the chat lock. The server can hold a send up to 5s behind another tab's turn. A return-triggered recovery aborted that POST, and the message was lost. Recovery now leaves any POST that hasn't answered alone, unless the chat already holds its message. When the busy refusal then arrives, the chat attaches to the turn that holds it explicitly, through recovery's own history read. The history read it relied on could repeat one the surface skipped while the POST was pending, so the tab never showed that turn and the queued message waited behind it unseen. A send waiting on the chat lock is kept when the user switches chats. A chat switch detaches the view but leaves the POST running. Its busy refusal was dropped as a stale answer before the conflict handling ran, so the message was lost. This predates the earlier PRs. A conflict is now handled after a switch too, and the message is re-queued in its own chat. "Already sent" with no stream is retried, not dropped. A retry can be deduplicated against an earlier attempt that is still in flight and hasn't opened a stream yet. The client reattached, read the 404 as a finished turn, and dropped the message. It is now retried later, like a busy refusal, as is one whose stream lookup failed for another reason (network, 5xx); the server deduplicates the retry by id. On the new-chat surface it stays under the key it was sent from: the stream is checked before the chat the answer names is adopted. The browser harness found this when Redis came back during a busy-refusal retry. If the user moved to another chat and started a turn while that check was pending, the old send no longer takes over the turn Stop acts on. A Send-now message is kept when the user switches chats during its Stop. If the Stop handoff failed ("Queued message was restored because the selected chat changed"), the send returned a plain failure, and the dispatch epoch check discarded it. It is now handed back held, so it stays in its own chat's queue. A surface that unmounted still resumes it from its stored handoff, as before. The saved-turn re-read stops with the chat view. It kept refetching an unobserved chat for up to 2 minutes after unmount. Type of Change Bug fix Testing DOM regressions in use-chat.dom.test.tsx. Each one fails on staging and passes here: does not recreate a deleted chat through a unreachable direct send does not recreate a deleted chat through a busy direct send backs off retrying a send the server keeps refusing as busy without a turn keeps a send waiting on the chat lock when the user returns to the tab (also asserts the attach to the holding turn) retries a send deduplicated against an attempt that opened no stream keeps a send-now message in its chat when the user switches chats during the Stop stops re-reading the saved turn when the chat view unmounts backs off a busy refusal of a first message on the new-chat surface keeps Stop on the new turn when a deduplicated send is checked after a chat switch queues a follow-up in a chat that loads after this tab saw it deleted keeps a chat deleted in another tab empty when a pending send there is refused as busy queues a follow-up after a return to the tab finds a chat this tab saw deleted keeps a direct send refused as busy after the user switched chats keeps a queued send refused as busy after the user switched chats retries a first message deduplicated against an attempt that opened no stream retries a deduplicated send whose stream lookup failed Store and event-handler regressions. Each one fails before its fix and passes here: does not move a new chat surface queue into a chat deleted meanwhile (store.test.ts) drops the queue of a chat deleted elsewhere and takes sends again once it is restored (use-mothership-chat-events.test.ts) mothership-chat-history-restore.test.ts: a server read or a restore after a delete reopens the chat. A read already in flight when the delete landed, or a read or restore overtaken by a newer delete, does not. lifts only the delete a restore saw, never a later one (store.test.ts) Browser E2E on a local Sim + worker stack with a scripted model: A send from a second tab while another tab's turn holds the chat, both with and without returning to the tab mid-wait: the message goes out once after the turn ends. Sim's Redis stopped for 75s, for a follow-up and for a first message from the new-chat surface: 5 paced attempts each (gaps of 8-18s), then the message is sent once Redis is back. Offline send, offline after a return, queue then reload, two tabs, and follow-ups under 7-way load all pass, with no console errors. Gate: the full gate plus integration tests ran on the CI runner. Checklist Code follows project style guidelines Self-reviewed my changes Tests added/updated and passing No new warnings introduced I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)
Open Graph Description: Summary Follow-up to #8674, #8675 and #8676. It closes seven gaps in how a chat send survives deletes, busy refusals, returns, chat switches and unmounts. A deleted chat's queue no longer come...
X Description: Summary Follow-up to #8674, #8675 and #8676. It closes seven gaps in how a chat send survives deletes, busy refusals, returns, chat switches and unmounts. A deleted chat's queue no longer ...
Opengraph URL: https://github.com/simstudioai/sim/pull/8695
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:6b099b0f-28b7-fe60-d7fa-15ec6d4aae6d |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9ECE:345450:BA63BB:10124D3:6AFB56EA |
| html-safe-nonce | c18c302aece59ae909366622435865c709526f1f3eabe839173acb6803a3ff1f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RUNFOjM0NTQ1MDpCQTYzQkI6MTAxMjREMzo2QUZCNTZFQSIsInZpc2l0b3JfaWQiOiI3NTg3ODU4ODg2MTUzNjg4ODEwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b94741e9166d1a2cc506f78dc5319aa03641e26a5f020c164025a12584c1c125 |
| hovercard-subject-tag | pull_request:4764722761 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/simstudioai/sim/pull/8695/files |
| twitter:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| og:image:alt | Summary Follow-up to #8674, #8675 and #8676. It closes seven gaps in how a chat send survives deletes, busy refusals, returns, chat switches and unmounts. A deleted chat's queue no longer come... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7122bb414b542dba14d71a3f0b9f6fd2abce715b9f5912d082800563e6c806d1 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/simstudioai/sim git https://github.com/simstudioai/sim.git |
| octolytics-dimension-user_id | 199344406 |
| octolytics-dimension-user_login | simstudioai |
| octolytics-dimension-repository_id | 912559512 |
| octolytics-dimension-repository_nwo | simstudioai/sim |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 912559512 |
| octolytics-dimension-repository_network_root_nwo | simstudioai/sim |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cbf66c024bb6d10e6955baa7413c54cf13a201bb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width