Skip to content

fix(web): stop replays from duplicating the transcript on reconnect - #94

Merged
shadaj merged 1 commit into
mainfrom
sandbox-fd248ca1-ee54-4173-83ff-9564bd4cef9f
Aug 10, 2026
Merged

fix(web): stop replays from duplicating the transcript on reconnect#94
shadaj merged 1 commit into
mainfrom
sandbox-fd248ca1-ee54-4173-83ff-9564bd4cef9f

Conversation

@shadaj

@shadaj shadaj commented Aug 6, 2026

Copy link
Copy Markdown
Member
  • infinity-web/src/App.tsx: a Replay always carries the complete
    transcript for the connected thread, so the handler now clears the
    message state (bumping the generation to invalidate MessageList's
    prefix cache), pending choices, and streaming flag before processing
    the replayed history. Previously the WS-reconnect path (Welcome
    re-Connect) never reset the transcript — unlike navigateTo /
    MigrateComplete — so each reconnect appended a full extra copy of
    the history to the messages array and DOM, making the page
    progressively laggier with every disconnect/reconnect cycle. The
    input draft is deliberately preserved (unlike resetMessages).

  • crates/infinity-daemon/src/session/thread_worker.rs:
    handle_subscribe now replaces an existing subscription on the same
    channel (same_channel) instead of pushing a duplicate. The web
    client re-sends Connect every 5s until Connected arrives; when a
    resume was slow, each retry stacked another subscriber for the same
    client, causing every display event (and another full Replay) to be
    delivered N times from then on.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 6, 2026

Copy link
Copy Markdown

Deploying infinity with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2273092
Status: ✅  Deploy successful!
Preview URL: https://057a9060.infinity-dc7.pages.dev
Branch Preview URL: https://sandbox-fd248ca1-ee54-4173-8.infinity-dc7.pages.dev

View logs

@shadaj
shadaj marked this pull request as ready for review August 8, 2026 00:10
@shadaj
shadaj requested a review from a team August 8, 2026 00:10
* `infinity-web/src/App.tsx`: a `Replay` always carries the complete
  transcript for the connected thread, so the handler now clears the
  message state (bumping the generation to invalidate MessageList's
  prefix cache), pending choices, and streaming flag before processing
  the replayed history. Previously the WS-reconnect path (`Welcome` →
  re-`Connect`) never reset the transcript — unlike `navigateTo` /
  `MigrateComplete` — so each reconnect appended a full extra copy of
  the history to the messages array and DOM, making the page
  progressively laggier with every disconnect/reconnect cycle. The
  input draft is deliberately preserved (unlike `resetMessages`).

* `crates/infinity-daemon/src/session/thread_worker.rs`:
  `handle_subscribe` now replaces an existing subscription on the same
  channel (`same_channel`) instead of pushing a duplicate. The web
  client re-sends `Connect` every 5s until `Connected` arrives; when a
  resume was slow, each retry stacked another subscriber for the same
  client, causing every display event (and another full `Replay`) to be
  delivered N times from then on.

Co-authored-by: Infinity 🤖 <infinity@hydro.run>
PR: #94
@shadaj
shadaj force-pushed the sandbox-fd248ca1-ee54-4173-83ff-9564bd4cef9f branch from ad2e37a to 2273092 Compare August 10, 2026 17:49
Comment on lines +422 to +426
subs.retain(|sub| !sub.tx.same_channel(&tx));
subs.push(Subscriber {
tx,
keeps_session_alive,
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would sub.tx.same_channel actually be true in the re-connect case?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not if it's a reconnect on a new TCP channel, but yes if the client just sends a second Connect to the same thread ID.

@shadaj
shadaj merged commit d054196 into main Aug 10, 2026
11 of 13 checks passed
@shadaj
shadaj deleted the sandbox-fd248ca1-ee54-4173-83ff-9564bd4cef9f branch August 10, 2026 20:07
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