Skip to content

fix(git_bridge): strip inherited git-context env in run_git (kills pre-push hook race)#1009

Merged
joelteply merged 1 commit into
canaryfrom
fix/git-bridge-tests-parallel-race
May 2, 2026
Merged

fix(git_bridge): strip inherited git-context env in run_git (kills pre-push hook race)#1009
joelteply merged 1 commit into
canaryfrom
fix/git-bridge-tests-parallel-race

Conversation

@joelteply
Copy link
Copy Markdown
Contributor

Summary

The pre-push hook's Phase 3 (Rust tests) was reliably failing 9-of-9 code::git_bridge::tests::* whenever invoked, even though the same tests passed in isolation. Root cause is git env inheritance, not parallelism.

Root cause

git push sets GIT_DIR, GIT_PREFIX, etc. on the pre-push hook's environment. Those env vars propagate through every child — including cargo test, including the test binary, including each test's tempdir git init/git commit. So a test's git commit in its tempdir inherits GIT_DIR=/Users/.../continuum/.git, runs the parent worktree's pre-commit hook (which can't find its target script in the tempdir context), and panics.

Three different surface symptoms, all from the same upstream cause:

  • "could not lock config file <bare>/.git/config: File exists"
  • "Unable to create '<bare>/.git/worktrees/<x>/index.lock'"
  • "<bare>/.git/hooks/pre-commit: <tmp>/src/scripts/git-precommit.sh: No such file or directory"

Fix

In run_git:

  • env_remove for GIT_DIR, GIT_WORK_TREE, GIT_COMMON_DIR, GIT_INDEX_FILE, GIT_PREFIX
  • Set GIT_CEILING_DIRECTORIES=workspace_root as defense-in-depth against future env vars

run_git is now context-clean: git discovers from current_dir(workspace_root) only, no parent contamination. Production callers get a small safety improvement (continuum-core's git_bridge invoked from any process won't accidentally inherit the caller's git context); test callers get reliable isolation.

Tests

Reproduces the previously-failing case by simulating the hook environment:

Command Before After
cargo test --lib code::git_bridge passed passed
GIT_DIR=<continuum>/.git cargo test --lib code::git_bridge 9 failures 9 passed
cargo test --lib (full suite, normal env) passed passed
cargo test --lib (full suite, via pre-push) 9 failures passed (this push)

Why this PR matters beyond itself

The pre-push hook's Phase 3 false-positive was blocking ANY PR whose change is non-Rust (PowerShell-only, docs-only, TS-only) from passing through. Two such PRs were blocked tonight — b69f's #1005 (Carl-OOTB Windows fix #1) and my unpushed install.ps1 networking-probe (Carl-OOTB Windows fix #2). With this fix, the hook stops false-positive blocking on the inherited-env race.

Test plan

  • CI green (clean-install matrix unaffected; this is Rust-only fix in continuum-core)
  • Local pre-push passed (this push went through cleanly)
  • Reviewers can repro: GIT_DIR=$(git rev-parse --git-dir) cargo test --lib --features metal,accelerate code::git_bridge — should pass on this branch, fail on canary

🤖 Generated with Claude Code

Root cause for the pre-push hook's git_bridge::tests cluster failure:

When `cargo test --lib` is invoked by the pre-push hook (which is
itself invoked by `git push`), git sets context env vars (GIT_DIR,
GIT_PREFIX, etc.) on the hook process. Those env vars propagate to
every child — including cargo, including the test binary, including
the tempdir `git init`/`git commit` calls inside the tests.

So when a test does `git commit` in its tempdir, git inherits
GIT_DIR=/Users/joelteply/.../continuum/.git, runs the parent
worktree's pre-commit hook (which itself shells `<repo>/src/scripts/
git-precommit.sh`), and panics because that script's path doesn't
exist relative to the tempdir.

Surface symptom: 9-of-9 git_bridge tests fail when run via the
pre-push hook with errors like:
  - "could not lock config file <bare>/.git/config: File exists"
  - "Unable to create '<bare>/.git/worktrees/<x>/index.lock'"
  - "<bare>/.git/hooks/pre-commit: <tmp>/src/scripts/git-precommit.sh:
     No such file or directory"

All three are symptoms of the same upstream cause: GIT_DIR pinning
git to the parent worktree regardless of cwd.

Fix: strip GIT_DIR / GIT_WORK_TREE / GIT_COMMON_DIR / GIT_INDEX_FILE
/ GIT_PREFIX from the environment when invoking git via run_git.
Also set GIT_CEILING_DIRECTORIES=workspace_root as defense-in-depth
against future git env vars.

This makes run_git context-clean: git discovers from current_dir
only, no parent contamination.

## Tests

Reproduces previously-failing case: simulate hook env by exporting
GIT_DIR before cargo test:
  Before: GIT_DIR=<continuum>/.git cargo test --lib code::git_bridge
          → 9 failures with "could not lock config file"
  After:  same command → 9 passed; 0 failed

Caught by continuum-b69f's pre-push run on 2026-05-02. Unblocks any
PR (PowerShell-only, docs-only, TS-only) from the spurious pre-push
fail. Also makes run_git production-safer: hooks invoking continuum-
core's git_bridge functions get a clean context.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@joelteply joelteply force-pushed the fix/git-bridge-tests-parallel-race branch from de8f46c to ff96c64 Compare May 2, 2026 05:55
@joelteply joelteply merged commit 0811dd3 into canary May 2, 2026
3 checks passed
@joelteply joelteply deleted the fix/git-bridge-tests-parallel-race branch May 2, 2026 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant