← Back to PRs

#9218: Fix Control UI chat resync on gaps and terminal events

by figitaki open 2026-02-05 01:05 View on GitHub →
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