← Back to Pull requests

Reject a script path that collides with the type stubs file #967

Closed
unknown closed this pull request without merging on Oct 05, 2026 09:36 UTC
View on GitHub
unknown unknown commented on Oct 04, 2026 08:27 UTC
Author

Fixes #717

If script_name is repl_type_stubs.pyi, the script gets written over the stubs file and ends up importing itself. #756 stopped the panic, but the type check result is still wrong: names from the stubs are reported as undefined, plus a "Cannot redefine T".

Now TypeChecker::run returns an error when the script and the stubs resolve to the same file. I compare files and not strings, so ./repl_type_stubs.pyi and similar paths are caught too.

The host sees it as "type checker failed". If you'd rather have it fail at Configure, I can move the check there.

Added a test in monty-type-checking and a subprocess test with the repro from the issue, both fail on main. fmt, clippy and the rust tests pass, I didn't run the python tests.

<!-- This is an auto-generated description by cubic. -->
---

Summary by cubic


Rejects scripts whose path resolves to the same file as the type stubs, which previously caused the script to overwrite the stubs and import itself, making stub names undefined and spans underflow.

  • Compares interned files rather than strings, so paths like ./repl_type_stubs.pyi and sub/../repl_type_stubs.pyi are also caught.

  • The type checker now returns an error to the host; the RPC feed ends in an error instead of a crash.

  • Adds a unit test covering path-normalized collisions and a subprocess test with the repro from #717.
  • <sup>Written for commit 06815adbbdee04955733acc45a26b5c10de635e3. Summary will update on new commits.</sup>

    <a href="https://cubic.dev/pr/pydantic/monty/pull/967?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

    <!-- End of auto-generated description by cubic. -->

    Diff: 252 lines (+189 / -63) across 3 files Reviewer: davidhewitt Review duration: 1508m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.44) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.44 · 252 lines diff across 3 files
    0.44
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.331
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #967"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 44% (MEDIUM) · Higher = larger blast radius
    44%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.4% · Safe to merge
    17.4%
    Repository