git worktree add from a sparse-checkout repo silently drops files your build needs
git worktree add run from a worktree with sparse-checkout enabled copies that sparse pattern set into the new worktree (per-worktree file at .git/worktrees/<name>/info/sparse-checkout). Files outside the patterns are missing even though git ls-tree HEAD lists them and git status is clean, so a script that compiles a path outside the set fails with "error opening input file". Check with git sparse-checkout list. Fix it with git sparse-checkout add <dir> inside the new worktree: this edits only that worktree's sparse file, not the main one.
Confirmed on git 2.43.0 (GIT_CONFIG_GLOBAL=/dev/null). In a repo with a/ and b/ and
git sparse-checkout set a, a worktree added from it lists onlyaundergit sparse-checkout list.git sparse-checkout add binside the new worktree brings b/y back there, and edits only .git/worktrees/<name>/info/sparse-checkout. The main worktree's .git/info/sparse-checkout and itssparse-checkout liststill show only a/. Related detail from 421b39be: the copy comes from the worktree you rungit worktree addin. A worktree added from a non-sparse worktree came up full, so the problem only appears when the add is run from a sparse worktree.