Skip to content

fix(picker): cap the preview pane at a line count skim can represent - #3959

Merged
max-sixty merged 4 commits into
mainfrom
fix/issue-3958
Aug 30, 2026
Merged

max-sixty merged 4 commits into
mainfrom
fix/issue-3958

Conversation

@worktrunk-bot

@worktrunk-bot worktrunk-bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Collaborator

skim keeps the preview pane's line count in a u16 and unwrap()s the conversion (total_lines in skim 5.6.5's src/tui/preview.rs), so a preview body over 65,535 lines aborts wt with exit 101 instead of rendering. The preview lands asynchronously, so the picker paints normally and dies a few seconds later — on screen it looks like the picker closing by itself, and no diagnostic bundle is written because the process aborts rather than returning an error. A git diff <default>...<branch> on a long-lived branch clears that line count on its own, so any repo with a big enough branch loses wt switch entirely.

This caps every preview body at 60,000 lines in render_preview, the one point all panes converge on before ItemPreview::AnsiText, and prints ○ Preview truncated to 60000 lines above the pane when a body was cut. The cap sits under the ceiling rather than at it because the body isn't the whole pane: the tab bar and the notice ride above it and count toward the same total.

Verified with a unit test in src/commands/picker/items.rs that pushes a 70,000-line body through render_preview: before the change the pane came back 70,003 lines (the count that panics inside skim), after it stays under u16::MAX and carries the notice. The test also pins the two quiet cases — a short body and one exactly at the cap render notice-free.

Notes
  • Reported in wt switch picker panics with exit 101 when a diff preview exceeds 65,535 lines (skim total_lines is u16) #3958 with a clean diagnosis, including the offending skim line and branch line counts (126,021 / 106,009 / 99,758 panic; a repo topping out at 39,547 never does).
  • The reporter's workaround (pager = "delta --paging=never | head -n 20000") works but is per-user and silently caps every preview; this makes the picker survivable by default.
  • Truncating at the render chokepoint rather than in compute_and_page_preview covers the panes that never go through the pager too — the comments thread and a --prs row's forge log.
  • Worth reporting upstream as well: skim-rs/skim could clamp or widen total_lines instead of unwrapping the conversion. The issue author found no existing upstream issue, and I haven't filed one — that's a call for a maintainer.

Closes #3958 — automated triage

skim keeps the preview pane's line count in a u16 and unwraps the
conversion, so handing it a body over 65,535 lines aborts the process
with exit 101. The picker paints first and the preview lands
asynchronously, so it looks like the picker closes by itself a few
seconds after opening. A `git diff <default>...<branch>` on a long-lived
branch clears that line count on its own.

Cap every preview body at 60,000 lines where they converge before skim,
with a notice above the pane when a body was cut.

Closes #3958

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fix looks right, and the cap is at the correct chokepoint — render_preview is the only producer of ItemPreview::AnsiText, so the comments and forge-log panes are covered by the same cut. One thing left over from the first commit.

render_preview_tabs lost its doc comment. MAX_PREVIEW_LINES was inserted directly below the closing line of that function's rustdoc (/// the preview pane width skim reports.) with no blank line between, so Rust reads the two as one block on the constant: render_preview_tabs is now undocumented and MAX_PREVIEW_LINES carries a ~20-line tab-bar spec — the orthogonal number-brightness / label-weight signals, the compact-form width adaptation. render_tab_row_full's see [render_preview_tabs] link now points at an item with no docs. Moving MAX_PREVIEW_LINES and cap_preview_lines above the /// Render the preview tab bar block (or below render_preview_tabs) restores both. It's out of the diff's line range, so no inline suggestion.

While that block is being moved: "the same u16 bounds the pane's scroll offset, so lines past it can't be scrolled to anyway" doesn't justify the number it sits under. Lines 60,001–65,535 are scrollable in skim's u16; the reason for the headroom is the three-line tab bar plus the notice riding above the body, which the clause right after it already says. Worth stating just that, so the next reader changing the constant doesn't work from a constraint that isn't there.

844c784 already resolved the two codecov/patch misses from the first commit (the assert! failure-message arguments, unreachable on a passing run) by hoisting them into lets, and tightened the first assertion to check the head rather than the whole pane. Codecov hasn't re-reported on this head yet — CLAUDE.md → Coverage still applies before merge.

