Skip to content

refactor(tui): re-arm the chat listener centrally and drop isDomainEvent - #1159

Merged
edenreich merged 1 commit into
mainfrom
refactor/central-chat-listener-rearm
Sep 2, 2026
Merged

edenreich merged 1 commit into
mainfrom
refactor/central-chat-listener-rearm

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

Closes #1150

What

  • ListenForChatEvents now yields tui.ChatChannelEvent{Event, Source}. ChatHandler.Handle unwraps it, dispatches, and re-arms the read on Source exactly once, only while Source is still the active session's channel. This is the single re-arm site.
  • All per-handler / per-coordinator ListenForChatEvents appends are gone (chat_handler, chat_handler_handlers, chatcompletion runner, toolcoordinator, a2acoord, directexec bash fallback). a2acoord no longer takes a Listener.
  • Runner.Start reads the first event off the stream instead of emitting a synthetic ChatStartEvent. Previously the synthetic event and the agent's own ChatStartEvent each armed a listener, so every turn ran two concurrent readers.
  • isDomainEvent is deleted. Its type list was identical to Handle's switch; Update now calls Handle unconditionally and unknown types return nil.

Why not key on the ChatEvent interface

Many ChatEvent implementations never come off the chat channel: NavigateBackInTimeEvent (keybinding), MessageEditSubmitEvent / MessageHistoryRestoreEvent (app), ToolCallPreviewEvent (one per tool call, from a cmd), UserQuestionRequestedEvent (tool channel), UserMessageChatEvent and friends (BroadcastEvent). Re-arming on the interface would add a reader for each of those, and N concurrent readers deliver chunks out of order. Marking what the listener actually read is the only signal that cannot drift.

Tests

  • TestHandle_RearmsChatListener (handlers): an unknown ChatEvent read off the channel keeps the chain alive; the same event off-channel or from a stale channel adds no reader.
  • Removed the judge-specific tests it supersedes; a2acoord tests drop the listener assertions.
  • go test -race ./internal/presentation/tui/... and task precommit:run clean.
  • Manual, mock gateway (INFER_GATEWAY_MOCK=true): a text + Bash tool-call turn completes with the card leaving "queued"; a slow-streamed turn cancelled with Esc shows "User interrupted" and the next turn (tool call + completion) runs cleanly.

Every chat event handler re-armed ListenForChatEvents by hand and every new
event type also had to be added to isDomainEvent; missing either silently
killed the event chain (#1148 left the tool card stuck at "queued").

ListenForChatEvents now yields tui.ChatChannelEvent{Event, Source}. ChatHandler.Handle
unwraps it, dispatches, and re-arms the read on Source once, only while Source is
still the active session's channel. Handlers and coordinators no longer append
listeners. Runner.Start reads the first event off the stream instead of emitting
a synthetic ChatStartEvent, which previously armed a second listener per turn
alongside the agent's own ChatStartEvent.

isDomainEvent duplicated Handle's type switch and is removed; Update calls Handle
unconditionally and Handle ignores unknown types. Re-arming is keyed on "read off
the chat channel" rather than the ChatEvent interface because many ChatEvent
implementations (navigation, message edit, tool-call previews, broadcasts) never
come from the channel and would each add a concurrent reader.

Closes #1150
@edenreich
edenreich requested a review from a team as a code owner September 2, 2026 19:29
@edenreich
edenreich merged commit 438c9fb into main Sep 2, 2026
1 check passed
@edenreich
edenreich deleted the refactor/central-chat-listener-rearm branch September 2, 2026 19:39
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.188.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TASK] Refactor re-arm the TUI chat listener centrally and drop the isDomainEvent type list

1 participant