copy-ignored fails silently with very large trees
I noticed today that I was not getting node_modules copied over correctly when creating new worktrees.
My ~/.config/worktrunk/config.toml only contains the following at the end of the default file:
[post-start]
copy = "wt step copy-ignored"
When I ran wt switch --create, I got what appeared to be a correct worktree and no error messages, but some of my npm packages were not there. These are not git-controlled files.
Next, I ran wt hook post-start -v to debug and got:
$ wt hook post-start -v
○ Expanding user:copy
wt step copy-ignored
→
wt step copy-ignored
◎ Running post-start user:copy
wt step copy-ignored
Nothing obviously wrong there. Then I ran wt step copy-ignored -v:
$ wt step copy-ignored -v
○ Copying 2628 entries:
.env (file)
<snip>
tmp/storage/zw (dir)
tmp/storage/zx (dir)
tmp/storage/zy (dir)
tmp/storage/zz (dir)
✗ copying directory storage/04
Too many open files (os error 24)
This is on macOS 26.4. It's a Rails project with a large seeded storage directory and a sub-project with a very large node_modules directory.
I can probably work around this by scripting a fresh rails db:seed and npm ci as a hook but the bigger issue, I think, is that an error in a low-level step isn't being propagated to the user.
While I think that rewriting the background processes to properly report errors is a bigger issue, https://github.com/max-sixty/worktrunk/pull/1864 is my effort to address the underlying failure.
Thanks for reporting this (and for the detailed investigation)! I can confirm the root cause from code reading.
File descriptor exhaustion: step_copy_ignored iterates entries with par_iter() on the global rayon pool. Each directory entry calls copy_dir_recursive, which creates its own 4-thread pool. With many directory entries processed in parallel, this spawns many independent thread pools — each holding open file handles — exhausting the OS limit.
Silent failure: When copy-ignored runs as a post-start hook, it's spawned as a detached background process. The parent only checks whether the spawn succeeded, not the command's exit status — so a failure like EMFILE is logged to a file but never shown to the user.
Your #1864 addresses the first concern. CI is currently failing on that PR (lint + test errors) — let us know if you'd like help getting it green. The silent error propagation is a separate issue worth tracking; I'll leave that for a maintainer to evaluate.
Linter and test fixes are now in.
CI is all green now — lint, tests (all platforms), and codecov pass. Thanks for the quick fixes!