Skip to content

fix(switch): repaint the picker preview after the alt-r sticky reposition - #3225

Merged
max-sixty merged 1 commit into
mainfrom
fix-picker-pty-flake
Jun 25, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix-picker-pty-flake

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

What

Two linked fixes around the alt-r "remove worktree" path in the interactive picker:

  1. Picker (behavior): the preview pane now repaints after the alt-r sticky reposition, so it tracks the cursor.
  2. Test (robustness): test_switch_picker_alt_r_keeps_cursor_sticky no longer races the preview pane.

The race

When alt-r removes a worktree, skim resets the cursor to the top on reload, and an injected Custom action repositions it onto the row that slides into the removed slot — that part works. But skim only re-runs the preview on a selection-change event (on_selection_changed → Event::RunPreview). Moving the cursor through the ItemList API inside that Custom action is not such an event, so skim kept showing the row it last previewed — the current worktree, which the reload had briefly reset the cursor to. The preview pane went stale until the next keystroke.

The flaky test asserted cursor position by reading that preview pane, so under load it timed out (~10%) waiting for "<sticky-row> has no uncommitted changes" text that the stale pane never showed — even though the cursor had landed correctly. Captured failure (note the > pointer is on wt-keep, but the pane shows main):

  @ main         ^                  │
> + wt-keep      _                  │○ main has no uncommitted changes

The fix

  • reposition_cursor_action returns Event::RunPreview once it lands the cursor, so the preview repaints for the sticky row — the same idiom the preview-tab keybindings already use. This fixes the real (if minor) UX papercut where the preview lagged the cursor after a removal.
  • drive_alt_r_then_switch gates on the list-pane cursor pointer (> on the target row) rather than the preview pane. The pointer is drawn on every item-list render, so it is a race-free signal of cursor position — which is exactly what this test verifies. New wait_for_cursor_on_row helper, built on a refactored predicate-based wait_for_stable_until that wait_for_stable_with_content now also delegates to.

The two fixes are independent: the test gates on the cursor, not the preview, so it is robust whether or not the picker repaints.

Sibling scan

switch_picker.rs is the only file with interactive picker screen-waits. The preview-panel and tab-cycle tests gate on preview content reached by key navigation (Down / alt-N / Tab), which does fire RunPreview, and the preview content is their actual subject — they don't share this flaw. The query-based proxy tests (emits_cd_directive, no_cd, pre_switch_hook) have a separate documented matcher-lag rationale. Only the alt-r Custom-action reposition had no preview refresh; the picker fix structurally protects any future alt-r-then-preview observation.

Validation

Reproduced the flake under load (~3/20 fail before). After the fix:

  • Test fix alone (no picker change): robust across many runs under heavy load.
  • Picker fix verified causally — with a strict preview-content gate the preview reliably tracks the cursor with the fix, and reverting only the picker fix reintroduces preview-gate timeouts. So the picker fix is what makes the preview follow the cursor.
  • Full gate (cargo run -- hook pre-merge --yes, includes --features shell-integration-tests): 4187 passed, all lints green, no snapshot changes.

This was written by Claude Code on behalf of max

…tion

After alt-r removes a worktree, the cursor sticks to the row that slides up,
but the preview pane kept showing the row skim last previewed — the current
worktree, which the reload briefly reset the cursor to. skim re-runs the
preview only on a selection-*change* event; moving the cursor through the
ItemList API inside the reposition Custom action isn't one, so the pane went
stale until the next keystroke. The reposition action now returns
Event::RunPreview on landing, so the preview tracks the cursor — mirroring the
preview-tab keybindings.

This also fixes the flaky test_switch_picker_alt_r_keeps_cursor_sticky, which
timed out (~10% under load) waiting for the sticky row's preview text that the
stale pane never showed — the cursor itself landed correctly the whole time.
The test now gates on the list-pane cursor pointer (drawn on every render, so
race-free) instead of the async preview pane, via a new wait_for_cursor_on_row
helper built on a refactored wait_for_stable_until.

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

