Add a mypy typecheck gate - retro finding from wave 1 #10

Closed
opened 2026-11-24 00:09:20 +00:00 by alex · 3 comments
Owner

Retro motivation (2026-11-23)

During the wave-1 merge, git auto-merged two branches into semantically broken test calls (settings= after the options refactor); only merger diligence + per-merge gates caught it. The retro asked what would have caught that class mechanically: a type checker. The repo mandates full type hints (CONTRACTS.md 1.1) but nothing checks them.

Measurement on arch-deepening @ 83a4785 (2026-11-23, uv run --with mypy mypy src/): 25 errors in 10 files — and they split into telling categories:

  • Pre-existing real bugs: doctor.py:250 assigns a bool to a list[str] variable; pipeline.py:507 passes Transcript | None where a Transcript is required; synthesis.py:841/844 reuse an AgentRunResult[ChunkCore] where ReportCore is expected; vision.py:382 matches no Agent overload (investigate — possibly a genuine call-shape bug).
  • Wave-1 signature drift that all three gates missed: vision.py:318/321/380/383 and synthesis.py:766 pass DescribeOptions/ReportOptions where llama_server_up/build_model expect Settings; config.py:157/167/182 misuse the StageOptions union; pipeline.py:516 calls model_copy on it.
  • Untyped third-parties (config, not code): sherpa_onnx, pyannote.audio, faster_whisper missing stubs.
  • Trivial: mcp_server.py:377 needs an annotation; mcp_server.py:1073 transport Literal.

A second measurement on main @ d93c464 found 16 errors — wave 1 added 9 while green on ruff + format + pytest. That is the case for the gate.

Proposed design

  1. uv add --dev mypy (pyproject.toml is a foundation file — this issue is the reviewed record per ADR-0001).
  2. [tool.mypy] in pyproject: scope src/, python_version = "3.13"; per-module ignore_missing_imports overrides ONLY for genuinely untyped third-parties (each with a one-line comment naming the library). No global ignore_missing_imports.
  3. Fix the real errors — fix, not silence. Where behaviour is visible, add a test (doctor bool/list, the None-guard). # type: ignore only with an inline reason.
  4. Add the gate to .pi/verify.json: { "name": "typecheck", "command": "uv run mypy src/", "on_settle": true }.

Acceptance criteria

  • uv run mypy src/ → zero errors on arch-deepening tip
  • The real-bug list above is fixed (or, where an "error" turns out to be mypy wrong about a dynamic-by-design call, documented inline and narrowed precisely)
  • Behaviour-visible fixes carry tests
  • .pi/verify.json has 4 gates, all green: lint, format, tests, typecheck
  • Existing tests stay green (373 passed / 2 skipped baseline at time of filing)

Sequencing

Land after issue #6 (both touch doctor.py and pipeline.py; #6's rewrite of _stt_model_checks settles that file first — re-measure after it merges) and before #8/#9: the typecheck gate then protects the two largest refactors of the effort (descriptor table, analysis module). Re-measure on your base when you start; the inventory above is the 2026-11-23 snapshot and will shift after #6.

