Skip to content

fix(tui): stop leaking unrelated thread events into pre-primary startup buffer#176

Closed
andrei-hasna wants to merge 1 commit into
mainfrom
openloops/open-codewith/66ca861a-fd0e-4ca4-99bd-7b0aae748f5c-29e96610
Closed

fix(tui): stop leaking unrelated thread events into pre-primary startup buffer#176
andrei-hasna wants to merge 1 commit into
mainfrom
openloops/open-codewith/66ca861a-fd0e-4ca4-99bd-7b0aae748f5c-29e96610

Conversation

@andrei-hasna

Copy link
Copy Markdown
Contributor

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_id is None. Previously handle_server_notification_event / 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/requests from unrelated loaded or scheduled threads leaked into the primary buffer and corrupted the primary event stream.

Changes

  • Entry point (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).
  • Flush (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.
  • Added ServerNotificationThreadTarget::thread_id() and App::is_tracked_thread / resolve_pending_primary_flush_target helpers.

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.
  • Existing enqueue_primary_thread_session_replays_buffered_approval_after_attach and resolved_buffered_approval_does_not_become_actionable_after_drain still pass (same-thread buffered replay preserved).

Validation: cargo check -p codex-tui, focused cargo test -p codex-tui, cargo fmt, and cargo clippy -p codex-tui --all-targets all clean.

🤖 Generated with Claude Code

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>
@andrei-hasna

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #211. Replacement #211 consolidates the current TUI/thread-routing stack and explicitly supersedes this PR. Please continue review on #211.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant