Skip to content

Centralize TUI project event adapter - #231

Merged
TraderSamwise merged 2 commits into
masterfrom
chore/next-20260623-tui-connection-adapter-6
Jun 23, 2026
Merged

Centralize TUI project event adapter#231
TraderSamwise merged 2 commits into
masterfrom
chore/next-20260623-tui-connection-adapter-6

Conversation

@TraderSamwise

@TraderSamwise TraderSamwise commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • wrap dashboard project SSE lifecycle in a single adapter owned by the TUI host
  • move stream aborts, reconnect recovery, pending view coalescing, and refresh fanout behind that adapter
  • guard stale in-flight event refreshes after stop/restart and cover teardown cleanup

Verification

  • yarn vitest run src/multiplexer/project-event-stream.test.ts src/multiplexer/runtime-lifecycle-methods.test.ts
  • yarn typecheck && yarn lint && yarn vitest run && yarn build
  • pre-push hook: yarn typecheck && yarn lint && yarn test

Summary by CodeRabbit

  • Tests

    • Added coverage ensuring dashboard event streaming stops safely during in-flight refreshes, without triggering further view renders.
    • Added coverage verifying buffered or queued alert events don’t appear in the UI after stopping the stream.
    • Updated teardown tests to confirm adapter state is cleared as expected.
  • Refactor

    • Improved dashboard project event stream handling with more robust stop/start behavior and safer refresh scheduling/currency checks.

@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
app Ready Ready Preview, Comment Jun 23, 2026 6:02am

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 63f0ddb2-ea74-4442-af95-6b043196067b

📥 Commits

Reviewing files that changed from the base of the PR and between 5be71eb and 030c5e9.

📒 Files selected for processing (2)
  • src/multiplexer/project-event-stream.test.ts
  • src/multiplexer/project-event-stream.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/multiplexer/project-event-stream.test.ts
  • src/multiplexer/project-event-stream.ts

📝 Walkthrough

Walkthrough

project-event-stream.ts is refactored from host-attached state fields into a per-host DashboardProjectEventAdapter class that owns an AbortController, debounced refresh scheduling, a pendingViews set, and a generation counter to invalidate stale or post-stop render work. An explicit abort check is added during SSE stream reading. Exported start/stop and delegate functions are updated to use the adapter instance, and new tests cover the stop-during-in-flight and buffered-event-suppression scenarios alongside teardown cleanup.

Changes

DashboardProjectEventAdapter refactor

Layer / File(s) Summary
DashboardProjectEventAdapter class, abort handling, and exported wiring
src/multiplexer/project-event-stream.ts
Introduces DashboardProjectEventAdapter encapsulating AbortController, generation counter, debounced scheduleViewRefresh, SSE runLoop, recover, and refreshViews methods. Adds an explicit abort check in readEventStream to return early when signal.aborted is observed. Updates startDashboardProjectEventStream/stopDashboardProjectEventStream to use getOrCreateDashboardProjectEventAdapter. Rewires handleProjectEvent and scheduleProjectViewRefresh to delegate to the adapter instance.
Tests: stop-during-in-flight, buffered-event suppression, and teardown cleanup
src/multiplexer/project-event-stream.test.ts, src/multiplexer/runtime-lifecycle-methods.test.ts
Adds a test asserting that stopping the stream while a refresh is in-flight allows refreshDashboardModelFromService to complete but blocks renderCurrentDashboardView. Adds a test verifying that SSE events enqueued after stop are ignored and do not trigger rendering. Extends the teardown test to include tuiProjectEventAdapter with a mocked stop() and asserts it is set to null after teardown.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • TraderSamwise/aimux#196: Initial project-service /events SSE integration and dashboard lifecycle wiring that this PR's adapter refactor builds upon.
  • TraderSamwise/aimux#219: Modifies event-driven refresh invocation in project-event-stream.ts, passing force: true into screen refreshes that this adapter now controls.
  • TraderSamwise/aimux#222: Hardens SSE/view-refresh behavior in project-event-stream.ts to prevent UI renders after stop and gate stale in-flight work.

Poem

🐇 A generation grows, timers tick away,
Old host fields scatter, the adapter holds sway.
In-flight refreshes finish, but rendering? No fear—
The generation guards render when stop is near.
Buffered events fade to silence, the stream runs anew,
One class to rule them all, tidy and true! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: centralizing the TUI project event adapter by consolidating SSE lifecycle handling into a unified adapter owned by the TUI host.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/next-20260623-tui-connection-adapter-6

Comment @coderabbitai help to get the list of available commands.

@TraderSamwise

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/multiplexer/project-event-stream.ts`:
- Around line 224-231: The changes to the startDashboardProjectEventStream and
stopDashboardProjectEventStream functions in project-event-stream.ts modify
aimux runtime behavior regarding SSE adapter lifecycle management, which
requires regenerating the compiled output. Run yarn build to rebuild the dist/
directory with these runtime changes, since source-level validation alone with
yarn vitest and yarn typecheck is insufficient to ship runtime behavior
modifications.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f8aaa057-c999-4ec5-bf6c-c85bc5ed4614

📥 Commits

Reviewing files that changed from the base of the PR and between 17e718e and 5be71eb.

📒 Files selected for processing (3)
  • src/multiplexer/project-event-stream.test.ts
  • src/multiplexer/project-event-stream.ts
  • src/multiplexer/runtime-lifecycle-methods.test.ts

Comment thread src/multiplexer/project-event-stream.ts
@TraderSamwise
TraderSamwise merged commit 44b7fcf into master Jun 23, 2026
3 checks passed
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