Copy link
Copy Markdown
Collaborator

Heads up that codecov/patch went red after I approved, but it looks like a false positive — no real coverage gap to address, so I've left the approval in place. Your call on the merge gate.

The only line codecov counts as a patch miss is a doc-comment line, not executable code. The behavioral change itself (return Ok(vec![Event::RunPreview]);) is covered.

Evidence (Codecov compare API, pullid 3225)

Per-line patch state for src/commands/picker/mod.rs (coverage.head: 0=hit, 1=miss, null=non-executable):

426  miss  +/// On landing, it returns [`Event::RunPreview`] so the preview pane repaints for
427  hit   +/// the row the cursor settled on. skim only repaints the preview on a
...
445  hit   +                return Ok(vec![Event::RunPreview]);

The single miss is line 426 — a /// doc comment. The functional line 445 is a hit. Codecov's patch summary for the file is 11/12 lines (91.66%), and the one "uncovered" line is that comment.

Codecov is also including the .last_match(true) / .tiebreak([Score, PathName, …]) block (codecov lines ~830–860) in the patch, but that already exists on origin/main and isn't part of this PR — gh pr view --json files lists only src/commands/picker/mod.rs and tests/integration_tests/switch_picker.rs. So the compare is aligning against a stale base and pulling in pre-existing code.

Net: the only patch "miss" is a documentation comment, which no test can cover.

@max-sixty

Copy link
Copy Markdown
Owner Author

Note on the red codecov/patch

The one uncovered patch line is the picker fix itself:

return Ok(vec![Event::RunPreview]);   // the alt-r reposition "landing" branch

