Repository navigation
refactor(tui): re-arm the chat listener centrally and drop isDomainEvent - #1159
Merged
Merged
Conversation
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
Closed
3 tasks
Contributor
|
🎉 This PR is included in version 0.188.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1150
What
ListenForChatEventsnow yieldstui.ChatChannelEvent{Event, Source}.ChatHandler.Handleunwraps it, dispatches, and re-arms the read onSourceexactly once, only whileSourceis still the active session's channel. This is the single re-arm site.ListenForChatEventsappends are gone (chat_handler, chat_handler_handlers, chatcompletion runner, toolcoordinator, a2acoord, directexec bash fallback). a2acoord no longer takes aListener.Runner.Startreads the first event off the stream instead of emitting a syntheticChatStartEvent. Previously the synthetic event and the agent's ownChatStartEventeach armed a listener, so every turn ran two concurrent readers.isDomainEventis deleted. Its type list was identical toHandle's switch;Updatenow callsHandleunconditionally and unknown types return nil.Why not key on the
ChatEventinterfaceMany
ChatEventimplementations never come off the chat channel:NavigateBackInTimeEvent(keybinding),MessageEditSubmitEvent/MessageHistoryRestoreEvent(app),ToolCallPreviewEvent(one per tool call, from a cmd),UserQuestionRequestedEvent(tool channel),UserMessageChatEventand 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 unknownChatEventread off the channel keeps the chain alive; the same event off-channel or from a stale channel adds no reader.go test -race ./internal/presentation/tui/...andtask precommit:runclean.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.