Skip to content

Clear retired socket snapshots before replay - #24

Merged
fdussert merged 3 commits into
fdussert:mainfrom
FlorianBruniaux:codex/socket-cache-invalidation
Oct 15, 2026
Merged

fdussert merged 3 commits into
fdussert:mainfrom
FlorianBruniaux:codex/socket-cache-invalidation

Conversation

@FlorianBruniaux

@FlorianBruniaux FlorianBruniaux commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

A newly opened widget could replay an old channel snapshot after the provider retired it. For example, deleting an account while a tile stayed subscribed left the previous account data in the browser's replay cache; a second tile could receive that stale snapshot. A disconnect could also miss the retirement event.

Clear only the host replay cache on a channel invalidate message and on WebSocket close. Existing widgets receive no synthetic payload; fresh provider data still flows to their subscriptions. This extracts the independent socket.ts fix from the held account-services PR #20.

Validation on current main: pnpm typecheck, pnpm test (1,371 server and 387 UI tests), and pnpm build. The two new UI tests cover invalidation while subscribed and a disconnect before a later subscriber.

@FlorianBruniaux
FlorianBruniaux force-pushed the codex/socket-cache-invalidation branch from c77ed76 to 3234c93 Compare October 15, 2026 15:56
@fdussert

Copy link
Copy Markdown
Owner

Thanks Florian, and thanks for splitting this out of #20 as suggested. The client side is exactly right: invalidate drops only that channel's replay cache, close clears everything, and live subscribers get neither a synthetic payload nor a re-subscribe.

One gap: on main nothing sends invalidate yet — Hub.forget() (server/src/ws/hub.ts) only clears the server's own cache, and the only sender is in #20. So that branch is dormant for now. Could forget() also send { type: 'invalidate', channel } to the sockets subscribed to that channel, with a hub test? The registry already calls forget() when a provider is stopped or replaced, so this PR becomes useful on its own. The last.clear() on close already helps today.

@fdussert fdussert left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Florian, forget() now invalidates only the live subscribers, the message matches what the client expects, and the reordered close keeps it off closing sockets. It also pairs nicely with #25: unticking the e-mail setting no longer lets a newly opened tile replay the old address. Tests are green on top of main. Approving and merging.

@fdussert

Copy link
Copy Markdown
Owner

Approved — sorry Florian, #12 and #14 landed a minute before this one and CHANGELOG.md now conflicts again. One more rebase on main and I'll merge it straight away.

FlorianBruniaux and others added 3 commits October 15, 2026 19:59
A provider can retire a channel while widgets remain subscribed, and reconnects can miss invalidations. Clear only the host replay cache so new tiles wait for fresh data.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
@fdussert
fdussert force-pushed the codex/socket-cache-invalidation branch from a671470 to f750c34 Compare October 15, 2026 17:59
@fdussert

Copy link
Copy Markdown
Owner

I rebased this on main myself to get it into 0.3.0: conflicts only, both sides kept, no change to your code, and you stay the author of every commit. If you push to this branch again, please git pull --rebase first. Thanks! Merging now.

@fdussert
fdussert merged commit 09d3b7c into fdussert:main Oct 15, 2026
1 check passed
@fdussert fdussert mentioned this pull request Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants