Personal_AI_Infrastructure icon indicating copy to clipboard operation
Personal_AI_Infrastructure copied to clipboard

CommitOwn drops files from the commit when a git listing exceeds 1 MB (spawnSync maxBuffer)

Open drpaulobernardy opened this issue 2 weeks ago • 2 comments

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

  1. git() passes maxBuffer: 512 << 20 and puts r.error into err when stderr is empty.
  2. The listings that decide the commit (ls-files --others, ls-files, ls-tree, diff --name-only) throw when ok is false. commitOwn returns fail(1) with the git error and undoes its add -N marks, instead of committing a partial list. The final git show --name-only asserts ok before the invariants compare lists.

With this fix, the reproduction above commits all 14,000 files and leaves git status clean.

drpaulobernardy avatar Nov 17 '26 12:11 drpaulobernardy

[!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 diff runs 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-nul with 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.

drpaulobernardy avatar Nov 17 '26 12:11 drpaulobernardy

[!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.

danielmiessler avatar Nov 18 '26 23:11 danielmiessler