Skip to content

fix(config): treat empty hook table as no steps - #2635

Merged
max-sixty merged 1 commit into
mainfrom
fix/issue-2634
May 7, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix/issue-2634

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Problem

An empty hook table — header retained but every command commented out — caused wt switch --create to panic with index out of bounds: the len is 0 but the index is 0 in src/commands/hooks.rs whenever another background hook was configured. This is easy to hit by temporarily commenting out a [post-switch] body while keeping the header, as long as another background hook (for example [post-start]) is present.

[post-switch]
# vscode = "code ."   # all commented out → empty table

[post-start]
copy = "wt step copy-ignored"
thread 'main' panicked at src/commands/hooks.rs:442:52:
index out of bounds: the len is 0 but the index is 0

The verbose path panicked at print_background_variable_table (hooks.rs:442); the non-verbose path panicked at spawn_hook_pipeline_quiet (hooks.rs:475). Reported in #2634 with a full source-level analysis from the reporter.

Root cause

In CommandConfig's visit_map, an empty TOML table produced steps: vec![HookStep::Concurrent(vec![])] — one step containing zero commands. The downstream filter in run_hooks_background only checks !steps.is_empty(), so the pipeline survived the filter and reached call sites that index cmds[0].

visit_seq already handles the analogous case for inline tables inside a pipeline list (it skips empty maps with continue). visit_map was inconsistent.

Solution

Mirror visit_seq's behavior in visit_map: when the map is empty, return zero steps instead of one empty Concurrent. This is the most localized fix — the empty Concurrent(vec![]) is never produced, so every downstream consumer is correct without further changes.

Testing

Added test_deserialize_empty_named_table in src/config/commands.rs, which fails on main (asserts steps.len() == 0 but gets 1) and passes with the fix.

Verified end-to-end with the reporter's reproduction script — both verbose and non-verbose wt switch --create paths complete without panicking, and the configured [post-start] hook still runs.


Closes #2634 — automated triage

An empty hook table such as `[post-switch]` (header retained, all
commands commented out) deserialized to a single `HookStep::Concurrent`
with an empty command vector. The downstream filter in
`run_hooks_background` only skips empty `steps` vectors, so this
pipeline reached `print_background_variable_table` /
`spawn_hook_pipeline_quiet`, which both index the first command and
panicked with "index out of bounds: the len is 0 but the index is 0".

Mirror `visit_seq`'s existing behavior for empty inline tables and
return zero steps when the map is empty.

Closes #2634

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit a600d8b into main May 7, 2026
25 checks passed
@max-sixty
max-sixty deleted the fix/issue-2634 branch May 7, 2026 08:07
@max-sixty max-sixty mentioned this pull request May 10, 2026
3 tasks done
max-sixty added a commit that referenced this pull request May 10, 2026
Bump worktrunk to **0.49.0** — minor bump (semver-checks reports a
breaking change in `GitError::UncommittedChanges`, which gained a
`dirty_files: Vec<String>` field).

## Highlights

**Improved**
- New `codename(n)` template filter — deterministic friendly worktree
names from a ~1.26M-combo pool (`{{ branch | codename(2) }}` →
`malleable-opah`).
[#2641](#2641), thanks
@endigma
- Picker preview disk cache for Log / BranchDiff / UpstreamDiff, with
background refresh for stale Log decorations.
[#2628](#2628),
[#2646](#2646)
- Picker shares one `default_branch_sha` lookup across BranchDiff items
instead of forking N rev-parse subprocesses.
[#2658](#2658)
- "X has uncommitted changes" errors now list the dirty files inline.
[#2653](#2653)

**Fixed**
- `wt switch` integrates with `cd` aliases like zoxide (uses `builtin
cd`). [#2644](#2644), thanks
@xkumiyu for reporting
- Empty hook tables no longer panic during `wt switch --create`.
[#2635](#2635), thanks @topit
for reporting
- `Repository::current_worktree()` and five sibling helpers no longer
silently leak the process CWD when called via `Repository::at(p)`.
[#2652](#2652)
- `WorkingTree::is_linked` tolerates non-git CWDs (e.g. Nix sandbox).
[#2625](#2625), thanks
@DArtagan for reporting
- Picker no longer overlays `collect` warnings on the active TUI; clears
its frame on exit in inline mode.
[#2627](#2627),
[#2626](#2626)
- Failed `git log` no longer poisons the picker's preview disk cache.
[#2651](#2651)
- `wt step prune` says "removing branch" for branch-only candidates.
[#2619](#2619)
- Claude Code Windows integration uses a `wt.sh` wrapper to avoid
colliding with Windows Terminal's `wt.exe`.
[#1754](#1754), thanks
@lucaspimentel

**Documentation**
- cmux workspace integration recipe.
[#1907](#1907), thanks
@alvistar

See
[CHANGELOG.md](https://github.com/max-sixty/worktrunk/blob/release/CHANGELOG.md)
for the full list including internal CI / test-isolation changes.

## Test plan

- [x] `cargo run -- hook pre-merge --yes` (tests + lints clean)
- [x] `cargo semver-checks check-release -p worktrunk` (one breaking
change confirmed → minor bump)
- [x] CHANGELOG entries verified by subagent against actual diffs

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.

Empty hook table causes panic in wt switch --create background HookAnnouncer path

2 participants