hermes-agent/ui-tui/src
kshitijk4poor f64d15ccb7 fix(tui): defer buffered gateway events to stop dashboard chat #301 (#36658)
Dashboard /chat spawns the TUI attached to the dashboard's in-memory
gateway via HERMES_TUI_GATEWAY_URL. In that attach mode the already-running
gateway replays `gateway.ready` (and `session.info`) the instant the socket
connects, so those events land in GatewayClient.bufferedEvents *before* the
consumer's mount-time subscribe effect (useMainApp.ts) calls drain().

drain() then emitted the buffered events synchronously, so the
`gateway.ready` handler's patchUiState / setHistoryItems cascade ran while
React was still inside the first commit — tripping "Too many re-renders"
(Minified React error #301) and breaking Dashboard chat after `hermes update`.
Spawn / inline / sidecar modes never hit this: their `gateway.ready` only
arrives after the Python child boots, on a later async tick.

Fix: drain() defers the replay to the next microtask AND keeps `subscribed`
false until that microtask runs. Keeping `subscribed` false in the gap means
any live event arriving before the flush keeps buffering (publish() pushes
when !subscribed) instead of emitting synchronously and jumping ahead of the
chronologically-earlier replayed events — the flush re-drains the buffer
right after flipping `subscribed`, preserving FIFO order. A drainGeneration
token (bumped in resetStartupState) makes a queued flush a no-op if the
transport was reset/killed in the meantime, avoiding use-after-teardown and
duplicate/reordered exits.

Regression tests: (1) drain() does not dispatch buffered events synchronously;
(2) a live event arriving in the post-drain / pre-microtask window still
delivers BEHIND the earlier-buffered event (FIFO). Both are red against the
old synchronous behavior, green with this fix. Same class of fix as #44528.

Closes #36658
2026-06-28 14:18:47 +05:30
..
__tests__ fix(tui): defer buffered gateway events to stop dashboard chat #301 (#36658) 2026-06-28 14:18:47 +05:30
app feat(moa): render reference-model blocks in TUI and desktop, not just CLI (#53855) 2026-06-27 18:46:20 -07:00
components fix: also preserve provider selection on Esc-clear-filter path 2026-06-27 04:33:48 +05:30
config style(desktop,tui): fix all lint/type/formatting issues 2026-06-26 01:04:33 -05:00
content feat: add TUI session orchestrator 2026-05-26 20:51:59 -07:00
domain style(desktop,tui): fix all lint/type/formatting issues 2026-06-26 01:04:33 -05:00
hooks style(desktop,tui): fix all lint/type/formatting issues 2026-06-26 01:04:33 -05:00
lib style(desktop,tui): fix all lint/type/formatting issues 2026-06-26 01:04:33 -05:00
protocol refactor(tui): /clean pass across ui-tui — 49 files, −217 LOC 2026-04-16 22:32:53 -05:00
types feat(pets): TUI pet pane, picker + gateway RPCs 2026-06-20 14:18:36 -05:00
app.tsx fix(tui): apply ui-tui fix pass and restore type-check 2026-04-25 14:08:54 -05:00
banner.ts feat(tui): responsive banner tiers 2026-05-23 17:37:51 -05:00
entry.tsx style(desktop,tui): fix all lint/type/formatting issues 2026-06-26 01:04:33 -05:00
gatewayClient.ts fix(tui): defer buffered gateway events to stop dashboard chat #301 (#36658) 2026-06-28 14:18:47 +05:30
gatewayTypes.ts feat(moa): render reference-model blocks in TUI and desktop, not just CLI (#53855) 2026-06-27 18:46:20 -07:00
theme.ts style(desktop,tui): fix all lint/type/formatting issues 2026-06-26 01:04:33 -05:00
types.ts feat(tui): track background subagents in the status bar (#51485) 2026-06-23 11:32:00 -07:00