#9218: Fix Control UI chat resync on gaps and terminal events
app: web-ui
stale
## Summary
- refresh chat history on websocket event gaps and terminal error/aborted events
- treat error/aborted from other runs as terminal for refresh
- reset gateway event sequence on reconnect to avoid false gap detection
## Testing
- pnpm -C ui exec vitest run src/ui/controllers/chat.test.ts
- pnpm -C ui test *(fails: src/ui/navigation.test.ts expects emoji icon, got "folder" — appears unrelated)*
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates the Control UI’s gateway/webchat handling to better recover from missed websocket events and terminal chat events. Specifically:
- `GatewayBrowserClient` now resets `lastSeq` on each websocket reconnect (`ui/src/ui/gateway.ts`), avoiding false “event gap” detections after a reconnect.
- The app-level gateway handler triggers chat history reloads on detected event gaps and expands “terminal” chat states to include `error` and `aborted` (`ui/src/ui/app-gateway.ts`, `ui/src/ui/controllers/chat.ts`).
- Unit tests were added to assert that `error`/`aborted` terminal events from *other* runs return a terminal state without clearing the current run’s streaming state (`ui/src/ui/controllers/chat.test.ts`).
<h3>Confidence Score: 3/5</h3>
- This PR is likely safe to merge after addressing the identified correctness issue in chat-triggered session refresh and confirming the host typing/casts are sound.
- Core changes are small and localized (gap detection reset; broadened terminal state handling), but there is at least one behavior regression risk: session refresh-after-chat is now gated only on `final`, and the new onGap refresh introduces additional reliance on unsafe casts that can become runtime errors if `connectGateway` is used with a non-`OpenClawApp` host.
- ui/src/ui/app-gateway.ts
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#13902: fix: auto-recover on event gap instead of showing error
by nikogamulin · 2026-02-11
87.9%
#14309: fix(ui): resolve chat event session key mismatch
by justonlyforyou · 2026-02-11
85.2%
#16767: fix: auto-resync webchat on reconnect and prevent message flicker o...
by alewcock · 2026-02-15
82.1%
#15564: fix: webchat messages disappear during concurrent session activity
by Automatedcapitalist · 2026-02-13
81.9%
#3721: fix(ui): webchat not displaying chat responses
by maxmaxrouge-rgb · 2026-01-29
80.5%
#9195: Fix: Control UI fails to render new messages after chat.history Web...
by vishaltandale00 · 2026-02-05
80.5%
#13960: fix(ui): preserve structured config validation error details
by constansino · 2026-02-11
80.3%
#19343: Refactor chat state management: reset chat messages and queue on se...
by saurav470 · 2026-02-17
80.0%
#18694: fix(ui): reset session key to main after /new in webchat
by Phineas1500 · 2026-02-17
79.5%
#13548: feat(control-ui): Add quote reply and send message to session features
by Annaxiebot · 2026-02-10
79.3%