Verification notes
  • Confirmed the premise against skim 5.6.5's own source rather than the issue's diagnosis: Preview::content does self.total_lines = text.lines.len().try_into().unwrap() with text from content.to_owned().into_text()?, and render_text repeats the same try_into().unwrap(). into_text splits on newlines, so the count is logical lines, not wrapped display lines — a logical-line cap is the right lever, and a pane of very long lines can't defeat it.
  • render_preview emits tab bar (3 lines: bar, controls, blank) + notice + body, so the worst case is ~60,004, about 5,500 under the ceiling.
  • Boundary behavior of cap_preview_lines checks out: 59,999 newlines plus an unterminated final line returns whole and notice-free; exactly 60,000 newlines with nothing after takes the keep == body.len() arm; 60,000 newlines plus a trailing fragment truncates and says so. last_newline + 1 is always a char boundary (\n is ASCII), and match_indices(...).nth(59_999) bounds the scan regardless of body size, so the per-repaint cost doesn't grow with the diff.
  • Ran the new test plus cargo clippy --bins --all-features --tests locally — clean.
  • Minor: let mut body = body; in cap_preview_lines can be mut body: String in the signature; both early return (body, None) paths still borrow-check.

Comment thread src/commands/picker/items.rs Resolved
`MAX_PREVIEW_LINES` was inserted directly below the closing line of
`render_preview_tabs`'s rustdoc with no blank line between, so Rust read
the two as one block on the constant: the function lost its docs and the
constant carried the tab-bar spec. Move the constant and
`cap_preview_lines` above that block.

Also drop the scroll-offset clause from the constant's rationale —
lines 60,001..=65,535 are inside skim's `u16`, so the headroom is for the
tab bar and notice riding above the body, which the same sentence
already says.
@max-sixty
max-sixty merged commit be7839f into main Aug 30, 2026
39 checks passed
@max-sixty
max-sixty deleted the fix/issue-3958 branch August 30, 2026 15:04
@max-sixty max-sixty mentioned this pull request Sep 1, 2026
max-sixty added a commit that referenced this pull request Sep 1, 2026
Cuts 0.76.0. `cargo semver-checks` fails ten lints, so the bump is
minor.

## Changelog filing fix

