Skip to content

[EPIC] Enforce mypy Type Safety in CI #429

Closed
4 of 4 issues completed
Closed

Description

@squid-protocol

🛑 Problem Statement

We previously root-caused several producer/consumer bugs (#364, #374, #375, and the rest of the #325 dead-key-auditor epic) where a consumer read a dict key the producer never wrote, or wrote under a different name. Investigated whether mypy in CI would have caught that class of bug: mostly no -- the affected structures (domain_context, ghost_meta, equations, APERTURE_CONFIG) are typed as Dict[str, Any] / Dict[str, int], under which d["AI Threat Score"] and d["AI Threat Confidence"] are equally valid to mypy. tests/dead_key_audit.py (already built and wired into CI) is the better-fit tool for that specific bug class.

That said, mypy still has real, independent value -- catching None-handling bugs, wrong argument types, incompatible return types -- and there's evidence of a prior ad hoc mypy cleanup pass in the git history (#293-#301) that was never wired into CI as an enforced gate, so it's drifted since.

📊 Current State (measured, not estimated)

Ran mypy gitgalaxy/ --ignore-missing-imports against current main:

235 errors across 31 files. Heavily concentrated: 5 files (signal_processor.py 60, record_keeper.py 48, language_lens.py 27, prism.py 27, detector.py 27) account for ~80% of the total.

Significant fan-out from a small number of root causes rather than 235 independent problems -- e.g. RECORDING_SCHEMAS dict values are typed as Collection[str] instead of List[str], which alone produces dozens of cascading "Collection[str]" has no attribute "index" errors across multiple files.

By error code:

Code Count Nature
attr-defined 80 Mostly the Collection[str]/.index() fan-out above
var-annotated 36 Missing annotations on empty containers -- mechanical
operator 23 Mostly "object" types from unannotated heterogeneous dict literals
assignment 22 Mixed -- some look like real bugs (e.g. None assigned to a float-typed var)
arg-type 18 Mixed
index 15 Mixed
return-value 13 Mixed
call-overload 12 Cascades from the operator/object root cause
misc / union-attr / other 16 Long tail

🎯 Objective

Wire mypy into CI as a baseline-gated check (same pattern as dead_key_audit.py -- fails only on new errors, doesn't demand the existing 235 be fixed on day one), then work down the baseline in reviewable chunks, prioritizing root causes with high fan-out first.

📋 Sub-Issues

Sub-issues

Sub-issues

4 of 4 Issues completed
Loading 4 sub-issues

Activity

  1. added
    python
    epic
    refactor
    on Jul 25, 2026
  2. squid-protocol commented on Jul 25, 2026

    @squid-protocol
    OwnerAuthor

    Status update: #430 and #431 done and closed. #432 (core engine) is 2/5 files cleared; #433 (long tail) has 2 incidental files cleared, otherwise not started.

    Overall: 228 → 126 unique mypy errors (45% reduction) since this epic started, all verified via the now-live `mypy-audit.yml` gate rather than estimated. Sequencing continues one file per session, largest-remaining-file first: `signal_processor.py` (22) and `detector.py` (18) are next up.

  3. added a commit that references this issue on Jul 25, 2026
  4. squid-protocol commented on Jul 25, 2026

    @squid-protocol
    OwnerAuthor

    Epic complete. `mypy gitgalaxy/ --ignore-missing-imports` went from 228 (as first seeded into tests/mypy_audit_baseline.json) to 0.

    Summary

    Was it just cosmetic?

    Mostly, but not entirely -- a handful of genuine (if mostly latent, non-currently-manifesting) bugs turned up along the way, each called out explicitly in its PR rather than silently annotated away:

    • `galaxyscope.py`: `import importlib` missing the `.util` submodule import it implicitly depended on.
    • `language_lens.py`'s `_find_balanced_end`: an un-cast float passed to `range()`, which would `TypeError` at runtime.
    • `manifest_parser.py`'s `locate_physical_package()`: declared to return `Path`, but 6 of its branches legitimately return `None` -- the signature was simply wrong, not the callers.
    • `llm_recorder.py`'s `_build_markdown()`: two variable-name collisions across one large (~1100-line) function, plus a missing `.get("path", "")` default that could have produced a `Path(None)` crash.
    • `spatial_mapper.py`: a `for b in bins_to_check` loop variable reused a few lines later for an unrelated quadratic-formula coefficient.

    All 16 PRs (#438 onward through #467) were individually verified: full `mypy` run (fresh cache, CI-matching minimal venv) with fan-out check, `flake8`, `dead_key_audit.py --ci`, full `pytest` suite (866 tests), and live CI (including the new `mypy-audit` gate itself) before merge.

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

    epicpythonrefactor

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions