fix(sessions): dedupe started session when created broadcast races

The session.created global event (added with spawn_session) could arrive
in the initiating tab before the start request's HTTP response resolved.
applyCreatedSession inserted a plain session row (archive/reload actions)
and then startSession unconditionally prepended the cached version (delete
action), leaving two badges with the same id.

Make the optimistic insert idempotent by filtering out any existing entry
with the same id before prepending the cached session, so the locally
cached session always wins regardless of event ordering.
This commit is contained in:
Federico Jaramillo Martinez
2026-06-16 23:40:47 +02:00
parent 1c6bc96110
commit dd23b3e054
3 changed files with 39 additions and 1 deletions
@@ -0,0 +1,5 @@
---
"@jmfederico/pi-web": patch
---
Fix a duplicate session appearing in the list when starting a new session. The `session.created` broadcast (added with the spawn_session tool) could race ahead of the start request's HTTP response in the same tab, leaving two badges with the same id — one with archive/reload actions and one with delete. The optimistic insert now replaces any entry the broadcast added, so the locally cached session (with its delete action and draft support) always wins.