Skip to content

fix(devshell): stop Nix mypy shadowing the uv.lock-pinned version - #3119

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/devshell-mypy-shadowing
Jul 18, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/devshell-mypy-shadowing

Conversation

@Sinity

@Sinity Sinity commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Summary

The Nix devshell's mypy entry in buildInputs silently shadowed the
uv.lock-pinned mypy 2.3.0 with the Nix store's 1.20.1, hiding real
strict-mypy findings locally that CircleCI's bare-Docker quick-gate
would catch.

Problem

devShells.default.buildInputs listed mypy directly (a Python
library package). mkShell's Python setup hooks add such packages'
site-packages to PYTHONPATH, and PYTHONPATH entries are consulted
before a venv's own site-packages when Python builds sys.path. So
.venv/bin/mypy (and any uv run mypy) ran the Nix-provided 1.20.1
instead of the correctly-installed 2.3.0 in .venv, even inside an
activated devshell.

This is exactly the class of drift PR #3077 hit and fixed for
polylogue/ on CircleCI: findings invisible locally, red on CI.
Running the real 2.3.0 against the full [tool.mypy] files config
(polylogue, tests/**, devtools/** — CircleCI checks polylogue/
only) surfaced two further findings CI has never covered:

  • tests/unit/coordination/test_envelope.py:215 — a real mypy
    narrowing limitation: after key in {tuple_a, tuple_b, tuple_c}
    narrows a tuple, mypy only tracks one alternative's literal type for
    a later subscript (key[1]), so a subsequent sibling if key[1] == "gate": is flagged as comparing non-overlapping literals even
    though the runtime behavior is correct.
  • tests/unit/cost/test_contract_suite.py:203 — a tautological
    assertion (!= "exact") already entailed by the preceding in {"priced", "partial"} check on the same narrowed value.

Solution

  • Drop mypy from the devshell's buildInputs. .venv (via
    uv sync --extra dev) is already the sole mypy provider; the Nix
    copy served no purpose except colliding with it.
  • test_envelope.py: bind the tuple element to an explicit str
    local (subcommand: str = key[1]) before comparing, which stops
    mypy from carrying an overly narrow literal type across the two
    sibling checks. No runtime behavior change.
  • test_contract_suite.py: delete the redundant assertion; the
    preceding line already proves it.
  • .gitignore: add .dmypy.json, the dmypy daemon state file that a
    now-actually-working dmypy invocation creates at the repo root
    (alongside the existing .mypy_cache/ entry).

Verification

  • nix develop --command bash -c 'python3 -c "import mypy; print(mypy.__file__, mypy.__version__)"'
    → resolves to .venv/.../mypy at 2.3.0 (was the Nix store's 1.20.1
    before this change).
  • nix develop --command uv run mypy polylogue/ → clean (matches
    CircleCI, whose 3 original findings were already fixed by fix(ci): satisfy Circle strict mypy checks #3077).
  • nix develop --command devtools verify --quick → 17/17 steps green,
    exit_code: 0.
  • devtools test tests/unit/coordination/test_envelope.py tests/unit/cost/test_contract_suite.py
    → 40 passed. 1 pre-existing failure unrelated to this change
    (KeyError: 'cost_outlook' in
    test_mcp_cost_outlook_tool_uses_shared_envelope) reproduces
    identically with these edits stashed out — MCP six-tool-cutover
    registry drift from fix(mcp): harden six-tool cutover — session correlation, status(operation), SessionStart preamble #3095, not touched by this PR.

Ref polylogue-i0ep

Problem

The Nix devshell listed `mypy` (a Python-library package) directly in
`devShells.default.buildInputs`. mkShell's Python setup hooks add such
packages' site-packages to PYTHONPATH, and PYTHONPATH entries are
consulted before a venv's own site-packages when Python builds
sys.path. So `.venv/bin/mypy` (and any `uv run mypy`) silently ran the
Nix-provided mypy 1.20.1 instead of the uv.lock-pinned 2.3.0, even
though `.venv` had the correct version installed all along.

This let 2.3.0-only strict findings pass locally while CircleCI's
bare-Docker quick-gate (no Nix PYTHONPATH injection) failed on the
same code, exactly as PR #3077 hit and fixed for polylogue/ itself.
Widening the check to the full mypy `files` config (polylogue, tests,
devtools — CircleCI checks polylogue/ only) surfaced two further
findings CI never covered: a real-mypy narrowing quirk on a tuple-set
membership check in test_envelope.py, and a tautological assertion in
test_contract_suite.py already implied by the preceding line.

Solution

- Drop `mypy` from the devshell's buildInputs; uv/`.venv` is already
  the sole mypy provider via the `dev` extra, so nothing needs it.
- Bind the narrowed tuple element to an explicit `str` local in
  test_envelope.py so mypy 2.3.0 stops inferring an overly narrow
  literal type across the two sibling `if` checks.
- Drop the redundant `!= "exact"` assertion in test_contract_suite.py
  (already entailed by the preceding `in {"priced", "partial"}` check).
- Ignore `.dmypy.json`, the dmypy daemon state file the working
  `dmypy` invocation now actually produces at the repo root.

Verification

- `nix develop --command bash -c 'python3 -c "import mypy;
  print(mypy.__file__, mypy.__version__)"'` → resolves to
  `.venv/.../mypy` at 2.3.0 (was the Nix store's 1.20.1).
- `nix develop --command uv run mypy polylogue/` → clean (matches
  CircleCI, which already fixed its 3 findings via #3077).
- `nix develop --command devtools verify --quick` → 17/17 steps green,
  exit_code 0 (previously failed on the two findings above once mypy
  ran at the correct version).
- `devtools test tests/unit/coordination/test_envelope.py
  tests/unit/cost/test_contract_suite.py` → 40 passed, 1 pre-existing
  failure unrelated to this change (`KeyError: 'cost_outlook'` in
  `test_mcp_cost_outlook_tool_uses_shared_envelope`, reproduces
  identically with these edits stashed out; MCP six-tool-cutover
  registry drift from #3095, not touched here).

Ref polylogue-i0ep
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 28 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b68f0e47-ed56-4bf4-a1fe-86b4b0184c56

📥 Commits

Reviewing files that changed from the base of the PR and between e1699f4 and 895bec0.

📒 Files selected for processing (4)
  • .gitignore
  • flake.nix
  • tests/unit/coordination/test_envelope.py
  • tests/unit/cost/test_contract_suite.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/devshell-mypy-shadowing

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Sinity
Sinity merged commit 46cab76 into master Jul 18, 2026
3 checks passed
@Sinity
Sinity deleted the feature/fix/devshell-mypy-shadowing branch July 18, 2026 17:34
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