Skip to content

fix(setup): resolve repo root without a work tree in linked worktrees - #10401

Merged
kodjima33 merged 1 commit into
mainfrom
issues-improver/10352-worktree-hook-root-resolution
Jul 23, 2026
Merged

kodjima33 merged 1 commit into
mainfrom
issues-improver/10352-worktree-hook-root-resolution

Conversation

@kodjima33

@kodjima33 kodjima33 commented Jul 23, 2026 •

Copy link
Copy Markdown
Collaborator

What

Make repo-root resolution in make setup, the git hook installer, and the installed hook dispatchers survive a linked worktree whose git context resolves to a git dir rather than a work tree.

Why

In a linked worktree (e.g. a Conductor workspace whose gitdir lives under the main clone's .git/worktrees/), git rev-parse --show-toplevel exits 128 with fatal: this operation must be run in a work tree. Three call sites assumed it always returns a path:

  • Makefile — PYTHON ?= $(shell … source "$(git rev-parse --show-toplevel)/scripts/dev-harness/_resolve_python.sh" …) collapsed to an empty prefix, so every target failed with /scripts/dev-harness/_resolve_python.sh: No such file and dev_harness_python: command not found.
  • scripts/install-git-hooks.sh — ROOT="$(git rev-parse --show-toplevel)" aborted make setup at setup-hooks with Error 128.
  • The installed pre-commit/pre-push dispatcher — the same call aborted the hook, forcing git push --no-verify and silently bypassing the local gate.

AGENTS.md mandates worktrees for all code changes, so this hit every agent working from a secondary workspace mount. Reported in #10352 (and duplicate #10293).

Fix

  • Makefile and the dispatcher fall back to pwd (git runs hooks, and make, from the top of the work tree) when --show-toplevel can't resolve a work tree. The root stays computed in-shell and is never interpolated into recipe text, so FC-shell-source-path-interpolation still holds (a checkout path with quote/$ characters cannot inject).
  • install-git-hooks.sh resolves its root from the script's own location (${BASH_SOURCE[0]}), matching the pattern _resolve_python.sh already uses. --git-path hooks is kept as-is for HOOKS_DIR — it does not require a work tree and resolves correctly in this context.

Tested

  • bash scripts/test-make-setup.sh — added a regression that reproduces the exact condition (bare GIT_DIR -> --show-toplevel exits 128 while --git-path hooks still resolves) and asserts PYTHON resolves. It fails on the pre-fix Makefile (PYTHON= empty, exit 1) and passes after.
  • python3 -m pytest scripts/dev-harness/tests/test_python_resolver.py — 5 passed (the shell-injection/space-in-path contract still holds; an earlier $(REPO_ROOT) interpolation attempt was rejected by these tests).
  • bash scripts/dev-harness/run-tests.sh — 50 passed.
  • Exercised the real installer in a linked worktree from both the work-tree top and the git-dir context: make setup-hooks succeeds and installs dispatchers carrying the pwd fallback; firing the installed pre-push/pre-commit dispatchers routes to the invoking worktree's scripts/.

Failure-Class: FC-shell-source-path-interpolation

Auto-generated from issue feedback by the mini issues-improver — tested and merged.

Review in cubic

`git rev-parse --show-toplevel` exits 128 ("this operation must be run in
a work tree") in a linked worktree whose git context resolves to a git
dir rather than a work tree (e.g. a Conductor workspace). Three call
sites assumed it always returns a path:

- Makefile PYTHON collapsed to an empty prefix, breaking every target
  with `/scripts/dev-harness/_resolve_python.sh: No such file`.
- install-git-hooks.sh aborted `make setup` at setup-hooks (Error 128).
- The installed pre-commit/pre-push dispatcher aborted the hook, forcing
  `git push --no-verify` and silently bypassing the local gate.

Makefile and the dispatcher fall back to `pwd` (make and git hooks both
run from the top of the work tree) while keeping the root computed
in-shell, so a checkout path with quote/`$` chars still cannot inject.
install-git-hooks.sh resolves its root from the script's own location.
Adds a regression to scripts/test-make-setup.sh that reproduces the
128 condition via a bare GIT_DIR and fails on the pre-fix Makefile.

Failure-Class: FC-shell-source-path-interpolation

fixes #10352
@kodjima33
kodjima33 merged commit 5c1b6d6 into main Jul 23, 2026
36 of 39 checks passed
@kodjima33
kodjima33 deleted the issues-improver/10352-worktree-hook-root-resolution branch July 23, 2026 15:23
Git-on-my-level added a commit that referenced this pull request Jul 30, 2026
Fixes #9724.
Fixes #10293.

## Summary

- make the single-flight runner register only host-supported signals and
replace destructive Windows `os.kill(pid, 0)` probing
- launch the extensionless pre-push script through Git Bash and carry
one explicit Python executable across every hook boundary, including the
`PRE_PUSH_SKIP_PR_PREFLIGHT=1` failure-class hatch
- contain the Windows command tree in a kill-on-close Job Object, with a
bootstrap barrier that assigns the job before the real command can spawn
- bind stale-lock identity to Windows process creation ticks so PID
reuse cannot impersonate the prior owner
- decode Git metadata as UTF-8 so native Windows locales can resolve
non-ASCII worktree paths
- make the check manifest Windows-aware and add a path-scoped native
Windows workflow that executes the manifest-owned portability checks
- preserve the mainline `forwardable_signals` and direct-child fallback
contracts while extending Windows ownership to the full process tree
- restore the linked-worktree repo-root fallback across all five
downstream shell/Python pre-push entrypoints, so a `show-toplevel` exit
128 does not force contributors toward `--no-verify`
- keep native process tests event-driven with pipe handshakes and
`WaitForSingleObject`, without wall-clock polling or leaked handles

## Root cause

The pre-push control plane assumed POSIX signals, process groups,
executable script launching, virtualenv layout, and `python3` naming at
native Windows boundaries. It also let Python decode Git's UTF-8 output
with the active Windows code page, so a worktree path containing
non-ASCII characters could fail before any check ran.

A second gap remained after #10401: the installed hook dispatcher could
recover when `git rev-parse --show-toplevel` failed in a linked
worktree, but `scripts/pre-push`, `scripts/pre-push-singleflight`,
`scripts/pr-preflight`, `.github/scripts/preflight_runner.py`, and
`.github/scripts/pr_preflight.py` repeated the unguarded lookup and
aborted later in the same chain.

Fixing only the first Windows exception or only the Makefile/dispatcher
boundary would expose the next launch, liveness, decoding,
root-resolution, or hatch failure. This PR closes that reachable
portability chain.

## Attribution

The linked-worktree root-resolution slice preserves Nik Shevchenko's
original #10491 implementation through the rebased commit lineage, with
`Co-authored-by: Nik Shevchenko <[email protected]>`. Its regression
was adapted to the explicit Windows Python launcher introduced by this
PR and registered in both manifest lanes plus native Windows CI.

## Verification

- rebased onto current `origin/main` (`ffc13daf4c`) and reran the native
Windows checks
- native Windows manifest run: `pre-push-worktree-fallback`,
`preflight-runner-portability`, and `check-manifest-contract` -> 3
checks passed
- native Windows: `test_preflight_runner.py` -> 23 tests passed with
`ResourceWarning` promoted to an error, including a real Job Object
parent/descendant termination proof, explicit hatch interpreter
coverage, and runner/direct PR-preflight execution from a Chinese
worktree path with `PYTHONUTF8=0`
- native Windows: a temporary Git repository ran the real
`pre-push-singleflight -> preflight_runner -> pre-push` chain with no
`python3` on `PATH`
- native Windows: `test_run_checks.py` -> 33 tests passed, 1 POSIX-only
fixture skipped; the real manifest subprocess path also resolved
`python3` to the active interpreter with an empty `PATH`
- native Windows: full `test_pr_preflight.py` -> 26 tests passed, 3
explicit host-capability skips
- native Windows: `test-pre-push-worktree-fallback.sh` passed against
all five downstream root resolvers under the reproduced exit-128
condition
- `test_pre_push_ci_prediction.py` -> 14 tests passed
- `scripts/test-pre-push-diff-base.sh` passed under Git Bash
- `bash -n` passed for all four touched shell scripts
- Black 26.5.1 passed for the touched Python files with the repository's
120-column/no-string-normalization settings
- actionlint 1.7.12 passed for the Windows workflow
- `python -m py_compile` passed for all touched Python files
- `scripts/failure-class validate --base origin/main --head HEAD ...`
passed with `Failure-Class: none`
- `git diff --check origin/main...HEAD` passed

GNU Make is not installed on the local Windows host, so
`scripts/test-make-setup.sh` could not be rerun there. The new
regression exercises every downstream root resolver directly on native
Windows; Linux CI remains authoritative for the existing Make fixture
and the full manifest.

The committed diff changes the manifest, so the legacy local selector
intentionally attempts every manifest check. On native Windows that
broad run currently stops while collecting the existing
`dev-harness-unit-tests` because its qualification module imports
POSIX-only `fcntl`; the path-scoped Windows workflow therefore executes
the portability contracts by manifest check ID, while Linux CI remains
the full-manifest authority.

## Product invariants affected

none

## Failure class (fixes)

Failure-Class: none
undivisible pushed a commit to undivisible/omi that referenced this pull request Sep 29, 2026
…BasedHardware#10401)

`git rev-parse --show-toplevel` exits 128 ("this operation must be run in
a work tree") in a linked worktree whose git context resolves to a git
dir rather than a work tree (e.g. a Conductor workspace). Three call
sites assumed it always returns a path:

- Makefile PYTHON collapsed to an empty prefix, breaking every target
  with `/scripts/dev-harness/_resolve_python.sh: No such file`.
- install-git-hooks.sh aborted `make setup` at setup-hooks (Error 128).
- The installed pre-commit/pre-push dispatcher aborted the hook, forcing
  `git push --no-verify` and silently bypassing the local gate.

Makefile and the dispatcher fall back to `pwd` (make and git hooks both
run from the top of the work tree) while keeping the root computed
in-shell, so a checkout path with quote/`$` chars still cannot inject.
install-git-hooks.sh resolves its root from the script's own location.
Adds a regression to scripts/test-make-setup.sh that reproduces the
128 condition via a bare GIT_DIR and fails on the pre-fix Makefile.

Failure-Class: FC-shell-source-path-interpolation

fixes BasedHardware#10352
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant