Public: anyone can read this; the crew can change it.

The .git symlink refusal for crew clones lands from a branch in trevato/forge that reviewers can read #15148

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

This replaces #14970. It carries that pull's fix onto today's main unchanged, and #14970 itself never landed. Crew clones are now refused when anything inside .git is a symbolic link.

Notes

shipped production is serving it deploy cfe12e4

opened this

This replaces #14970. It carries that pull's fix onto today's main unchanged, and #14970 itself never landed. Crew clones are now refused when anything inside .git is a symbolic link.

Where the change came from. #14970's head (fddfdb8ab) can't be fetched from trevato/forge or mason/forge any more, because its branch mason/14916 is gone. I rebuilt the patch from the diff the forge stored for #14970: 106 additions and 10 deletions in src/crew/clone_git.ts, 118 and 1 in test/crew-clone-git.test.ts. It applied cleanly to 799bde0b6. Only the combined diff survives, so its four commits land as one, ending Co-authored-by: mason.

What it does (src/crew/clone_git.ts): foreignGitDir now walks every entry under .git without following links, reading one entry at a time. It refuses the clone, naming the entry, when it finds:

  • a symbolic link anywhere inside .git;
  • an entry that is neither a file nor a directory, such as a FIFO;
  • the wrong kind where git expects one, per GIT_ENTRY_KIND (for example, index must be a file and objects a directory).

What to look at:

  • Entry cap: the issue says 100,000, but the head that went green sets GIT_ENTRY_LIMIT = 8192. I kept 8192 rather than rewrite the fix. The code comment explains it: git packs loose objects at 6,700 (gc.auto), and at 8,192 the walk takes about 10 ms. A fresh crew clone has about 64 entries under .git, so it passes easily.
  • Where the branch lives: a plain git push from this sandbox went to mason/forge, the same fork as before, not to trevato/forge. The sandbox has no way to push to trevato/forge. If reviewers' clones fetch only trevato/forge, they may see an empty diff again. That needs the forge to fetch the head, or a person to push this branch to trevato/forge.

Tests:

  • bun test test/crew-clone-git.test.ts: 24 pass, 0 fail. The 1 skip is an older test that needs bwrap.
  • The file is not in EXCLUDED, so the gate runs it.
  • bun scripts/gate.ts --fix changed nothing and bun x tsc --noEmit is clean.
  • scripts/fast.ts named 2,201 files, so I picked the suites that reach the callers of clone git myself: leak-worker, orphan-claims, orphan-clones, review-head-fetch, run-secrets, secrets-never-surface and job-slices. All 35 tests pass.
  • I briefly started an unfiltered bun test by mistake (an empty file list) and stopped it; ignore it.

How to try: bun test test/crew-clone-git.test.ts. Each case first shows plain git following the link, then shows runCloneGit refusing it. A clean clone passes.

🤖 Generated with Claude Code

Closes #15143

2 earlier comments · 1 event
commented

This replaces #14970. It carries that pull's fix onto today's main unchanged, and #14970 itself never landed. Crew clones are now refused when anything inside .git is a symbolic link.

Where the change came from. #14970's head (fddfdb8ab) can't be fetched from trevato/forge or mason/forge any more, because its branch mason/14916 is gone. I rebuilt the patch from the diff the forge stored for #14970: 106 additions and 10 deletions in src/crew/clone_git.ts, 118 and 1 in test/crew-clone-git.test.ts. It applied cleanly to 799bde0b6. Only the combined diff survives, so its four commits land as one, ending Co-authored-by: mason.

What it does (src/crew/clone_git.ts): foreignGitDir now walks every entry under .git without following links, reading one entry at a time. It refuses the clone, naming the entry, when it finds:

  • a symbolic link anywhere inside .git;
  • an entry that is neither a file nor a directory, such as a FIFO;
  • the wrong kind where git expects one, per GIT_ENTRY_KIND (for example, index must be a file and objects a directory).

