Skip to content

refactor(switch): pin the picker alt-r keep path to BranchOnly - #3228

Merged
max-sixty merged 3 commits into
mainfrom
picker-row-removal-loop
Jun 25, 2026
Merged

max-sixty merged 3 commits into
mainfrom
picker-row-removal-loop

Conversation

@max-sixty

@max-sixty max-sixty commented Jun 25, 2026 •

Copy link
Copy Markdown
Owner

Two review follow-ups from #3211 (the picker's up-front alt-r removability prediction), no behavior change.

keep_unremovable_row took the whole RemoveResult and re-matched for BranchOnly, silently no-oping the impossible RemovedWorktree arm. It now takes branch_name: &str, so the keep path is unrepresentable for a worktree result, and invoke destructures the branch in the keep arm. The invariant that only a BranchOnly row reaches that arm is already pinned by removal_will_remove_target's tested truth table — every RemovedWorktree returns true, so the non-removing branch can only be BranchOnly. The impossible case therefore needs no runtime guard: an else { debug_assert!(false) } would duplicate that guarantee (belt-and-suspenders) and add a permanently-uncovered line, so it's left out.

The second change is doc-only: it records the overlapping reposition-chains tradeoff in send_reposition. Rapid alt-r leaves several self-terminating chains in flight; the last to run wins, and the cursor self-corrects on the next render. Pinning this to only the newest reposition would mean threading a generation token through every chain and every PickerCollector construction site — not worth it for a self-correcting cosmetic transient.

This was written by Claude Code on behalf of max

max-sixty and others added 2 commits June 24, 2026 22:10
Follow-ups from #3211's up-front removability prediction.

`keep_unremovable_row` took the whole `RemoveResult` and re-matched for
`BranchOnly`, silently no-oping the impossible `RemovedWorktree` arm. It now
takes `branch_name: &str`, so the keep path is unrepresentable for a worktree
result; `invoke` destructures the branch and `debug_assert!`s the unreachable
variant (a `RemovedWorktree` always removes, so it never reaches the keep path).

Also documents the overlapping reposition-chains tradeoff in `send_reposition`:
rapid alt-r leaves several self-terminating chains in flight, last-to-run wins,
and the cursor self-corrects on the next render — not worth a cross-chain
generation token.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The type narrowing of `keep_unremovable_row` to `&str` already makes a
`RemovedWorktree` unrepresentable on the keep path, and the tested
`removal_will_remove_target` truth table pins that a worktree always removes.
A `debug_assert!(false)` for that case was belt-and-suspenders and an
uncovered line; let the impossible branch fall through (a kept row is
data-safe regardless).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The refactor is sound — removal_will_remove_target returns true for every RemovedWorktree, so the non-removing else can only be a BranchOnly, and narrowing keep_unremovable_row to take branch_name: &str makes the keep path unrepresentable for a worktree result. Nice.

One small gap: the PR body says invoke "debug_assert!s the unreachable variant," but there's no assert in the diff — the impossible RemovedWorktree-reaching-the-else case silently no-ops (the else if let just doesn't match). That preserves the old behavior, but doesn't deliver the safety the body describes. Either add the assert (suggested inline) or drop the claim from the description.

Comment thread src/commands/picker/mod.rs Resolved
@max-sixty
max-sixty merged commit a66f03d into main Jun 25, 2026
45 of 47 checks passed
@max-sixty
max-sixty deleted the picker-row-removal-loop branch June 25, 2026 06:53
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.

2 participants