Repository navigation
fix: route all background hooks through pipeline-aware API - #1910
Merged
Merged
Conversation
Three bugs fixed: - Post-merge and post-remove hooks bypassed the pipeline path, losing serial/concurrent semantics for list-form configs. Now all callers use prepare_background_hooks/spawn_prepared_hooks. - Pipeline context leaked per-step hook_name to all steps. The shared context now strips hook_name; the background runner injects it per-step. - Name-filtered pipeline commands in the flat spawn path passed raw unexpanded templates to the shell. spawn_background_hooks now expands lazy templates before detaching. Also extracts PostRemoveContext struct (replaces prepare_post_remove_commands), adds expand_lazy_template helper, and stops merging pipeline steps from different hook types into one pipeline in handle_switch.rs. Co-Authored-By: Claude <[email protected]>
# Conflicts: # src/commands/handle_switch.rs # tests/integration_tests/user_hooks.rs
- Simplify run_post_hook to use prepare_background_hooks/spawn_prepared_hooks for non-name-filtered background hooks, eliminating manual pipeline detection - Make prepare_pipeline_hooks_with_configs private (only used internally now) - Add post-remove pipeline serial ordering test - Add name-filtered lazy template expansion test Co-Authored-By: Claude <[email protected]>
worktrunk-bot
approved these changes
Apr 4, 2026
max-sixty
pushed a commit
that referenced
this pull request
Apr 4, 2026
## Problem CI on `main` failed on Windows with a stack overflow in `test_copy_ignored_many_directories_no_emfile`: ``` thread '<unknown>' (2316) has overflowed its stack ``` The rayon worker in the copy thread pool inherits the platform default stack size. On Linux/macOS this is ~8 MiB, but on Windows it is only ~2 MiB, which is not enough for concurrent `reflink_or_copy` work over 200 directories of ignored files. The failing run (23987711021) sits on a commit (#1910) that doesn't touch the copy path — this is a latent Windows-specific issue in the dedicated copy pool introduced in #1905. ## Solution Set an explicit 8 MiB `stack_size` on `COPY_POOL` so behaviour is consistent across platforms. This matches the Unix default and is a narrow, targeted fix at the place the problem is — the rayon pool used exclusively for `copy_dir_recursive`. ## Testing - `cargo test --test integration test_copy_ignored_many_directories_no_emfile` passes locally (Linux). - Full Windows CI re-run will exercise the large-scale concurrent copy path. --- Automated fix for [failed run](https://github.com/max-sixty/worktrunk/actions/runs/23987711021) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: worktrunk-bot <[email protected]> Co-authored-by: Claude <[email protected]>
max-sixty
added a commit
that referenced
this pull request
Jun 11, 2026
…#3042) Hook templates expanded eagerly at prep time unless they referenced `vars.*` (#1840); aliases were unconditionally lazy. The dual representation (`expanded` + `lazy_template` on `PreparedCommand`) put a mode choice in front of every consumer, and the seams produced real bugs (#1855, #1910). The background runner also re-rendered eagerly-expanded strings: a latent double-expansion whenever expansion output contained `{{`. This PR unifies on one rule: syntax is validated at preparation (before step 1), templates render when each step runs, and `vars.*` always reads fresh from git config. This is the direction #2128 recorded ("treat hooks as aliases bound to triggers"). **Navigating the diff:** - `src/commands/command_executor.rs`: `PreparedCommand` now carries the raw template plus the frozen context map; JSON is produced only at the process boundary. A `template_name` field keeps the moved errors' text identical to the old prep-time messages. `prepare_steps` validates syntax and freezes context; `resolve_command_str` renders at execution; `map_config_steps` is the structural walker shared with aliases. - `src/commands/alias.rs`: alias prep shares the walker. The residual fork is genuinely alias-specific: context construction (filtered to referenced vars, `{{ args }}` injection) and labels. A prep-time syntax check turned out to be dead code (the arg-routing parse already aborts on syntax errors), so `referenced_vars_for_config` now produces the rich `TemplateExpandError` instead. - `src/commands/hooks.rs`: the background spec always ships raw templates; the runner renders each step (it already did for vars steps). - Dry-run paths (`wt hook --dry-run`, `wt config alias dry-run`) share `render_template_preview`: vars-referencing templates shown raw after a syntax check, everything else rendered at display time. **Behavior changes** (each pinned by a test or snapshot): 1. A foreground pipeline whose step N has a semantic template error (undefined variable) runs steps 1..N-1 before failing, matching what vars-referencing steps already did. New test: `test_foreground_pipeline_undefined_var_runs_earlier_steps`. 2. A semantic error in a background hook template no longer fails the foreground command; it surfaces in the runner log. Syntax errors still abort at prep. New test: `test_background_hook_undefined_var_fails_in_runner`; `test_merge_drops_pending_hooks_when_post_merge_fails` switched to a syntax-error fixture since that is what now reaches its subject (the announcer Drop-flush). 3. `-v` no longer prints the parent-side rendered command for background hooks (rendering happens in the runner). The variables table remains and `wt hook <type> --dry-run` previews commands; help text updated. Three snapshots changed by exactly this. 4. Announce gutters for vars-referencing foreground steps show the rendered command instead of the raw template. 5. Syntax errors caught by the arg-routing parse (aliases, `wt hook` `--KEY=VALUE` routing) render as the rich template error with the source-line gutter, naming the alias or hook. `ApprovedHookPlan` freezing, approval semantics (keyed and displayed by template), config file format, and CLI flags are unchanged. **Testing:** full local gate green (3917 tests + lints). The deferral semantics in changes 1 and 2 previously had no coverage; both are now pinned. > _This was written by Claude Code on behalf of max_ Co-authored-by: Claude Fable 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three bugs in the background hooks system, found by Codex review:
Post-merge and post-remove bypassed the pipeline path.
merge.rscalledprepare_hook_commands+spawn_background_hooksdirectly, andprepare_post_remove_commandsreturned flatVec<SourcedCommand>. List-form configs lost serial/concurrent semantics — commands raced instead of running in order.Pipeline context leaked per-step
hook_name.spawn_hook_pipelinedeserialized the first command'scontext_jsonas the shared pipeline context, which includedhook_name. Later steps saw step 1's name instead of their own. Additionally,handle_switch.rsmerged PostSwitch and PostStart pipeline steps into one pipeline, giving PostStart steps the wronghook_type.Lazy template expansion broken in flat spawn path. When name-filtering pipeline commands via
wt hook post-start db,run_post_hookfell through tospawn_background_hooks, which passed the raw{{ vars.name }}template to the shell instead of expanding it.Fixes:
prepare_background_hooks/spawn_prepared_hooks, which auto-detects pipeline vs flat configshook_name; the background runner injects it per-step viabuild_step_context_jsonspawn_background_hooksexpands lazy templates before detaching (sharedexpand_lazy_templatehelper)handle_switch.rsspawns each hook type's pipeline independentlyprepare_post_remove_commandsreplaced byPostRemoveContextstruct + unified APIrun_post_hooksimplified to use unified API (removes manual pipeline detection)prepare_pipeline_hooks_with_configsmade private (only used byprepare_background_hooks)4 regression tests: pipeline
hook_nameisolation, post-merge pipeline ordering, post-remove pipeline ordering, name-filtered lazy template expansion.