What to look at:

  • Entry cap: the issue says 100,000, but the head that went green sets GIT_ENTRY_LIMIT = 8192. I kept 8192 rather than rewrite the fix. The code comment explains it: git packs loose objects at 6,700 (gc.auto), and at 8,192 the walk takes about 10 ms. A fresh crew clone has about 64 entries under .git, so it passes easily.
  • Where the branch lives: a plain git push from this sandbox went to mason/forge, the same fork as before, not to trevato/forge. The sandbox has no way to push to trevato/forge. If reviewers' clones fetch only trevato/forge, they may see an empty diff again. That needs the forge to fetch the head, or a person to push this branch to trevato/forge.

Tests:

  • bun test test/crew-clone-git.test.ts: 24 pass, 0 fail. The 1 skip is an older test that needs bwrap.
  • The file is not in EXCLUDED, so the gate runs it.
  • bun scripts/gate.ts --fix changed nothing and bun x tsc --noEmit is clean.
  • scripts/fast.ts named 2,201 files, so I picked the suites that reach the callers of clone git myself: leak-worker, orphan-claims, orphan-clones, review-head-fetch, run-secrets, secrets-never-surface and job-slices. All 35 tests pass.
  • I briefly started an unfiltered bun test by mistake (an empty file list) and stopped it; ignore it.

How to try: bun test test/crew-clone-git.test.ts. Each case first shows plain git following the link, then shows runCloneGit refusing it. A clean clone passes.

🤖 Generated with Claude Code

commented

Host-side git in crew clones now refuses a symbolic link anywhere inside .git, not only at the top (#15143, replaces #14916). This carries pull #14970 onto today's main unchanged. Its head can no longer be fetched, so the patch was rebuilt from the pull's stored diff and lands as one commit.

What changed in src/crew/clone_git.ts: foreignGitDir now walks every entry under .git one at a time and checks each without following links. It refuses:

  • a symbolic link;
  • an entry that is neither a file nor a directory;
  • the wrong kind where git expects a particular one (listed in GIT_ENTRY_KIND);
  • a .git with more than GIT_ENTRY_LIMIT (8192) entries, so the walk, which blocks while it runs, never stalls the forge.

Fix for the failing check: the test "a link deeper in .git, a non-file entry, or the wrong kind where git expects one is refused" in test/crew-clone-git.test.ts made seven clones and wrote 8193 files. It took 2.14 s, over the 2 s budget for one test. It is now four tests, with the same cases and assertions:

  • a link deeper in .git;
  • links where git keeps info, hooks or logs;
  • index as a directory and packed-refs as a named pipe (a non-file entry);
  • the entry limit, plus a clone git made itself passing.

Each makes at most three clones. The slowest, the entry limit, runs in about 1 s. The test was too slow, not wrong, and the code under test is untouched.

test/migrate.test.ts (2.01 s) appears in the check log, but only on the list of tests over the time budget; the one shard that failed was the clone-git test. I left it alone because this change doesn't touch it.

Checks run: bun test test/crew-clone-git.test.ts gives 27 pass, 1 skipped (a unix-socket suite this sandbox skips), 0 fail. bun scripts/gate.ts --fix and bun x tsc --noEmit are clean.

To try it: run bun test test/crew-clone-git.test.ts and look at the #14916 describe blocks.

🤖 Generated with Claude Code

Approved

Approved. The walk is lstat-free (d_type), reads one entry at a time, refuses links, non-file/dir entries and wrong kinds per GIT_ENTRY_KIND, runs on every git call, and each case first shows plain git following the link. Backend only, no page or README change. Two things I would do next: (1) decide the entry cap with the issue: it asked for 100,000 and this ships 8192; confirm no legitimate crew clone with many loose refs/tags nears it, or raise it. (2) Hoist the repeated inline await import("node:fs") in the new tests to the top-level import.

commented

Left #15143 open: 1 unticked item remain (the commits of #14970 are on a branch in trevato/forge, rebased on today's main, each ending Co-authored-by naming mason. They are: foreignGitDir in src/crew/clone_git.ts lstats every entry under .git and refuses a symbolic link, a non-file/non-directory entry, or the wrong kind per GIT_ENTRY_KIND, with a cap of 100,000 entries).

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs