Skip to content

fix(terminal): drop stale terminal_output chunks after a reconnect race - #437

Open
RonenMars wants to merge 1 commit into
fix/diff-viewer-full-width-lines-integrationfrom
fix/terminal-seq-guard
Open

fix(terminal): drop stale terminal_output chunks after a reconnect race#437
RonenMars wants to merge 1 commit into
fix/diff-viewer-full-width-lines-integrationfrom
fix/terminal-seq-guard

Conversation

@RonenMars

Copy link
Copy Markdown
Owner

Summary

Investigated a Terminal-tab bug where displayed conversation lines appeared shuffled.
useTerminalStream.ts trusts raw WebSocket arrival order to feed its client-side VT100 emulator (virtual-terminal.ts) — normally reliable, but a reconnect can leave a stale terminal_output frame from the superseded connection in flight, and it can land after the client has already reset state for a fresh terminal_replay, landing content out of order.

The companion streamer PR (threadbase-streamer#299) adds a per-session monotonic seq to terminal_output/terminal_replay. This PR consumes it here: a lastSeqRef guard drops any terminal_output chunk whose seq isn't greater than the last accepted one, and terminal_replay.seq baselines it on (re)subscribe.

  • Additive/backward compatible: a streamer that omits seq (older version) never trips the guard — msg.seq != null gates both checks.
  • No change to wrapping behavior (confirmed separately: that's native RN Text wrap, working as intended).

Base branch note

Branched from fix/diff-viewer-full-width-lines-integration (currently the most recent upstream branch) since basing off main directly produced Podfile.lock rebase conflicts from unrelated iOS build-number bump commits already on that branch. This PR's own diff touches only hooks/useTerminalStream.ts, services/ws-client.ts, and its new test file — no overlap with the base branch's changes.

Test plan

  • npx tsc --noEmit — clean
  • npx eslint hooks/useTerminalStream.ts services/ws-client.ts __tests__/unit/hooks/useTerminalStream.seq.test.tsx — clean
  • New __tests__/unit/hooks/useTerminalStream.seq.test.tsx: accepts increasing seq, drops a stale/lower seq, baselines from terminal_replay.seq, and never rejects when a streamer omits seq entirely
  • Existing useTerminalStream.userMessages.test.tsx and useTerminalStream.watchdog.test.tsx still pass (14/14 total across the three suites)

Guard against a frame from a superseded WS connection landing after
a reconnect reset, using the streamer's new per-session seq field.
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.

1 participant