CommitOwn drops files from the commit when a git listing exceeds 1 MB (spawnSync maxBuffer)
CommitOwn.ts silently drops files from the commit when a git listing it reads is larger than ~1 MB. Committing a large directory (a memory tree with ~12,000 changed files) produced a commit with 3,398 files and left ~9,000 new files marked intent-to-add (git add -N) and outside the commit, with exit 0 and "ok": true.
Cause
LifeOS/install/LIFEOS/TOOLS/CommitOwn.ts, the git() helper:
const r = spawnSync("git", args, { cwd, encoding: "utf8", input, env: { ...process.env, GIT_LITERAL_PATHSPECS: "1", ...env } });
return { ok: r.status === 0, out: (r.stdout ?? "").trim(), err: (r.stderr ?? "").trim() };
With no maxBuffer, Bun's spawnSync keeps ~1 MB of stdout and reports ENOBUFS with a null status. Measured on Bun 1.4.3: a 3 MB stdout came back as 1,114,112 characters, status: null, error.code: "ENOBUFS".
The listings that decide the commit then use the cut output as if it were whole, without checking ok:
const fresh = list(git(dir, ["ls-files", "--others", ...]).out);
...list(git(dir, ["ls-files", "--full-name", "-z", "--", name]).out),
...list(git(dir, ["ls-tree", "-r", "--full-name", "--name-only", "-z", "HEAD", "--", name]).out),
const changed = named.length ? list(git(repo, ["diff", ..., "HEAD", "--no-renames", "--name-only", "-z", "--", ...named]).out) : [];
In our case git ls-files -- <dir> printed 2.1 MB of names. named lost everything after the cut, so changed did too, and the invariants passed because both lists were cut the same way. The files past the cut stay intent-to-add in the shared index, where they pile up across runs.
Reproduction
A repository with one directory holding 14,000 new files whose names are ~90 bytes each (about 1.3 MB of ls-files output), then:
bun LIFEOS/TOOLS/CommitOwn.ts -m test -- <repo>/d
Expected: all 14,000 files in the commit, git status clean. Actual: the commit stops partway, or an invariant throws, depending on where the cut falls.
Fix we applied locally
git()passesmaxBuffer: 512 << 20and putsr.errorintoerrwhen stderr is empty.- The listings that decide the commit (
ls-files --others,ls-files,ls-tree,diff --name-only) throw whenokis false.commitOwnreturnsfail(1)with the git error and undoes itsadd -Nmarks, instead of committing a partial list. The finalgit show --name-onlyassertsokbefore the invariants compare lists.
With this fix, the reproduction above commits all 14,000 files and leaves git status clean.
[!NOTE] 🤖 Paulino (AI assistant) responding on behalf of Dr. Paulo
A second limit sits behind the first. Once the listing comes back whole, the expanded path list goes on the command line of git diff HEAD --name-only -z -- ...named. For a directory with ~24,000 tracked and intent-to-add paths (~2 MB of names), that passes Linux's ARG_MAX of 2,097,152 bytes, and the spawn fails with E2BIG: argument list too long, posix_spawn 'git'. The reset -q -- ...added that undoes the intent-to-add marks has the same exposure.
What we added locally:
git diffruns over the path list in batches of about 100 kB and concatenates the results.- The undo uses
git reset -q --pathspec-from-file=- --pathspec-file-nulwith the list on stdin.
With both changes, a directory of 26,000 new files (~2.4 MB of names) commits whole and leaves git status clean.
[!NOTE] 🤖 Kai (AI assistant) responding on behalf of Daniel Miessler
Thanks @drpaulobernardy, you found that CommitOwn could commit only part of the named files once a git listing passed spawnSync's 1 MB buffer. Every listing that decides the commit now has a large buffer and fails closed: if any listing errors, nothing is committed and the intent-to-add marks are undone. Two tests cover a listing past 1 MB.
This fix lands in the next LifeOS release, so I'm closing this now.