Skip to content

code-metrics: measure same-named modules under hyphenated directories instead of leaving the Python lane unavailable #4123

Closed

Description

@kyle-sexton

This was generated by AI during a consumer-repo exercise of the skill.

Refs #3848, #4064

Context

audit-type-debt runs mypy with --explicit-package-bases so that a file vendored into several plugins (sanctioned replication) is named by its path and measured once per copy. mypy's module walk (find_sources.py, crawl_up, read at 1.19.1) stops at the first directory whose name is not a Python identifier, so two same-named files under two hyphenated directories (my-pkg/mod.py and other-pkg/mod.py) still both derive the bare name mod and collide. mypy exits 2 with Duplicate module named "mod", and the collector turns that into the adapter contract's exit 4: the Python run row reads unavailable with mypy's message, no percentage is reported, and the run continues. The Gotchas in the skill body say so.

That is honest, but it measures nothing for the whole lane because of two files. This repository does not hit the case today (its replicated files sit under identifier-named lib/ and hooks/ directories inside hyphenated plugin directories, which mypy names by their path), so the cost is borne by consumers whose layout puts same-named modules directly under hyphenated directories, for example a monorepo of service-a/main.py, service-b/main.py.

Options the interview surfaced, none chosen yet:

  • Detect the collision before running mypy (derive each scope file's mypy name with the collector's own module_name, which already re-derives crawl_up), then run mypy once per collision-free partition and sum the file rows. Per-file rows exist since 0.3.0, so attribution is by file, not by module name.
  • Run mypy once per colliding group with the group's parent as MYPYPATH or with --explicit-package-bases plus a synthetic base, so each copy is named by a distinct path. Needs verification that mypy accepts a non-identifier base component in that mode.
  • Report the collision as a partial: measure the non-colliding files, list the colliding ones in the run row's reason, and label the lane row partial. Cheapest, and still never a false percentage.

Proposed work

  • Decide between the three options above (a /planning:interview round; the third is the recommended floor because it keeps the never-a-false-number rule with the least new machinery).
  • Implement the chosen option in scripts/collectors/mypy-report.py, keeping the exit-4 unavailable path for any other mypy fatal error.
  • Add a fixture that reproduces the collision with the real mypy (two hyphenated directories, one same-named module each) and a test for the chosen behaviour.
  • Update the audit-type-debt Gotchas so the hyphenated-directory bullet states the new behaviour instead of the collision.

Acceptance criteria

  • A scope containing a-dir/mod.py and b-dir/mod.py produces a Python lane row with expressions_total > 0 rather than an unavailable row.
  • Every file the run measured has its own file row; any file the run could not measure is named in the run row's reason and the lane row is labelled partial.
  • Any other mypy exit 2 (a usage or config error) still reaches the exit-4 unavailable row with mypy's message.
  • The fixture is a real mypy capture and the test runs against it; scripts/affected-tests.sh --run selects and passes the suite.
  • The skill body's Gotchas describe the shipped behaviour and carry no reference to the earlier collision.

References

Metadata

Field Value
Category enhancement
Area code-metrics / audit-type-debt / mypy-report collector
Ecosystem python

Activity

  1. added
    needs-triage
    on Sep 12, 2026
  2. added
    agent-ready
    status: ready
    and removed
    needs-triage
    on Sep 23, 2026
  3. kyle-sexton commented on Sep 23, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during triage.

    Decision defaulted: option 3 (report partial, list colliding files, keep never-a-false-number rule; issue's own "recommended floor") — veto before merge

  4. changed the issue type fromtoon Sep 23, 2026
  5. kyle-sexton commented on Sep 23, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during triage.

    Agent Brief

    Type: Bug
    Summary: Report a partial result instead of an unavailable lane when two same-named Python modules under different hyphenated directories collide during type-debt measurement.

    Current behavior:
    The type-debt audit's Python lane runs mypy with a package-bases mode so a file vendored into multiple plugins (sanctioned replication) is named by its path and measured once per copy. mypy's own module-naming walk stops at the first directory whose name is not a valid identifier, so two files sharing a base name under two different hyphenated directories still resolve to the same bare module name and collide. When that happens, mypy exits with a duplicate-module error, and the whole Python lane's row is reported as unavailable with mypy's message: no coverage percentage and no file rows for anything measured in that run, even files that never collided.

    Desired behavior:
    Defaulted decision: report a partial result (recommended as the cheapest option that keeps the never-report-a-false-number rule with no new machinery). Maintainer-vetoable alternative: detect the collision before running the tool and measure each collision-free group in a separate run, or run the tool once per colliding group with a synthetic path-based base so each copy resolves to a distinct name.
    When a name collision is detected, the Python lane reports every non-colliding file's own measured row, names the colliding files in the run row's reason, and labels the lane row partial rather than unavailable. A coverage percentage is never fabricated for a colliding file; only files the tool could actually measure get one. Any other tool fatal error unrelated to a name collision (a usage or configuration error) still produces the existing unavailable lane row with the tool's message, unchanged.

    Key interfaces:

    • The Python lane collector's file-collection entry point and its existing fatal-exit-to-unavailable mapping — extended with a partial outcome for the collision case specifically, not a replacement of the existing path
    • The collector's own module-name re-derivation logic (the identifier-directory walk it already uses to match mypy's naming rule) — reused to detect or attribute a collision
    • The lane row's partial label and its reason field, which must name every file the run could not measure

    Acceptance criteria:

    • A scope containing two same-named module files under two different hyphenated directories produces a Python lane row with a coverage total greater than zero rather than an unavailable row.
    • Every file the run successfully measured has its own file row in the output.
    • Every file the run could not measure due to the name collision is named in the run row's reason, and the lane row is labeled partial.
    • A tool fatal error unrelated to a duplicate-module collision (a usage or configuration error) still produces the existing unavailable lane row carrying the tool's message.
    • The type-debt audit's documented caveats describe the shipped partial-reporting behavior for hyphenated-directory collisions rather than describing the case as unmeasurable.

    Out of scope:

    • Changing mypy's own module-naming algorithm or working around it via a non-default naming mode
    • Any change to coverage measurement for the Bash, Go, or TypeScript/JavaScript lanes
    • Adding a general recommendation or lint against hyphenated directory names
  6. kyle-sexton commented on Sep 29, 2026

    @kyle-sexton
    MemberAuthor

    From the 2026-09-29 audit of the Cursor run. This issue stays closed; recording a gap in what closed it.

    AC3 asked for the lane row to be labelled partial. PR #4765 marked only the run row partial (dispatch.sh:686-687) and left the lane-total row unlabeled.

    Fix: #5308 adds the partial label to the lane-total row when held_out is non-empty (mypy-report.py, report-schema.md, audit-type-debt SKILL.md, tests). With that, all five ACs are met on the branch. #5308 uses Refs #4123 because the issue is already closed.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readystatus: ready

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions