fix(tui): stop leaking unrelated thread events into pre-primary startup buffer#176
Closed
andrei-hasna wants to merge 1 commit into
Closed
Conversation
During startup the primary thread is set asynchronously, so there is a window where primary_thread_id is None. Previously handle_server_notification_event and handle_server_request_event routed every thread-targeted event to enqueue_primary_thread_notification/request whenever primary_thread_id was None, and the flush in enqueue_primary_thread_session re-dispatched all buffered events onto the newly-started primary thread. Notifications and requests from unrelated loaded or scheduled threads leaked into the primary buffer and corrupted the primary event stream. Two layers now keep pre-primary routing correct: - Entry point: when primary_thread_id is None but the target thread is already tracked (has a channel or is a registered side thread), route directly to that thread instead of buffering as a pending primary event. - Flush: re-derive each buffered event's own thread and route by it — to the started primary when it matches, to an already-tracked thread's own channel otherwise, or drop (with a debug log) when the thread is untracked and unrelated. Adds regression coverage asserting an unrelated pre-primary notification is dropped rather than replayed onto the primary, and that a known-thread event routes to its own channel. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
Author
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.
Summary
Fixes startup routing for pre-primary thread notifications (todos task
66ca861a).During startup the primary thread is configured asynchronously, so there is a window where
primary_thread_idisNone. Previouslyhandle_server_notification_event/handle_server_request_eventrouted every thread-targeted event toenqueue_primary_thread_notification/requestwheneverprimary_thread_idwasNone, and the flush inenqueue_primary_thread_sessionre-dispatched all buffered events onto the newly-started primary thread. Notifications/requests from unrelated loaded or scheduled threads leaked into the primary buffer and corrupted the primary event stream.Changes
app_server_events.rs): during the pre-primary window, if the target thread is already tracked (has a channel or is a registered side thread), route directly to that thread instead of buffering it as a pending primary event. Unknown threads still buffer (may be the primary being started).thread_routing.rs): re-derive each buffered event's own thread and route by it — to the started primary when it matches, to an already-tracked thread's own channel otherwise, or drop (with a debug log) when the thread is untracked and unrelated.ServerNotificationThreadTarget::thread_id()andApp::is_tracked_thread/resolve_pending_primary_flush_targethelpers.Tests
enqueue_primary_thread_session_drops_unrelated_pre_primary_notifications— asserts an unrelated pre-primary notification is dropped rather than replayed onto the primary, while the primary's own buffered event still replays.enqueue_primary_thread_session_routes_known_thread_pre_primary_notifications— asserts a known-thread event routes to its own channel, not the primary stream.enqueue_primary_thread_session_replays_buffered_approval_after_attachandresolved_buffered_approval_does_not_become_actionable_after_drainstill pass (same-thread buffered replay preserved).Validation:
cargo check -p codex-tui, focusedcargo test -p codex-tui,cargo fmt, andcargo clippy -p codex-tui --all-targetsall clean.🤖 Generated with Claude Code