Summary
codebase-index index crashes with ValueError: ... is not in the subpath of ... on any repository that has a root-level symlink pointing outside the repo. Bazel's convenience symlinks (bazel-bin, bazel-out, bazel-testlogs, bazel-<workspace>) are the common trigger, but any out-of-tree symlink in the walked root will do it. The crash happens before any file is indexed.
Environment
- codebase-index 1.8.0 (pipx)
- Python 3.11
- Linux
Repro
- Use a repo with a root symlink that points outside the tree. A Bazel workspace after a build is the easy case: it creates
bazel-out -> ~/.cache/bazel/.../bazel-out, etc.
codebase-index init
codebase-index index
Traceback (abridged)
indexer/pipeline.py -> build_index -> discovery/walker.py:walk -> _rel
return path.resolve().relative_to(root).as_posix()
ValueError: '/home/.../.cache/bazel/.../bazel-out' is not in the subpath of '/home/.../repo'
Root cause
discovery/walker.py:_rel:
def _rel(root: Path, path: Path) -> str:
return path.resolve().relative_to(root).as_posix()
os.walk lists the symlink in dirnames; the directory filter calls _rel on it while building the argument to is_ignored; .resolve() follows the symlink out of the tree, and .relative_to(root) then raises.
There is no user-side workaround: is_ignored_dir is backed by the hardcoded BUILTIN_DENYLIST (not configurable), and extra_ignore is evaluated via is_ignored after _rel has already thrown. Adding bazel-* patterns to extra_ignore still crashes.
Suggested fix
Drop the .resolve():
def _rel(root: Path, path: Path) -> str:
return path.relative_to(root).as_posix()
os.walk uses followlinks=False by default, so it never descends into the symlinked directory, and it already yields paths lexically under root. .resolve() is unnecessary here and is the sole cause of the crash. Alternatively, guard relative_to with a try/except and skip out-of-tree paths.
Reproduced on v1.8.0. v1.9.0 likely affected too if the walker is unchanged (not verified).
Summary
codebase-index indexcrashes withValueError: ... is not in the subpath of ...on any repository that has a root-level symlink pointing outside the repo. Bazel's convenience symlinks (bazel-bin,bazel-out,bazel-testlogs,bazel-<workspace>) are the common trigger, but any out-of-tree symlink in the walked root will do it. The crash happens before any file is indexed.Environment
Repro
bazel-out -> ~/.cache/bazel/.../bazel-out, etc.codebase-index initcodebase-index indexTraceback (abridged)
Root cause
discovery/walker.py:_rel:os.walklists the symlink indirnames; the directory filter calls_relon it while building the argument tois_ignored;.resolve()follows the symlink out of the tree, and.relative_to(root)then raises.There is no user-side workaround:
is_ignored_diris backed by the hardcodedBUILTIN_DENYLIST(not configurable), andextra_ignoreis evaluated viais_ignoredafter_relhas already thrown. Addingbazel-*patterns toextra_ignorestill crashes.Suggested fix
Drop the
.resolve():os.walkusesfollowlinks=Falseby default, so it never descends into the symlinked directory, and it already yields paths lexically underroot..resolve()is unnecessary here and is the sole cause of the crash. Alternatively, guardrelative_towith a try/except and skip out-of-tree paths.Reproduced on v1.8.0. v1.9.0 likely affected too if the walker is unchanged (not verified).