This is a pre-existing, structural coverage gap, not a regression. On main the entire reposition landing branch (count() > 0, jump_to_first, scroll_by, and the prior Ok(Vec::new())) is already uncovered (base=0 in the codecov compare API) — the branch runs inside skim's tokio event-loop Custom callback, which the PTY test exercises but LLVM coverage doesn't capture in the wt subprocess (the instrumented binary doesn't flush counters before the test reclaims the child). Editing the line simply moved it into the patch denominator.

It can't be covered by an in-process unit test either: skim's ActionCallback::call is pub(crate), and App / item_list can't be populated from outside the crate, so the callback body isn't drivable from a test.

The branch is exercised end-to-end by test_switch_picker_alt_r_keeps_cursor_sticky (which now gates on the cursor pointer and is green on all three test platforms). Merging with this codecov/patch miss accepted.

This was written by Claude Code on behalf of max

@max-sixty
max-sixty merged commit 84efcb3 into main Jun 25, 2026
35 of 36 checks passed
@max-sixty
max-sixty deleted the fix-picker-pty-flake branch June 25, 2026 04:52
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
worktrunk 0.62.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## Release Notes

### Improved

- **Browse open PRs/MRs in the `wt switch` picker, with live CI**: The picker now streams a live CI/review-status column per row — priming from the local cache, then fetching live (it previously showed only cached numbers with no network). A new `--prs` flag adds the repository's open PRs (GitHub) / MRs (GitLab) as rows alongside your worktrees, each with `pr` / `comments` / `log` preview tabs loaded from the forge in the background; selecting one fetches its branch and switches. Rows whose branch is already shown aren't duplicated, so `--prs` differs from plain `wt switch` only by the extra rows. [Docs](https://worktrunk.dev/switch/) ([#3128](max-sixty/worktrunk#3128), [#3169](max-sixty/worktrunk#3169), [#3189](max-sixty/worktrunk#3189), [#3252](max-sixty/worktrunk#3252))

- **`main…±` diff column shows by default in `wt list`**: The `main…±` column (lines changed since the merge-base with the default branch) now renders in the default `wt list` and picker, served from a persistent cache rather than a history walk. `--full` now adds only the columns that reach off-machine — CI status and LLM branch summaries — and `wt list --format=json` populates `main.diff` for every item, not just under `--full`. ([#3236](max-sixty/worktrunk#3236))

- **`[list] columns` selects and orders the columns `wt list` shows**: A new `[list] columns` user-config key (also settable via `--config-set`) takes an ordered array of column names — built-in (`branch`, `status`, `ci`, `path`, …) and `[list.custom-columns]` headers alike — and renders exactly those, in that order. Where v0.61.0's custom columns *add* columns, this *selects and reorders* the whole set; omit the key for the default layout. (`WORKTRUNK__LIST__COLUMNS` isn't supported yet and warns if set.) ([#3141](max-sixty/worktrunk#3141))

- **Picker PR preview shows full PR/MR detail**: The `pr` tab now renders the PR/MR title, markdown description, author, draft state, comment count, bold branch name, and underlined URL for any row whose branch has an open PR — not just `--prs` rows — and the `comments` tab fetches the real thread. The title and description ride the CI fetch the picker already makes; the comment thread is fetched lazily in the background, once per row. ([#3167](max-sixty/worktrunk#3167), [#3197](max-sixty/worktrunk#3197), [#3223](max-sixty/worktrunk#3223), [#3195](max-sixty/worktrunk#3195), [#3231](max-sixty/worktrunk#3231))

- **Interactive picker runs on Windows**: The `wt switch` picker was Unix-only because its preview-tab keys shelled out through a per-process state file `cmd.exe` lacks; tab state moved to an in-memory atomic with native skim callbacks, lifting the platform gate. ([#3217](max-sixty/worktrunk#3217))

- **Picker keyboard shortcuts**: `Alt-y` copies the selected branch name, `Alt-o` opens the row's PR/MR in the browser, and `Alt-r` refreshes the list (picking up worktrees created or removed elsewhere). (Breaking: in the picker, remove moved from `Alt-r` to `Alt-x`) ([#3233](max-sixty/worktrunk#3233))

- **Picker uses the full terminal**: List height scales with the terminal (a roughly even split with the preview, minimum 3 rows) instead of a fixed 12-row cap, the table lays out at full width so toggling the preview off with `Alt-p` reveals the freed columns with no reflow, and a scrollbar appears when the list overflows. ([#3205](max-sixty/worktrunk#3205), [#3214](max-sixty/worktrunk#3214), [#3198](max-sixty/worktrunk#3198))

- **Picker filters on more of each row**: Typing a gutter sigil filters by row kind (`+` for linked worktrees, `@` for the current one), the fuzzy matcher ranks on the distinguishing path segment rather than the shared parent prefix, and rows with a PR/MR also match on its number, title, and author. ([#3143](max-sixty/worktrunk#3143), [#3208](max-sixty/worktrunk#3208), [#3252](max-sixty/worktrunk#3252))

- **Picker visual polish**: The legend recolored to dim-cyan and reordered so navigation leads, and preview loading placeholders moved to the dim-hint style (`↳` transient, `○` settled, `▲` failed). ([#3237](max-sixty/worktrunk#3237), [#3253](max-sixty/worktrunk#3253))

- **"Still waiting" status for slow commit-message generation**: A configured `commit.generation` command captures stdout, so a slow or hung LLM previously showed nothing while `wt step commit`/`squash` waited. After a 2s delay worktrunk now shows a dim, in-place `○ Waiting for the commit message (Ns)` status, escalating at 10s to reveal the exact shell-escaped invocation in a gutter beneath it; the block clears on completion, mirroring `wt list`'s stall footer. ([#3178](max-sixty/worktrunk#3178))

- **"Still waiting" status extended to more slow commands**: The same waiting status now covers three more foreground commands that were silent while a captured subprocess ran — the `wt config show --full` commit-generation self-test, the `wt switch pr:`/`mr:` host lookup, and the `wt config show --full` version check. The version check no longer caps its fetch at an aggressive 5s, instead showing the status while a slow-but-working request completes (with a generous ceiling so a non-interactive run can't hang). ([#3183](max-sixty/worktrunk#3183))

- **`wt config state logs profile` performance profiler**: A new subcommand turns a `-vv` `[wt-trace]` capture (a path argument, `-` for stdin, or the default `trace.log`) into a performance profile: subprocess time by command shape, the slowest calls, parallelism and peak concurrency, redundant cache-miss re-runs, and — for `wt list`/picker captures — derived latencies and a collect timeline. `--format=json` emits the same data, and every `-vv` bug-report bundle now inlines a rendered profile. ([#3184](max-sixty/worktrunk#3184), [#3186](max-sixty/worktrunk#3186))

- **`WORKTRUNK_VERBOSE` env var**: `WORKTRUNK_VERBOSE=0|1|2` mirrors `-v`/`-vv`, combined with any flag via `max` (the env sets a floor the flag can raise). Unlike the flags it's honored on the shell-completion path, which returns before flag parsing — so a slow tab-completion can be profiled for the first time. ([#3166](max-sixty/worktrunk#3166))

- **Aliases inherit the wrapped command's completion**: An alias that forwards `{{ args }}` to a single `wt` command (`co = "wt switch {{ args }}"`) now completes that command's arguments and flags — `wt co <Tab>` completes branches like `wt switch <Tab>` — instead of a generic stub. Bare dispatchers and multi-`{{ args }}` aliases keep the stub. ([#3172](max-sixty/worktrunk#3172), thanks @yzx9)

- **`wt step copy-ignored --require-include`**: A new `--require-include` flag makes the copy a no-op unless a `.worktreeinclude` file exists in the source worktree (matching Claude Code desktop, where that file is required), reporting why it skipped as a hint in text mode and a `reason` field in `--format=json`. ([#3196](max-sixty/worktrunk#3196), thanks @yzx9)

- **`wt step tether` honors `-C`**: The global `-C <path>` flag now sets the tethered command's working directory (`wt step tether -C frontend -- npm run dev`); teardown still watches the worktree root, so the command is reaped when the worktree is removed. ([#3207](max-sixty/worktrunk#3207))

- **Statusline rate-limit pace color grades by severity**: The pace segment's color now deepens (dim → dim-yellow → yellow) with the projected throttling severity, so an early-window burst stays muted while a costly projected lockout stands out. The displayed pace number is unchanged. ([#3229](max-sixty/worktrunk#3229))

### Fixed

- **Picker `Alt-x` removal updates the row in place**: Removing a worktree no longer re-collects the whole list (a flicker that reset the cursor to the top): an unmerged worktree's row morphs into a branch-only row while the worktree is removed in the background, and a merged worktree's row drops with the cursor landing on the row that slid up. A removal that can't safely happen — the current or main worktree, or a dirty or locked one — is declined with the same diagnostic `wt remove` prints, rather than a dead keypress or a disruptive `cd` home. The post-removal cursor lands by row identity, so it stays correct even under an active filter. ([#3262](max-sixty/worktrunk#3262), [#3199](max-sixty/worktrunk#3199), [#3211](max-sixty/worktrunk#3211), [#3225](max-sixty/worktrunk#3225))

- **Picker preview refreshes when its background fetch lands**: A diff/log/PR-view fetch that completed after its triggering keystroke used to sit unshown until the next keypress; the pane now updates on its own when the fetch lands. ([#3247](max-sixty/worktrunk#3247))

- **Picker rows stay aligned while filtering**: Typing a filter no longer slides the matched row left and drops its leading sigil, and `Alt-l`/`Alt-h` no longer scroll the list off its gutter. ([#3213](max-sixty/worktrunk#3213), [#3226](max-sixty/worktrunk#3226))

- **fish completions no longer recurse to the call-stack limit**: With worktrunk's fish lazy-load wrapper installed, co

See merge request: Harmonybrew/homebrew-core!12862
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