René's URL Explorer Experiment


Title: fix(chat): deduplicate chat sends server-side instead of probing for them by waleedlatif1 · Pull Request #6536 · simstudioai/sim · GitHub

Open Graph Title: fix(chat): deduplicate chat sends server-side instead of probing for them by waleedlatif1 · Pull Request #6536 · simstudioai/sim

X Title: fix(chat): deduplicate chat sends server-side instead of probing for them by waleedlatif1 · Pull Request #6536 · simstudioai/sim

Description: Summary Follow-up to #6525, which fixed a real bug — a send withdrawn by an unmount cleanup was silently lost — but paid for it with a client-side probe. This replaces that probe with the deduplication mechanism the codebase already owns, and deletes more than it adds. The problem #6525 had to solve. A client cannot tell whether a request it aborted reached the server. lib/copilot/chat/post.ts never reads request.signal, so a request the server accepted still runs resolveOrCreateChat, persistUserMessage, and the billed turn to completion after the browser drops the socket (Next.js discussion). Retrying blind meant two chats and two billed runs; not retrying meant losing the message. How #6525 answered it. It polled the orphaned stream for up to 2.5s before deciding. That number was a guess with no production timing behind it, the poll had to distinguish "the server has no such stream" from "we stopped looking" (conflating them re-sent after teardown, opening an uncancellable POST), and it still left a window open for a server slower than the ceiling. How this answers it. IdempotencyService already backs webhook, polling, and billing deduplication here, and billingIdempotency exists for exactly this hazard — its own comment says a retry "would double-record usage — real money". Chat sends now claim through it, keyed on the client-generated userMessageId. Retrying is just reusing the id. Server chatSendIdempotency claims each send. The key is scoped to the authenticated user — userMessageId is client-supplied, so an unscoped key would let one user probe another's sends and read back their chat id Storage is forced to Postgres for the same reason as billingIdempotency: a missed dedup is a second billed turn, so the key must survive Redis memory pressure. ~1-5ms is invisible next to the LLM call that follows The chat is recorded against the claim as soon as it resolves — the earliest a retry can be answered with somewhere to go. From there the claim is permanent; before there, it is released so a failed send stays retryable A repeat gets 409 naming the chat, deliberately the shape the pending-stream lock already returns, so the client's existing conflict handler reattaches rather than starting a turn It fails open at every step. Deduplication saves a duplicate chat; the send is the user's message. An unreachable bookkeeping store must degrade chat, never take it down — an early draft failed closed and turned every send into a 409, which is exactly the outcome to avoid in production. Client Deleted with the probe: the poll and its two constants, the three-state result, the epoch plumbing that kept a superseded poll from re-sending, and the chat-adoption branch it required. The hook nets 67 lines smaller. Retry carries resumeUserMessageId through the same lanes #6525 built (live event, stored handoff, queue entry) — same plumbing, a payload that is consumed synchronously instead of awaited Idle sends go back to calling startSendMessage directly. #6525 routed them through the durable queue so recovery had a backing entry, which put every message in the product through the queue store, sessionStorage, and the dispatch loop for a rare path. Recovery never needed it — message, attachments, contexts, and id are all in scope at the abort. Both callers now share one handOffWithdrawnSend Removing the probe also removes a race it introduced: it awaited up to 2.5s between dispatchQueuedMessage's "re-read live" and the send, so an edit during that window sent pre-edit text startSendMessage takes its optional tail as an options object; it was at six positional parameters and the retry id would have been a seventh Testing Server: deduplicates a repeat without opening a second chat or stream, scopes the key per user, records the chat against the send, and still sends when the claim store is down. Client: reuses the original id on retry, and adopts the chat a deduplicated retry names. Plus the coverage #6525 earned — StrictMode double-mount, live-surface delivery, stored-handoff fallback, and the departing surface not claiming its own recovery event. Each new test was confirmed red without its fix. 2058 tests, type-check, biome, and check:api-validation pass. Known residuals All three are deliberate, and each is better than what main or staging does in the same scenario. Losing the claim store loses deduplication for that window — the fail-open trade above. The dedup window is 1 hour; userMessageId is never reused, so a longer one would be harmless. A concurrent retry can be told to reattach to a turn that never starts. A retry arriving between storeResult and the turn starting gets 409 and reattaches; if the original then also fails, there is nothing to attach to. The client keeps the optimistic pair (the generic 409 branch does not roll back) and finalizes with an error, so the user sees their message with a failed response rather than losing it — and the original's finally releases the claim, so sending again starts a fresh turn. main loses the message with no error; staging re-sends and can duplicate the turn. A failed storeResult degrades to no deduplication after 60s. The claim stays in-progress, which atomicallyClaimDb lets a retry reclaim once the lease expires, so a retry more than 60s later can start a second billed turn. Every alternative is worse: releasing on record failure duplicates immediately, and extending the lease to cover a turn (maxDuration is 3600s) lets a crashed pod poison the id for an hour. Leaving it in-progress still deduplicates for the first 60s, which is where recovery retries actually land — they fire from the unmount cleanup within milliseconds. Requires a Postgres write failure to reach, and logs Could not record the chat for this send when it happens. Claim lifecycle The load-bearing invariant, since it is easy to get wrong: the claim is permanent only once a turn is streaming. One line clears it, immediately before the stream response; finally releases it on every other exit. Exit Turn started Claim Duplicate (409) — not ours, untouched Claim store unavailable n/a never taken Rejected branch (400) no released Chat not found (404) no released Stream collision (409) no released Throw (500) no released Stream returned (200) yes kept, 1h Type of Change Bug fix Refactor 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 #6525, which fixed a real bug — a send withdrawn by an unmount cleanup was silently lost — but paid for it with a client-side probe. This replaces that probe with the deduplica...