## Retro motivation (2026-11-23) During the wave-1 merge, git auto-merged two branches into *semantically* broken test calls (`settings=` after the options refactor); only merger diligence + per-merge gates caught it. The retro asked what would have caught that class mechanically: a type checker. The repo mandates full type hints (CONTRACTS.md 1.1) but nothing checks them. Measurement on arch-deepening @ `83a4785` (2026-11-23, `uv run --with mypy mypy src/`): **25 errors in 10 files** — and they split into telling categories: - **Pre-existing real bugs**: `doctor.py:250` assigns a `bool` to a `list[str]` variable; `pipeline.py:507` passes `Transcript | None` where a `Transcript` is required; `synthesis.py:841/844` reuse an `AgentRunResult[ChunkCore]` where `ReportCore` is expected; `vision.py:382` matches no `Agent` overload (investigate — possibly a genuine call-shape bug). - **Wave-1 signature drift that all three gates missed**: `vision.py:318/321/380/383` and `synthesis.py:766` pass `DescribeOptions`/`ReportOptions` where `llama_server_up`/`build_model` expect `Settings`; `config.py:157/167/182` misuse the `StageOptions` union; `pipeline.py:516` calls `model_copy` on it. - **Untyped third-parties** (config, not code): `sherpa_onnx`, `pyannote.audio`, `faster_whisper` missing stubs. - **Trivial**: `mcp_server.py:377` needs an annotation; `mcp_server.py:1073` transport `Literal`. A second measurement on main @ `d93c464` found 16 errors — wave 1 added 9 while green on ruff + format + pytest. That is the case for the gate. ## Proposed design 1. `uv add --dev mypy` (pyproject.toml is a foundation file — this issue is the reviewed record per ADR-0001). 2. `[tool.mypy]` in pyproject: scope `src/`, `python_version = "3.13"`; per-module `ignore_missing_imports` overrides ONLY for genuinely untyped third-parties (each with a one-line comment naming the library). No global `ignore_missing_imports`. 3. Fix the real errors — fix, not silence. Where behaviour is visible, add a test (doctor bool/list, the None-guard). `# type: ignore` only with an inline reason. 4. Add the gate to `.pi/verify.json`: `{ "name": "typecheck", "command": "uv run mypy src/", "on_settle": true }`. ## Acceptance criteria - [ ] `uv run mypy src/` → zero errors on arch-deepening tip - [ ] The real-bug list above is fixed (or, where an "error" turns out to be mypy wrong about a dynamic-by-design call, documented inline and narrowed precisely) - [ ] Behaviour-visible fixes carry tests - [ ] `.pi/verify.json` has 4 gates, all green: lint, format, tests, typecheck - [ ] Existing tests stay green (373 passed / 2 skipped baseline at time of filing) ## Sequencing Land **after issue #6** (both touch doctor.py and pipeline.py; #6's rewrite of `_stt_model_checks` settles that file first — re-measure after it merges) and **before #8/#9**: the typecheck gate then protects the two largest refactors of the effort (descriptor table, analysis module). Re-measure on your base when you start; the inventory above is the 2026-11-23 snapshot and will shift after #6.
alex added the ready-for-agentenhancement labels 2026-11-24 00:09:20 +00:00
Author
Owner

Fresh measurement after wave 2 (arch-deepening @ 434745d, #6 landed): 35 errors in 10 files — #6's protocol work surfaced ~10 more sites. The error classes in the issue body still hold. Re-measure on your base when you start.

Fresh measurement after wave 2 (arch-deepening @ 434745d, #6 landed): 35 errors in 10 files — #6's protocol work surfaced ~10 more sites. The error classes in the issue body still hold. Re-measure on your base when you start.
Author
Owner

Implemented on arch-deepening in d94188e (mypy 2.4.1 dev dep; [tool.mypy] with five named per-module overrides; 29 sites fixed, 0 type: ignore; 4th gate in .pi/verify.json) + trailing docs in 799a810 (AGENTS.md/CONTRACTS.md describe the four-gate set). Gates 4/4 on the branch — 400 passed / 2 skipped, mypy clean on 22 files. Closes when arch-deepening merges to main.

Implemented on arch-deepening in d94188e (mypy 2.4.1 dev dep; [tool.mypy] with five named per-module overrides; 29 sites fixed, 0 `type: ignore`; 4th gate in .pi/verify.json) + trailing docs in 799a810 (AGENTS.md/CONTRACTS.md describe the four-gate set). Gates 4/4 on the branch — 400 passed / 2 skipped, mypy clean on 22 files. Closes when arch-deepening merges to main.
alex closed this issue 2026-11-24 13:04:41 +00:00
Author
Owner

Merged to main in 37ef5e5 (arch-deepening): d94188e + 799a810 - the mypy typecheck gate as the 4th gate (35 errors -> 0, zero type: ignore, five named third-party overrides); AGENTS.md/CONTRACTS.md describe the four-gate set naming no count.

Merged to main in 37ef5e5 (arch-deepening): d94188e + 799a810 - the mypy typecheck gate as the 4th gate (35 errors -> 0, zero type: ignore, five named third-party overrides); AGENTS.md/CONTRACTS.md describe the four-gate set naming no count.
Sign in to join this conversation.