Skip to content

fix(scripts): resolve worktree root before relative_to in type_check_gate - #31906

Merged
yuneng-berri merged 2 commits into
litellm_internal_stagingfrom
litellm_/ecstatic-ramanujan-97f9c8
Jul 1, 2026
Merged

fix(scripts): resolve worktree root before relative_to in type_check_gate#31906
yuneng-berri merged 2 commits into
litellm_internal_stagingfrom
litellm_/ecstatic-ramanujan-97f9c8

Conversation

@yuneng-berri

Copy link
Copy Markdown
Collaborator

Relevant issues

Linear ticket

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • My PR passes all CI/CD checks (e.g., lint, format, unit tests)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

Screenshots / Proof of Fix

The failure mechanism, reproduced on macOS:

$ python3 -c "from pathlib import Path; import tempfile; d=Path(tempfile.mkdtemp()); print((d/'x').resolve().relative_to(d))"
ValueError: '/private/var/folders/08/.../T/tmphmqa3g1v/x' is not in the subpath of '/var/folders/08/.../T/tmphmqa3g1v'

Before the fix, every local make lint-basedpyright on a Mac died with "basedpyright produced no errors for the base tree ... refusing to blame this change for it". After the fix, with no TMPDIR workaround:

$ env -u TMPDIR make lint-basedpyright
(uv run --no-sync basedpyright --outputjson || true) | uv run --no-sync python scripts/type_check_gate.py --base origin/litellm_internal_staging
OK: every rule is within its basedpyright limit or no higher than base (154833 errors total)

The new regression test fails on the old code and passes with the fix:

$ git stash -- scripts/type_check_gate.py && uv run pytest tests/test_litellm/test_type_check_gate.py::test_symlinked_root_keeps_diagnostics_in_tree -q
FAILED tests/test_litellm/test_type_check_gate.py::test_symlinked_root_keeps_diagnostics_in_tree
$ git stash pop && uv run pytest tests/test_litellm/test_type_check_gate.py -q
18 passed in 0.13s

Type

🐛 Bug Fix

Changes

On macOS, tempfile.mkdtemp() returns a path under /var/folders/..., which is a symlink to /private/var/.... The base pass of scripts/type_check_gate.py runs basedpyright in a temp worktree there, and _to_relative resolved each diagnostic path (yielding /private/var/...) but not the worktree root, so relative_to raised ValueError for every diagnostic. Every base diagnostic was dropped, base counts came back empty, and the vacuous-run guard failed the run. Since make pre-commit includes this gate for any litellm/ Python change, it always failed locally on a Mac. CI runs Linux where the temp dir is not a symlink, so it never saw this

The fix resolves the root as well: absolute.resolve().relative_to(root.resolve()). The sibling gates are fine; scripts/type_discipline_gate.py already resolves root for exactly this reason and scripts/ruff_strict_gate.py counts rule codes straight from ruff JSON without computing worktree-relative paths

The regression test builds an explicit symlinked root instead of relying on the macOS /var symlink, so it exercises the bug on Linux CI too

…gate

On macOS, tempfile.mkdtemp returns a path under /var/folders, a symlink
to /private/var. The base pass in type_check_gate.py resolved each
diagnostic path (yielding /private/var/...) but not the worktree root,
so relative_to raised ValueError for every diagnostic, base counts came
back empty, and the vacuous-run guard failed every local
make lint-basedpyright run. type_discipline_gate.py already resolves
root the same way; ruff_strict_gate.py counts rule codes without
touching worktree paths, so it is unaffected. CI runs Linux where the
temp dir is not a symlink, which is why this only bit local macOS runs
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixes a ValueError in scripts/type_check_gate.py caused by calling relative_to(root) after resolving the diagnostic path — leaving root unresolved while its resolved form differs (e.g., macOS /var/private/var). The one-line change adds .resolve() to root so both sides of relative_to are canonicalized consistently.

  • scripts/type_check_gate.py: _to_relative now calls root.resolve() alongside absolute.resolve(), matching the pattern already used in scripts/type_discipline_gate.py.
  • tests/test_litellm/test_type_check_gate.py: Adds test_symlinked_root_keeps_diagnostics_in_tree which constructs an explicit symlink via tmp_path, reproducing the failure on Linux CI without requiring the macOS-specific /var symlink.

Confidence Score: 5/5

The change is isolated to a developer tooling script and its test; no production code is touched.

The fix is a single .resolve() call that aligns the gate's behavior with the sibling type_discipline_gate.py script. The new regression test explicitly reproduces the failure on all platforms, all 18 existing tests continue to pass, and the scope is limited to the CI linting pipeline.

No files require special attention.

Important Files Changed

Filename Overview
scripts/type_check_gate.py Single-character fix in _to_relative: adds .resolve() on root so both sides of relative_to are symlink-resolved, matching the already-resolved diagnostic path. Correct and minimal.
tests/test_litellm/test_type_check_gate.py Adds test_symlinked_root_keeps_diagnostics_in_tree which builds an explicit symlinked root via tmp_path, exercising the bug on Linux CI without requiring the macOS /var symlink. All existing tests are untouched.

Reviews (1): Last reviewed commit: "Merge remote-tracking branch 'origin/lit..." | Re-trigger Greptile

@yuneng-berri
yuneng-berri merged commit ae6dbb4 into litellm_internal_staging Jul 1, 2026
121 of 122 checks passed
@yuneng-berri
yuneng-berri deleted the litellm_/ecstatic-ramanujan-97f9c8 branch July 1, 2026 21:09
duanhongyi pushed a commit to duanhongyi/litellm that referenced this pull request Jul 2, 2026
…gate (BerriAI#31906)

On macOS, tempfile.mkdtemp returns a path under /var/folders, a symlink
to /private/var. The base pass in type_check_gate.py resolved each
diagnostic path (yielding /private/var/...) but not the worktree root,
so relative_to raised ValueError for every diagnostic, base counts came
back empty, and the vacuous-run guard failed every local
make lint-basedpyright run. type_discipline_gate.py already resolves
root the same way; ruff_strict_gate.py counts rule codes without
touching worktree paths, so it is unaffected. CI runs Linux where the
temp dir is not a symlink, which is why this only bit local macOS runs
Rodrigo-Palma pushed a commit to Rodrigo-Palma/litellm that referenced this pull request Jul 3, 2026
…gate (BerriAI#31906)

On macOS, tempfile.mkdtemp returns a path under /var/folders, a symlink
to /private/var. The base pass in type_check_gate.py resolved each
diagnostic path (yielding /private/var/...) but not the worktree root,
so relative_to raised ValueError for every diagnostic, base counts came
back empty, and the vacuous-run guard failed every local
make lint-basedpyright run. type_discipline_gate.py already resolves
root the same way; ruff_strict_gate.py counts rule codes without
touching worktree paths, so it is unaffected. CI runs Linux where the
temp dir is not a symlink, which is why this only bit local macOS runs
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.

2 participants