[Bug]: StageUntracked merges git stderr into the NUL-separated pathspec stream — one unreadable untracked dir fails the node with "did not match any files"
Component / host
Platform — runner / sandbox
Edition
Platform
LoopForge version
v0.4.0 image ghcr.io/tencent/loopforge:0.4.0 (sha256:87b6a3e3cba2…); reproduced there, and unchanged in v0.4.1 / v0.4.2 / v0.4.3 (= main be6918d7c05)
What happened?
A LOOP run's first agent node failed with:
artifact contract: intent-add untracked files: exit status 128: fatal: pathspec 'warning: could not open directory 'services/platform/backend/internal/auth/idaas/data/': Permission denied
warning: could not open directory 'services/platform/backend/internal/auth/data/': Permission denied
warning: could not open directory 'services/platform/backend/internal/router/data/': Permission denied' did not match any files
Actual behavior. internal/gitwork.StageUntracked runs
git ls-files -z --others --exclude-standard through exec.CombinedOutput(). When the
workspace contains an untracked directory the sandbox user cannot read (in our case
runtime-generated JWT keypair dirs owned by root, mode 0700, while the platform runs as
uid 1000), git ls-files prints warning: could not open directory … on stderr.
CombinedOutput() merges stderr into the NUL-separated stdout stream. Because the warning
lines contain no \x00, they glue onto the neighbouring entry when the output is split on
"\x00", pass the Excluded() filter as a bogus "path", and are fed verbatim into
git add -N --pathspec-from-file=- --pathspec-file-nul. Git then fails with
fatal: pathspec '<warning lines>' did not match any files (exit 128). The artifact
contract fails and marks the node failed — in our run the run eventually failed too, even
though every later node and the delivery (PR) succeeded.
Expected behavior. stderr diagnostics from git ls-files should never end up in the
pathspec list. A warning about an unreadable directory should at most be logged; that
directory's contents simply are not listed as untracked files.
Why this is nasty. Any workspace where a root-owned or foreign-owned runtime directory
appears inside the repo tree bricks every agent node's finish phase, and retrying the
node cannot help because the condition is environmental. Workaround today: fix the dir
ownership, or add the runtime dir to .gitignore / .git/info/exclude (we did the latter
in-repo; both only dodge the stderr-merging defect instead of fixing it).
Still present on main. Verified 2026-11-27 against
be6918d7c0576e182d41daa808e140f1e529d7d9 (current main, identical to tag v0.4.3):
internal/gitwork/exclude.go → StageUntracked still calls cmd.CombinedOutput(). The
logic entered the tree with fb4e331 ("feat: add self-hosted LoopForge platform and retain
Local workflows (#48)", 2026-10-19, the first platform commit) and is byte-identical in
v0.4.0, v0.4.1, v0.4.2, v0.4.3 and main. Both PatchInventory and StageChanges call
StageUntracked, so this hits more than one node type.
Suggested fix. Separate stdout and stderr so only stdout is parsed; keep stderr for error context:
var stdout, stderr bytes.Buffer
cmd.Stdout, cmd.Stderr = &stdout, &stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("list untracked files: %w: %s", err, strings.TrimSpace(stderr.String()))
}
for _, rel := range strings.Split(stdout.String(), "\x00") {
...
}
Optional hardening in the same function: skip entries that do not look like paths (e.g.
strings.HasPrefix(rel, "warning:")), so a future stderr/stdout interleaving can never
inject pathspecs again. The sibling CombinedOutput in StageChanges (ls-files --cached)
only feeds a len()==0 check and is harmless today.
For completeness: our unreadable dirs were runtime-generated
(services/platform/backend/internal/{auth,auth/idaas,router}/data/ JWT keypairs,
root-owned from an earlier root-run process). They are gitignored now, which is correct
repo hygiene — but the platform should not fail hard on stderr noise regardless.
Reproduction
Minimal git-level repro of the exact code path (any machine with git + Go):
mkdir demo && cd demo
git init -q
echo hi > tracked.txt && git add . && git commit -qm init
echo new > new-untracked.txt # a file the contract SHOULD pick up
sudo mkdir -p locked # unreadable untracked dir
sudo chown root:root locked && sudo chmod 700 locked
Then simulate what StageUntracked does (internal/gitwork/exclude.go, v0.4.3):
cmd := exec.Command("git", "ls-files", "-z", "--others", "--exclude-standard")
out, _ := cmd.CombinedOutput() // stderr warning merges into the stream
for _, rel := range strings.Split(string(out), "\x00") {
if rel != "" { fmt.Printf("entry: %q\n", rel) }
}
Observed: one "entry" is the glued warning block, e.g.
entry: "warning: could not open directory 'locked/': Permission denied\nnew-untracked.txt"
That entry survives Excluded() and is passed as a single pathspec to
git add -N --pathspec-from-file=- --pathspec-file-nul, producing:
fatal: pathspec 'warning: could not open directory 'locked/': Permission denied' did not match any files
End-to-end in LoopForge: run any built-in delivery LOOP against a repo containing such a
directory; the node's artifact contract fails with
intent-add untracked files: exit status 128 (seen on the very first agent node of a
generic-backend-delivery run).
Sanitized diagnostics
$ git ls-files -z --others --exclude-standard # in the sandbox workspace, as uid 1000
warning: could not open directory 'services/platform/backend/internal/auth/idaas/data/': Permission denied
warning: could not open directory 'services/platform/backend/internal/auth/data/': Permission denied
warning: could not open directory 'services/platform/backend/internal/router/data/': Permission denied
new-file-1.go\0new-file-2.go\0... (NUL-separated stdout; the warnings above end up glued to one entry)
$ ls -ld services/platform/backend/internal/auth/data
drwx------ 2 root root 4096 <date> services/platform/backend/internal/auth/data
node: <first agent node of generic-backend-delivery>
artifact contract: intent-add untracked files: exit status 128: fatal: pathspec 'warning: could not open directory 'services/platform/backend/internal/auth/idaas/data/': Permission denied
warning: could not open directory 'services/platform/backend/internal/auth/data/': Permission denied
warning: could not open directory 'services/platform/backend/internal/router/data/': Permission denied' did not match any files
run: ended failed, although later nodes and the PR delivery succeeded
Safety checks
- [x] I removed credentials, private endpoints, internal identifiers, and personal data.
- [x] I searched existing issues for duplicates.
Thanks for the report. I understand that while staging untracked files, git warnings on stderr are merged into the NUL-separated path list, so one unreadable untracked directory can make the artifact step fail with a pathspec error.
This is noted and will be reviewed along with the existing issues.