Skip to content

fix: reconcile worktree lifecycle transitions - #343

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

fix: reconcile worktree lifecycle transitions#343
TraderSamwise merged 8 commits into
masterfrom
chore/core-sidecar-next-68

Conversation

@TraderSamwise

@TraderSamwise TraderSamwise commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • keep TUI worktree create/graveyard pending through transient project-service snapshot misses
  • reconcile slow creates/removals in the background instead of surfacing premature failure dialogs
  • update the north-star tracker for TUI worktree lifecycle settlement

Verification

  • yarn vitest run src/multiplexer/worktrees.test.ts src/multiplexer/dashboard-ops.test.ts src/multiplexer/tui-api-runtime.test.ts src/dashboard/pending-actions.test.ts
  • yarn typecheck
  • yarn lint
  • yarn build
  • yarn vitest run

Summary by CodeRabbit

  • Bug Fixes
    • Improved worktree creation flow so “pending” stays until the new worktree is actually visible, including slow/delayed situations.
    • Prevented stale results from clearing newer pending worktree actions, avoiding UI flicker and incorrect success/failure states.
    • Made dashboard refreshes more reliable during inactive/session periods and adjusted server error handling to return 422 instead of 500 for failed create attempts.

@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 6: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: 20 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: 6b5d4088-fd5d-48c5-9935-5d6b1e4cb2bf

📥 Commits

Reviewing files that changed from the base of the PR and between d290eff and abe0abf.

📒 Files selected for processing (3)
  • src/metadata-server.test.ts
  • src/metadata-server.ts
  • src/multiplexer/worktrees.test.ts
📝 Walkthrough

Walkthrough

The PR adds allowInactive dashboard model refresh handling for inactive sessions and refactors worktree create and graveyard mutations to use token-aware pending tracking with reconciliation. Tests and the completion tracker are updated, and one server error response changes from 500 to 422.

Changes

Dashboard refresh while inactive

Layer / File(s) Summary
Allow-inactive refresh contract
src/multiplexer/dashboard-model.ts, src/multiplexer/dashboard-api-client.ts, src/multiplexer/dashboard-model-service.test.ts, src/multiplexer/dashboard-api-client.test.ts
Adds allowInactive to refresh options, forwards it through API/service refresh calls, and covers inactive-session refresh behavior in tests.
Worktree mutation reconciliation
src/multiplexer/worktrees.ts, src/metadata-server.ts, src/multiplexer/worktrees.test.ts, docs/north-star-completion-tracker.md
Refactors worktree create and graveyard settlement around token-aware pending actions and background reconciliation, updates error handling, expands tests, and splits the completion checklist item.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

  • TraderSamwise/aimux#5: Both changes add token-aware guarding so stale settle callbacks do not clear newer pending worktree actions.
  • TraderSamwise/aimux#222: Both changes alter worktree settlement flows to use lifecycle/current-state gating against stale async results.
  • TraderSamwise/aimux#229: Both changes thread lifecycle-scoped refresh behavior through dashboard model settlement paths.
🚥 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 matches the main change: reconciling worktree lifecycle transitions and pending settlement behavior.
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-68

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/multiplexer/worktrees.ts (1)

128-138: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Reuse the shared recoverability contract here isRecoverableWorktreeRequestError falls back to false for opaque errors, unlike isRecoverableTuiApiError, which falls back to true. That sends unclassified create failures down the immediate error path instead of reconcile; reuse the shared helper or match its fallback.

🤖 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/worktrees.ts` around lines 128 - 138,
isRecoverableWorktreeRequestError currently diverges from the shared
recoverability contract by returning false for opaque errors, which bypasses
reconcile for unclassified failures; update it to reuse the same logic as
isRecoverableTuiApiError or otherwise match its true-by-default fallback. Keep
the existing recoverable/status/code checks in worktrees.ts, but ensure unknown
errors are treated as recoverable so create failures follow the reconcile path
consistently.
🤖 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/worktrees.test.ts`:
- Line 736: The `vi.waitFor` assertion in `worktrees.test.ts` is relying on the
default timeout, which is too tight for this pending-state transition and can
flake in CI. Update the `vi.waitFor` call in the worktree pending-state test to
pass an explicit longer timeout, matching the sibling test’s approach for
consistency and enough headroom. Use the existing `pending.state.get(...)`
assertion site to locate it.

---

Nitpick comments:
In `@src/multiplexer/worktrees.ts`:
- Around line 128-138: isRecoverableWorktreeRequestError currently diverges from
the shared recoverability contract by returning false for opaque errors, which
bypasses reconcile for unclassified failures; update it to reuse the same logic
as isRecoverableTuiApiError or otherwise match its true-by-default fallback.
Keep the existing recoverable/status/code checks in worktrees.ts, but ensure
unknown errors are treated as recoverable so create failures follow the
reconcile path consistently.
🪄 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: f222fa4c-93fe-4cf4-9a37-246ac0f7aaa9

📥 Commits

Reviewing files that changed from the base of the PR and between 4547fbc and 21d29cb.

📒 Files selected for processing (3)
  • docs/north-star-completion-tracker.md
  • src/multiplexer/worktrees.test.ts
  • src/multiplexer/worktrees.ts

Comment thread src/multiplexer/worktrees.test.ts
@TraderSamwise

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@TraderSamwise

Copy link
Copy Markdown
Owner Author

Handled CodeRabbit summary recoverability finding in d290eff: worktree mutations now reuse isRecoverableTuiApiError for opaque/retryable failures while keeping explicit 501 create-unsupported responses terminal; synchronous worktree create domain failures now return 422 from the project service.

@coderabbitai

coderabbitai Bot commented Jul 6, 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/worktrees.test.ts`:
- Around line 1103-1146: The allowInactive check inside the mock for
refreshDashboardModelFromService is too brittle because a failed expectation can
be swallowed by the surrounding refresh error handling. Update the test to
capture the options passed into refreshDashboardModelFromService on each call
and assert after the async flow completes that at least one invocation included
allowInactive: true, so the failure surfaces as a real test assertion. Use the
existing symbols refreshDashboardModelFromService, beginWorktreeRemoval, and
attachPendingReapply to keep the assertion tied to the same scenario.
🪄 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: 3798d0d6-19a1-4af5-a8e3-16b261266572

📥 Commits

Reviewing files that changed from the base of the PR and between 21d29cb and d290eff.

📒 Files selected for processing (7)
  • src/metadata-server.ts
  • src/multiplexer/dashboard-api-client.test.ts
  • src/multiplexer/dashboard-api-client.ts
  • src/multiplexer/dashboard-model-service.test.ts
  • src/multiplexer/dashboard-model.ts
  • src/multiplexer/worktrees.test.ts
  • src/multiplexer/worktrees.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/multiplexer/worktrees.ts

Comment thread src/multiplexer/worktrees.test.ts
@TraderSamwise

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 6, 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.

@TraderSamwise

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 6, 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.

@TraderSamwise

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 6, 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.

@TraderSamwise
TraderSamwise merged commit e6abc05 into master Jul 6, 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