Skip to content

Finish requested picker removals before exiting - #4458

Closed
max-sixty wants to merge 14 commits into
mainfrom
codex/picker-removal-completion
Closed

max-sixty wants to merge 14 commits into
mainfrom
codex/picker-removal-completion

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Leaving the picker can terminate requested removal work before it finishes or before its error is shown. Join removal workers before exit, preserve their actual diagnostics, and restore optimistic rows when removal fails.

Depends on #4457, whose shared removal producer preserves errors after checkout deletion; review this diff against codex/branch-removal-errors.

Validation: 46 focused tests pass under Rust 1.98. Claude reviewed the source; its technical findings are addressed, with the follow-up reviewed independently by Codex.

This was written by Codex on behalf of max-sixty

worktrunk-bot
worktrunk-bot previously approved these changes Oct 12, 2026

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

codecov/patch fails on this head: 10 added lines in src/commands/picker/mod.rs are uncovered. AGENTS.md makes that check a merge gate needing explicit approval, so I've withdrawn my approval until it's addressed or waived.

The gap worth closing is the new else if let Some(error) = failure arm in both background closures (stash_failed_removal(&stashed_warnings, …) in drop_and_remove_in_background and morph_and_remove_in_background). It handles a removal that errors after the checkout is gone, which is the case the PR description calls out ("report it even when there is no row to restore"), and no test reaches it. The do_removal doc names a trigger: a post-remove/post-switch hook that fails to render or spawn during announcer.flush(). A test like test_apply_reverts_morph_when_pre_remove_fails with an approved post-remove that fails that way, then finish_removals and an assert on the stash, would cover both arms.

The other misses look fine to leave: the Err arm of spawn_removal (thread spawn failure) and the empty-diagnostic early returns in stash_failed_removal / stash_diagnostic aren't reachable from a normal test.

@worktrunk-bot
worktrunk-bot dismissed their stale review October 12, 2026 20:56

codecov/patch failed — merging needs a coverage fix or explicit maintainer approval

@max-sixty
max-sixty changed the base branch from main to codex/branch-removal-errors October 12, 2026 21:37
worktrunk-bot
worktrunk-bot previously approved these changes Oct 12, 2026

@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 new test_post_removal_ref_failure_preserves_drop_or_morph_outcome covers the post-checkout failure arm I asked about. codecov/patch is still red at 97.1%, though. The 7 lines it reports as missed are the Err arm of spawn_removal (thread spawn failure), the empty-diagnostic return in stash_diagnostic, and an assert-message argument in a test. None of them can be reached from a normal test. AGENTS.md makes a failing codecov/patch a merge gate that needs explicit approval, so I've withdrawn my approval again. A maintainer waiver is the remaining step. The code itself needs no change.

@worktrunk-bot
worktrunk-bot dismissed their stale review October 12, 2026 22:12

CI failed — codecov/patch below target; needs maintainer waiver

Base automatically changed from codex/branch-removal-errors to main October 28, 2026 17:32
@max-sixty

Copy link
Copy Markdown
Owner Author

Closing in favor of #4861, which fixes the same failure in far less code: the picker now waits for a requested removal before exiting.

This was written by Claude Code on behalf of max-sixty

@max-sixty max-sixty closed this Nov 20, 2026
max-sixty added a commit that referenced this pull request Nov 21, 2026
…ker removals before exit (#4861)

Three removal-safety fixes. Together they replace #4458 and #4463,
fixing the same failures in far less code.

**`wt remove` and `wt step prune` deleted a checkout nested inside the
target.** `wt remove`, `wt remove --force` and `wt step prune` moved the
target into trash along with any checkout nested inside it, deleting
that checkout's uncommitted files at exit 0. An ignored nested checkout
is invisible to the dirty gate, and `--force` waives only the target's
own changes. Only `wt merge` refused this (#4360). Planning now refuses
such a target on every removal path:

- `wt remove` fails with a hint to remove the nested worktree first.
- `wt step prune` prints `Skipped <branch> (contains worktree @ <path>)`
and removes the rest.

The guard is `Repository::worktree_nested_in`. It canonicalizes each
registered checkout once per inventory read and answers each target with
one range lookup, so prune adds no per-target path resolution (#3954). A
checkout nested during `wt remove`'s approval prompt or `pre-remove`
hook still isn't caught; only merge rechecks after them.

**Leaving the picker right after alt-x abandoned the removal.** The
process exited with the removal thread still running: the row was gone
but the worktree stayed, and nothing said so. A removal further along
left its checkout in trash. `wt switch` now waits for requested removals
once skim releases the terminal. It prints `Finishing worktree
removal...` while one is still running, then reports any failure.

**A failed promote gave `rm -rf` as the first step for the only copy of
the ignored files.** When a `post-checkout` hook fails `git switch`
after promote has staged ignored files in `.git/wt/staging/promote`, the
error now names that directory. The next run says what `a/` and `b/`
hold, and gives `rm -rf` only as the step after recovering them.

Supersedes #4458 and #4463.

> _This was written by Claude Code on behalf of max-sixty_
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