Five entries had been appended to the already-tagged `## 0.75.0` section
after v0.75.0 shipped (#3977/#2860, #3949 ×2, #3959, #3945). They
describe changes that ship *here*, and GitHub's 0.75.0 release notes —
built from the tag — never showed them. They are moved into `## 0.76.0`
and rewritten to the length ceiling; `## 0.75.0` is restored
byte-identical to `git show v0.75.0:CHANGELOG.md`.

The mechanism is systemic: a PR appends under whatever heading is
currently top, so every post-release PR lands in the shipped section
until the next release opens a new one.

## `--execute` template guidance

`#3977` switched `--execute` expansion to `ShellEscapeMode::Literal`,
which is correct for an argv model. But the migration that
v0.53.0–v0.75.0's deprecation warning *printed* — `-x sh -- -c '<old
body>'` — splices a template variable into text `sh` re-parses, so a
value with spaces word-splits where the old POSIX-escaped model kept it
intact. Worst case is `rm -rf` against unintended paths.

`--execute`'s help now documents passing the variable as a separate
argument and referencing it positionally. `extending.md` already
modelled that form, so no recipe changed.

## Validation

- `nightly` on the cut-from tip (`baf161bf6`): all 14 jobs green — [run
33538866753](https://github.com/max-sixty/worktrunk/actions/runs/33538866753)
- `wt hook pre-merge --yes`: 4713 passed
- Data-loss surface reviewed across the 45-commit diff by four
independent finders; adjudication in the release thread. No new
destructive path — `#3977` removes one, deleting the EXEC directive file
from all five shell wrappers.

> _This was written by Claude Code on behalf of max-sixty_
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
worktrunk 0.76.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

- **`wt switch --execute` takes a program, not a shell string**: `-x` names one program, with everything after `--` passed as literal argv. Worktrunk spawns it as a child rather than running it in your interactive shell, so shell functions and its `cd` no longer reach you. `-x sh -- -c '…'` recovers shell syntax, not functions. (Breaking: existing `-x` strings, plus `WORKTRUNK_DIRECTIVE_EXEC_FILE` and `WORKTRUNK_SHELL`.) ([#3977](max-sixty/worktrunk#3977), closes [#2860](max-sixty/worktrunk#2860), fixes [#3944](max-sixty/worktrunk#3944), thanks @omgreenfield for testing the migration path)

- **Worktrunk decides tracking for the branches it creates**: a new branch gets an upstream only when its name matches the remote branch it starts from, whatever `branch.autoSetupMerge` says: `--create release --base origin/release` tracks, `--create feature --base origin/release` does not. Under `autoSetupMerge = false` this previously exited 128 after creating the worktree. ([#3913](max-sixty/worktrunk#3913), [#3950](max-sixty/worktrunk#3950), fixes [#3937](max-sixty/worktrunk#3937), thanks @mjakl for reporting and diagnosing)

- **Retired config keys are no longer read**: `commit.generation.template-file` and `squash-template-file` are gone — put the file's contents in `template` or `squash-template`. There is no migration: the key stays, warns as unknown on every load, and the prompt reverts to the built-in default. Setting both `template` and `template-file` used to fail the load; it now loads `template`. `switch.picker.timeout-ms` likewise warns rather than being stripped. (Breaking.) ([#3949](max-sixty/worktrunk#3949))

- **Project aliases and hooks can use `wt switch --execute`**: their bodies previously refused it. Worktrunk now starts the program itself instead of handing shell text to your shell, and the command-approval gate remains the control on project-defined commands. ([#3977](max-sixty/worktrunk#3977))

- **Established automation and LLM customization interfaces are now stable**: `wt step eval`, `wt step for-each`, `wt step prune`, LLM branch summaries, `wt config state vars`, and `commit.generation.template-append` are no longer marked experimental. ([#3949](max-sixty/worktrunk#3949))

- **`wt step prune` stages removals concurrently again**: only the `git worktree remove` teardowns serialize, so dirty checks, fsmonitor shutdown, and the trash rename overlap. The `prune_e2e/live` benchmark median went from 377 ms to 222 ms. ([#3954](max-sixty/worktrunk#3954))

- **`wt config approvals add` reads as a review rather than a warning**: it opens with a cyan `Review 1 command for repo:` instead of a yellow `▲ … needs approval to execute`. The execution-time gate is unchanged. ([#3953](max-sixty/worktrunk#3953))

### Fixed

- **The `wt switch` picker survives a preview longer than 65,535 lines**: skim keeps the pane's line count in a `u16`, so a larger diff aborted `wt` with exit 101 seconds after it painted — on screen the picker looked like it closed by itself. Panes now cap at 60,000 lines and say so. ([#3959](max-sixty/worktrunk#3959), fixes [#3958](max-sixty/worktrunk#3958), thanks @sandertammesoo for reporting and diagnosing)

- **The nushell wrapper propagates exit codes without a POSIX shell**: it reported a failing `wt` by spawning `sh`, so on Windows every failing command printed a ``Command `sh` not found`` trace and exit 1 whatever the real code was. Nushell's wrapper is a static file, so rerun `wt config shell install` to pick this up. ([#3945](max-sixty/worktrunk#3945))

- **The picker no longer shows one detached worktree's diff for another**: previews were keyed by branch name, so every detached row shared the key `(detached)`. Rows now key by canonical identity, which also lets `wt remove feature ~/repo.feature` plan that worktree once instead of failing on the second. ([#3926](max-sixty/worktrunk#3926))

- **`wt switch pr:<n>` gives `pre-switch` hooks the real branch**: `branch` and `target` held the literal `pr:3933`, and `target_worktree_path` was unset even when that branch had a worktree. `pr_number` and `pr_url` are now set for same-repo PRs, not only forks. ([#3941](max-sixty/worktrunk#3941), fixes [#3934](max-sixty/worktrunk#3934), thanks @robsonpeixoto for reporting)

- **`wt config shell install` no longer replaces an rc file created while it was checking**: the missing-file path refuses to clobber and fails with a rerun hint. A dangling rc symlink is preserved and rejected rather than overwritten. ([#3929](max-sixty/worktrunk#3929))

- **`wt switch --create X --base pr:<n>` works when the PR branch has no local branch**: the fetch writes only the remote-tracking ref, and git won't expand a bare name to one, so the command failed with `No branch, tag, or commit named …`. The base is now named under its remote. ([#3951](max-sixty/worktrunk#3951))

- **`wt switch --create` streams `git worktree add` instead of stalling**: where a sandbox denied the timed wait's pipe or `sigaction`, the command waited out git's entire run and then reported `Failed to wait for command` for work that had already succeeded. ([#3881](max-sixty/worktrunk#3881))

- **Claude Code activity markers stay on the session's launch worktree**: the plugin's marker hooks pass `-C "$CLAUDE_PROJECT_DIR"`, so a `cd` mid-session no longer marks another repository. A session launched outside a repository gets no marker. ([#3956](max-sixty/worktrunk#3956))

### Documentation

- **`--execute` documents how to get a variable into a shell body**: each position is substituted verbatim, so a variable spliced into `sh -c` text is re-parsed by that shell and splits on spaces. The help now shows passing it as a separate argument and referencing it positionally. ([#3977](max-sixty/worktrunk#3977))

- **The clone-local default-branch override is documented**: `wt config state default-branch set` writes `worktrunk.default-branch` to the clone's local git config — machine-local, never committed, and shared by every linked worktree. `set` warns when the branch isn't checked out locally, and `wt list` skips its comparisons until it is. ([#3947](max-sixty/worktrunk#3947), [#3948](max-sixty/worktrunk#3948), fixes [#3946](max-sixty/worktrunk#3946), thanks @danielo515 for the request)

- **The docs site renders code with the CLI's own colors**: terminal examples reproduce each snapshot's exact ANSI roles, while command references and the homepage command comparison get clap and shell syntax color from paired light/dark themes. File excerpts gain a path tab, and code wraps instead of scrolling on mobile. ([#3936](max-sixty/worktrunk#3936), [#3938](max-sixty/worktrunk#3938), [#3939](max-sixty/worktrunk#3939), [#3942](max-sixty/worktrunk#3942))

- **The `pre-start` upstream example uses `--base`**: it showed `wt switch --create feature origin/feature`, which `wt switch` rejects. ([#3955](max-sixty/worktrunk#3955))

### Internal

- **Library API rework** (Breaking library API): `cargo-semver-checks` fails ten lints — `RemoteRefProvider` and its provider structs give way to `ForgeKind` dispatch, the `--execute` rework retires the fish and PowerShell `ShellEscapeMode` escapes and `WORKTRUNK_SHELL_ENV_VAR`, `BranchRef` swaps `full_ref`/`worktree_path` for `id`, and accessors including `Branch::unset_upstream` and `ProjectConfig::ci_platform` are gone. ([#3913](max-sixty/worktrunk#3913), [#3926](max-sixty/worktrunk#3926), [#3949](max-sixty/worktrunk#3949), [#3963](max-sixty/worktrunk#3963), [#3977](max-sixty/worktrunk#3977))

- **Hook pipelines and `wt list` collection lost two indirection layers**: the background pipeline carries `PreparedStep` directly, and 15 marker task types collapse into one exhaustive dispatch. The synthesized-`--force` submodule path keeps its dirty re-check and destructive command under one lock, so prune's narrower locking doesn't widen that window. ([#3964](max-sixty/worktrunk#3964), [#3954](max-sixty/worktrunk#3954))

## Install worktrunk 0.76.0

### Install prebuilt binaries via shell script

```sh
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/max-sixty/worktrunk/releases/download/v0.76.0/worktrunk-installer.sh | sh && wt config shell install
```

### Install prebuilt binaries via powershell script

```sh
powershell -ExecutionPolicy Bypass -c "irm https://github.com/max-sixty/worktrunk/releases/download/v0.76.0/worktrunk-installer.ps1 | iex"; git-wt config shell install
```

### Install prebuilt binaries via Homebrew

```sh
brew install worktrunk && wt config shell install
```

## Download worktrunk 0.76.0

|  File  | Platform | Checksum |
|--------|----------|----------|
| [worktrunk-aarch64-apple-darwin.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.76.0/worktrunk-aarch64-apple-darwin.tar.xz) | Apple Silicon macOS | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.76.0/worktrunk-aarch64-apple-darwin.tar.xz.sha256) |
| [worktrunk-x86_64-ap

See merge request: Harmonybrew/homebrew-core!18482
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automated-fix Automated CI fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wt switch picker panics with exit 101 when a diff preview exceeds 65,535 lines (skim total_lines is u16)

2 participants