Skip to content

Tighten TUI API connection state - #341

Merged
TraderSamwise merged 2 commits into
masterfrom
chore/core-sidecar-next-66
Jul 6, 2026
Merged

Tighten TUI API connection state#341
TraderSamwise merged 2 commits into
masterfrom
chore/core-sidecar-next-66

Conversation

@TraderSamwise

@TraderSamwise TraderSamwise commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • replace the TUI API runtime's connected/degraded state with explicit ready/refreshing/stale/reconnecting/repairing/repaired/failed phases
  • expose connection snapshots with pending/stale/failed resource details
  • wire scheduled recovery into repairing/repaired/failed transitions and update north-star docs

Verification

  • yarn vitest run src/multiplexer/tui-api-runtime.test.ts
  • yarn verify

Summary by CodeRabbit

  • New Features

    • Improved connection status reporting with more precise states during refresh and recovery.
    • Added clearer runtime snapshot information so the app can better reflect pending, stale, and failed resources.
  • Bug Fixes

    • Critical views now stay in a refreshing or stale state during API interruptions and recover only after recovery completes.
    • Recovery handling is now more reliable, including clearer transitions when scheduled checks succeed or fail.

@vercel

vercel Bot commented Jul 6, 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 Jul 6, 2026 2:28pm

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 50 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d20c6eb0-0bf3-4aed-8865-b43f53089ec0

📥 Commits

Reviewing files that changed from the base of the PR and between 4b79b66 and d39ef28.

📒 Files selected for processing (1)
  • src/multiplexer/tui-api-runtime.test.ts
📝 Walkthrough

Walkthrough

TuiApiRuntime's connection state model is replaced with a multi-phase state machine (ready, refreshing, stale, reconnecting, repairing, repaired, failed, disposed), adding a new connection snapshot interface and recovery lifecycle methods. Tests are updated to match new states, and documentation reflects the new terminology.

Changes

Connection state machine expansion

Layer / File(s) Summary
State type and snapshot contract
src/multiplexer/tui-api-runtime.ts
TuiApiConnectionState expands to eight states; new TuiApiConnectionSnapshot interface and getConnectionSnapshot() method expose derived resource lists and lastError; initial state changes to "ready".
Transition helpers and recovery lifecycle
src/multiplexer/tui-api-runtime.ts
New beginRecovery(), markRecoveryFailed(), finishRecovery(), markRecoverableFailure(), hasAnyStaleResource(), and updated markRequestSuccess()/markResourceRefreshStarted() manage state transitions.
Wiring into request/mutation/refresh/recovery flows
src/multiplexer/tui-api-runtime.ts
Request, mutation, and refresh failure handling call markRecoverableFailure; refresh() calls markResourceRefreshStarted; onConnectionStateChange writes host.tuiApiConnectionSnapshot; scheduled recovery calls beginRecovery/finishRecovery/markRecoveryFailed.
Test suite updates
src/multiplexer/tui-api-runtime.test.ts
Existing assertions updated from connected/degraded to ready/reconnecting/stale; new tests added for connection snapshots and scheduled recovery success/failure transitions.
Documentation updates
docs/core-sidecar-north-star.md, docs/north-star-completion-tracker.md
North-star doc rewords critical-resource behavior to stale/reconnecting terminology; Epic C checklist marks state machine and regression-test items complete.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Scheduler
  participant TuiApiRuntime
  participant Host
  Scheduler->>TuiApiRuntime: beginRecovery()
  TuiApiRuntime->>TuiApiRuntime: refreshRuntimeGuard()
  TuiApiRuntime->>TuiApiRuntime: refreshCriticalResources()
  alt success
    TuiApiRuntime->>TuiApiRuntime: finishRecovery()
  else error
    TuiApiRuntime->>TuiApiRuntime: markRecoveryFailed(error)
  end
  TuiApiRuntime->>Host: onConnectionStateChange updates tuiApiConnectionSnapshot
Loading

Possibly related PRs

  • TraderSamwise/aimux#233: Overlaps at the recovery/probe implementation level with the debounced scheduled-recovery logic in the same runtime file.
  • TraderSamwise/aimux#240: Modifies the same scheduled recovery/connection-state transition logic in tui-api-runtime.ts.
  • TraderSamwise/aimux#269: Directly changes recovery/connection-state transition behavior and exposed state values in the same file and its tests.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: tightening the TUI API connection state model.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/core-sidecar-next-66

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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

@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.

🧹 Nitpick comments (1)
src/multiplexer/tui-api-runtime.test.ts (1)

478-512: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Strengthen the new success-path recovery test.

toContain checks don't verify ordering or that the mocked refreshRuntimeGuard/getFromProjectService were actually invoked. As written, this test would still pass even if "repaired" appeared before "repairing", or if the recovery path never called the mocks the way intended. The sibling recovery test (lines 432-445) asserts toHaveBeenCalledTimes for exactly this reason — consider mirroring that here, plus asserting relative ordering (e.g. states.indexOf("repairing")).toBeLessThan(states.indexOf("repaired")) or toEqual on the full sequence).

Suggested strengthening
       expect(states).toContain("repairing");
       expect(states).toContain("repaired");
       expect(runtime.getConnectionState()).toBe("ready");
+      expect(states.indexOf("repairing")).toBeLessThan(states.indexOf("repaired"));
+      expect(host.refreshRuntimeGuard).toHaveBeenCalledTimes(1);
+      expect(host.getFromProjectService).toHaveBeenCalledTimes(2);
🤖 Prompt for 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.

In `@src/multiplexer/tui-api-runtime.test.ts` around lines 478 - 512, The
success-path recovery test in TuiApiRuntime is too weak because it only checks
for presence of states, not ordering or that the recovery mocks were exercised.
Strengthen the test by asserting the expected call counts on refreshRuntimeGuard
and getFromProjectService, then verify the connection-state sequence in order
around scheduleTuiApiRecovery and refreshJson. Use the existing states array to
assert that "repairing" occurs before "repaired" and that the final state is
"ready", matching the stricter sibling recovery test pattern.
🤖 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.

Nitpick comments:
In `@src/multiplexer/tui-api-runtime.test.ts`:
- Around line 478-512: The success-path recovery test in TuiApiRuntime is too
weak because it only checks for presence of states, not ordering or that the
recovery mocks were exercised. Strengthen the test by asserting the expected
call counts on refreshRuntimeGuard and getFromProjectService, then verify the
connection-state sequence in order around scheduleTuiApiRecovery and
refreshJson. Use the existing states array to assert that "repairing" occurs
before "repaired" and that the final state is "ready", matching the stricter
sibling recovery test pattern.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dd7f80e1-350d-4c65-a562-bb068c6694e2

📥 Commits

Reviewing files that changed from the base of the PR and between f9f909a and 4b79b66.

📒 Files selected for processing (4)
  • docs/core-sidecar-north-star.md
  • docs/north-star-completion-tracker.md
  • src/multiplexer/tui-api-runtime.test.ts
  • src/multiplexer/tui-api-runtime.ts

@TraderSamwise
TraderSamwise merged commit 73a671b into master Jul 6, 2026
3 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jul 6, 2026
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