X Description: Summary Follow-up to #6525, which fixed a real bug — a send withdrawn by an unmount cleanup was silently lost — but paid for it with a client-side probe. This replaces that probe with the deduplica...

Opengraph URL: https://github.com/simstudioai/sim/pull/6536

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,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-controllerpull_requests
route-actionfiles
fetch-noncev2:d7a18c87-3122-6053-b047-ddff35d54b25
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id83E4:15DF38:733F8E:9E1D1A:6AFB42C7
html-safe-nonceacb837bec89b5256c0a6f26373dd81d6588d444f1e9c3e189bb9d4f5486984d1
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4M0U0OjE1REYzODo3MzNGOEU6OUUxRDFBOjZBRkI0MkM3IiwidmlzaXRvcl9pZCI6Ijg0OTIzMzkwNjgzODAzMzI3NDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac3117ad1643be8070caaab8fb2bc37ac232fb8165fd260b4f8708910969bc6f3e
hovercard-subject-tagpull_request:4251265279
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/simstudioai/sim/pull/6536/files
twitter:imagehttps://avatars.githubusercontent.com/u/40672544?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/40672544?s=400&v=4
og:image:altSummary Follow-up to #6525, which fixed a real bug — a send withdrawn by an unmount cleanup was silently lost — but paid for it with a client-side probe. This replaces that probe with the deduplica...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noned849b928f455c800985398e7f1b659425adb312a5fa14fba5d9a14e62e9fe5dd
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/simstudioai/sim git https://github.com/simstudioai/sim.git
octolytics-dimension-user_id199344406
octolytics-dimension-user_loginsimstudioai
octolytics-dimension-repository_id912559512
octolytics-dimension-repository_nwosimstudioai/sim
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id912559512
octolytics-dimension-repository_network_root_nwosimstudioai/sim
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasea6c2f87cbcb6414452377b4967858ed6a66f1109
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/simstudioai/sim/pull/6536/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsimstudioai%2Fsim%2Fpull%2F6536%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsimstudioai%2Fsim%2Fpull%2F6536%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=simstudioai%2Fsim
Reloadhttps://github.com/simstudioai/sim/pull/6536/files
Reloadhttps://github.com/simstudioai/sim/pull/6536/files
Reloadhttps://github.com/simstudioai/sim/pull/6536/files
simstudioaihttps://github.com/simstudioai
simhttps://github.com/simstudioai/sim
Codehttps://github.com/simstudioai/sim
Issues129 (129)https://github.com/simstudioai/sim/issues
Pull requests200 (200)https://github.com/simstudioai/sim/pulls
Actionshttps://github.com/simstudioai/sim/actions
Projectshttps://github.com/simstudioai/sim/projects
Security and qualityhttps://github.com/simstudioai/sim/security
Insightshttps://github.com/simstudioai/sim/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fsimstudioai%2Fsim%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fsimstudioai%2Fsim%2Fissues%2Fnew%2Fchoose
waleedlatif1https://github.com/waleedlatif1
staginghttps://github.com/simstudioai/sim/tree/staging
fix/chat-send-idempotencyhttps://github.com/simstudioai/sim/tree/fix/chat-send-idempotency
Conversation 22 https://github.com/simstudioai/sim/pull/6536
Commits 4 https://github.com/simstudioai/sim/pull/6536/commits
Checks 31 https://github.com/simstudioai/sim/pull/6536/checks
Files changed https://github.com/simstudioai/sim/pull/6536/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6536/files
fix(chat): deduplicate chat sends server-side instead of probing for them https://github.com/simstudioai/sim/pull/6536/files#top
Show all changes 4 commits https://github.com/simstudioai/sim/pull/6536/files
ac7a732 fix(chat): deduplicate chat sends server-side instead of probing for … waleedlatif1 Aug 11, 2026 https://github.com/simstudioai/sim/pull/6536/commits/ac7a7322f8e6768e5cf01ee13e7cf112527eb1d9
98099a6 fix(chat): keep a withdrawn send in its own chat, and release strande… waleedlatif1 Aug 11, 2026 https://github.com/simstudioai/sim/pull/6536/commits/98099a6087584a9aa8b22024b3c0a883d461d39c
d7a16ab fix(chat): make a send's claim permanent only once its turn starts waleedlatif1 Aug 11, 2026 https://github.com/simstudioai/sim/pull/6536/commits/d7a16abb50052f0041048203b0f675db53a2e9d1
9ab60fa refactor(chat): give the send claim a single point of permanence waleedlatif1 Aug 11, 2026 https://github.com/simstudioai/sim/pull/6536/commits/9ab60facfec5c37667297d3f1c37ebceba022591
Clear filters https://github.com/simstudioai/sim/pull/6536/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6536/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6536/files
home.tsx https://github.com/simstudioai/sim/pull/6536/files#diff-eb66b9102ddc0010fd22549f03941b3c32eecdcef27b7ee4efc52a84e1c3ba83
use-chat.mount-send.test.tsx https://github.com/simstudioai/sim/pull/6536/files#diff-9f2c022a72a0c3ca7686691ebd743065a87c326e151587fb518ce594c4c9338a
use-chat.ts https://github.com/simstudioai/sim/pull/6536/files#diff-1a0584ccf9cc4bacd55ce19aeeea8d807c39f36c365fa5b6638587aad38c700d
panel.tsx https://github.com/simstudioai/sim/pull/6536/files#diff-a5104cb2e061f06aafd1ed7e52c94682826ac914de7755b827cfde111661b54b
post.test.ts https://github.com/simstudioai/sim/pull/6536/files#diff-0540c905a8ad71a1496dcdd48b1a21b0d7c4cd9f0760c49f1733e53ba17be369
post.ts https://github.com/simstudioai/sim/pull/6536/files#diff-60de90a5f54e09f0885aef9b2ced6b38c99d9cee23fd9ca290313eca4923b729
service.ts https://github.com/simstudioai/sim/pull/6536/files#diff-6622bed9a9e8ea71519df9b69f50201260f8b7aa4742fe7973f87212b37dc024
browser-storage.ts https://github.com/simstudioai/sim/pull/6536/files#diff-32aeb777aa84abec058370c350ef61e17af04b4ad37244ce193e02cf076e0e6a
events.ts https://github.com/simstudioai/sim/pull/6536/files#diff-f7e608162b8307f9c529fbf1e388eb601f07dd6ab95beeca71933fd3fcc7670d
store.ts https://github.com/simstudioai/sim/pull/6536/files#diff-f9609bb09028d5fea616b8fbeca370d62c6a6d20f6dc460fed34a8a0594dce70
types.ts https://github.com/simstudioai/sim/pull/6536/files#diff-66995a79415f1ef4665bc2e86e1d1a9d3b0d0babf5f62114dc92f09880c1d1ae
apps/sim/app/workspace/[workspaceId]/home/home.tsxhttps://github.com/simstudioai/sim/pull/6536/files#diff-eb66b9102ddc0010fd22549f03941b3c32eecdcef27b7ee4efc52a84e1c3ba83
View file https://github.com/simstudioai/sim/blob/9ab60facfec5c37667297d3f1c37ebceba022591/apps/sim/app/workspace/%5BworkspaceId%5D/home/home.tsx
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/simstudioai/sim/pull/6536/{{ revealButtonHref }}
https://github.com/simstudioai/sim/pull/6536/files#diff-eb66b9102ddc0010fd22549f03941b3c32eecdcef27b7ee4efc52a84e1c3ba83
https://github.com/simstudioai/sim/pull/6536/files#diff-eb66b9102ddc0010fd22549f03941b3c32eecdcef27b7ee4efc52a84e1c3ba83
https://github.com/simstudioai/sim/pull/6536/files#diff-eb66b9102ddc0010fd22549f03941b3c32eecdcef27b7ee4efc52a84e1c3ba83
https://github.com/simstudioai/sim/pull/6536/files#diff-eb66b9102ddc0010fd22549f03941b3c32eecdcef27b7ee4efc52a84e1c3ba83
apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.mount-send.test.tsxhttps://github.com/simstudioai/sim/pull/6536/files#diff-9f2c022a72a0c3ca7686691ebd743065a87c326e151587fb518ce594c4c9338a
View file https://github.com/simstudioai/sim/blob/9ab60facfec5c37667297d3f1c37ebceba022591/apps/sim/app/workspace/%5BworkspaceId%5D/home/hooks/use-chat.mount-send.test.tsx
Open in desktop https://desktop.github.com
Please reload this pagehttps://github.com/simstudioai/sim/pull/6536/files
apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.tshttps://github.com/simstudioai/sim/pull/6536/files#diff-1a0584ccf9cc4bacd55ce19aeeea8d807c39f36c365fa5b6638587aad38c700d
View file https://github.com/simstudioai/sim/blob/9ab60facfec5c37667297d3f1c37ebceba022591/apps/sim/app/workspace/%5BworkspaceId%5D/home/hooks/use-chat.ts
Open in desktop https://desktop.github.com
Please reload this pagehttps://github.com/simstudioai/sim/pull/6536/files
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsxhttps://github.com/simstudioai/sim/pull/6536/files#diff-a5104cb2e061f06aafd1ed7e52c94682826ac914de7755b827cfde111661b54b
View file https://github.com/simstudioai/sim/blob/9ab60facfec5c37667297d3f1c37ebceba022591/apps/sim/app/workspace/%5BworkspaceId%5D/w/%5BworkflowId%5D/components/panel/panel.tsx
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/simstudioai/sim/pull/6536/{{ revealButtonHref }}
https://github.com/simstudioai/sim/pull/6536/files#diff-a5104cb2e061f06aafd1ed7e52c94682826ac914de7755b827cfde111661b54b
https://github.com/simstudioai/sim/pull/6536/files#diff-a5104cb2e061f06aafd1ed7e52c94682826ac914de7755b827cfde111661b54b
apps/sim/lib/copilot/chat/post.test.tshttps://github.com/simstudioai/sim/pull/6536/files#diff-0540c905a8ad71a1496dcdd48b1a21b0d7c4cd9f0760c49f1733e53ba17be369
View file https://github.com/simstudioai/sim/blob/9ab60facfec5c37667297d3f1c37ebceba022591/apps/sim/lib/copilot/chat/post.test.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/simstudioai/sim/pull/6536/{{ revealButtonHref }}
https://github.com/simstudioai/sim/pull/6536/files#diff-0540c905a8ad71a1496dcdd48b1a21b0d7c4cd9f0760c49f1733e53ba17be369
https://github.com/simstudioai/sim/pull/6536/files#diff-0540c905a8ad71a1496dcdd48b1a21b0d7c4cd9f0760c49f1733e53ba17be369
https://github.com/simstudioai/sim/pull/6536/files#diff-0540c905a8ad71a1496dcdd48b1a21b0d7c4cd9f0760c49f1733e53ba17be369
https://github.com/simstudioai/sim/pull/6536/files#diff-0540c905a8ad71a1496dcdd48b1a21b0d7c4cd9f0760c49f1733e53ba17be369
https://github.com/simstudioai/sim/pull/6536/files#diff-0540c905a8ad71a1496dcdd48b1a21b0d7c4cd9f0760c49f1733e53ba17be369
https://github.com/simstudioai/sim/pull/6536/files#diff-0540c905a8ad71a1496dcdd48b1a21b0d7c4cd9f0760c49f1733e53ba17be369
https://github.com/simstudioai/sim/pull/6536/files#diff-0540c905a8ad71a1496dcdd48b1a21b0d7c4cd9f0760c49f1733e53ba17be369
https://github.com/simstudioai/sim/pull/6536/files#diff-0540c905a8ad71a1496dcdd48b1a21b0d7c4cd9f0760c49f1733e53ba17be369
Please reload this pagehttps://github.com/simstudioai/sim/pull/6536/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6536/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.