Skip to content

build(pyright): strict-check the pure modules (#245 Stage 2)#268

Merged
pbean merged 2 commits into
mainfrom
feat/pyright-strict-pure-245
Jul 23, 2026
Merged

build(pyright): strict-check the pure modules (#245 Stage 2)#268
pbean merged 2 commits into
mainfrom
feat/pyright-strict-pure-245

Conversation

@pbean

@pbean pbean commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

Stage 2 of #245 (assessment F-4), the follow-up to the basic-mode gate that landed in #264. Adds the seven pure/leaf modules to pyright's strict list so the domain core is held to strict analysis while the I/O-heavy modules stay basic:

model.py, statemachine.py, policy.py, documents.py, machine.py, checks.py, sanitize.py

strict overrides typeCheckingMode for those paths only — the same effect as a per-file # pyright: strict comment (verified against the 1.1.411 docs, the version CI pins). No runtime behaviour changes in this PR: annotations, config, and suppressions only.

What the gate caught (and how it's resolved)

The spike surfaced 77 strict findings. Breakdown and disposition:

  • Genuine annotation fixes (source):

    • checks.Finding.detail and ValidationReport.{add,ok,warn,fail} were bare dictMapping[str, object]. Mapping (covariant in its value type) is deliberate so install.py's dict[str, str] detail dicts stay assignable under basic mode; dict[str, object] would have tripped invariance there.
    • documents.validate_document return dictdict[str, object]; status_document's local tasks list annotated.
    • statemachine.py comes back strict-clean with zero changes.
  • Irreducible boundary / idiom noise (suppressed precisely): three of the seven modules reconstruct typed objects from loosely-typed persisted data — json/tomllib hand back dict[str, Any], and isinstance-narrowing an Any yields dict[Unknown, Unknown] — or use the idiomatic field(default_factory=list|dict) that pyright can only infer as [Unknown]. These fire the three "expression fully known" rules (reportUnknown{Member,Argument,Variable}Type) on correct code. Clearing them would take a TypedDict per persisted shape or runtime coercions — out of scope for a no-runtime-change gate. So:

    • policy.py / model.py / sanitize.py / checks.py relax only those specific rules via a documented file-level # pyright: pragma. Those rules are off in basic mode already, so the pragma is a no-op for every non-strict file.
    • machine.py's single stdlib-stub gap (TextIO.reconfigure) keeps a targeted inline # pyright: ignore, written in black's wrapped form so the suppression stays on the flagged token line.
    • Every other strict rule (missing param/return types, bare generics, unnecessary comparisons, inconsistent constructors, deprecated APIs, …) stays on — a positive control confirms an untyped function in a strict module is still rejected.

Verification

  • uvx pyright@1.1.4110 errors, 0 warnings (matches the pinned CI runner).
  • trunk check → clean. Formatting is black-stable (re-running trunk fmt is a no-op; the two trailing-ignore lines were reworked so black's wrap doesn't relocate them off the flagged token).
  • Full suite: 2766 passed, 1 skipped. The 2 test_module_skills_sync failures are the pre-existing local-only drift (gitignored .agents/.claude install copies at module_version 0.8.1 vs canonical 0.9.0); they touch nothing this PR changes and are absent on a fresh CI checkout.

Completes #245.

Summary by CodeRabbit

  • Quality Improvements

    • Enhanced static type checking across core validation, document, policy, and data-processing components.
    • Added more precise type definitions for validation details and generated document data.
    • Applied targeted checks and exceptions to improve analysis of dynamic configuration and JSON data.
  • Compatibility

    • No runtime behavior or package functionality has changed.

Stage 2 of #245 (assessment F-4): add the seven pure/leaf modules —
model, statemachine, policy, documents, machine, checks, sanitize — to
pyright's `strict` list so the domain core is held to strict analysis
while the I/O-heavy modules stay basic. `strict` overrides
typeCheckingMode per path (same effect as a per-file `# pyright: strict`
comment), verified against the 1.1.411 docs and pinned CI runner.

No runtime changes — annotations, config, and suppressions only:

- checks.Finding.detail / ValidationReport.{add,ok,warn,fail}: bare `dict`
  -> `Mapping[str, object]` (covariant, so install.py's dict[str,str]
  detail dicts stay assignable under basic mode).
- documents.validate_document -> dict[str, object]; status_document's
  local `tasks` list annotated.
- statemachine.py comes back strict-clean with zero changes.

Three of the seven parse loosely-typed persisted data (json/tomllib hand
back dict[str, Any]; isinstance-narrowing an Any yields dict[Unknown,
Unknown]) or use the `field(default_factory=list|dict)` idiom pyright can
only infer as `[Unknown]`. Those surface the three "expression fully
known" rules on correct code at that boundary; clearing them would need a
TypedDict per persisted shape or runtime coercions, out of scope here. So
policy/model/sanitize/checks relax only those specific rules via a
documented file-level pragma (a no-op in basic mode, where they are off),
and machine's one stdlib-stub gap (TextIO.reconfigure) keeps a targeted
inline ignore. Every other strict rule stays on and still catches drift.
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 40 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3d114391-866b-482c-ad11-03160455035d

📥 Commits

Reviewing files that changed from the base of the PR and between 0055af6 and cd62995.

📒 Files selected for processing (1)
  • tests/test_cli.py

Walkthrough

Pyright strict checking is enabled for selected core modules. Public detail payloads and document return values receive precise container types, while local directives relax diagnostics at known dynamic boundaries. Runtime behavior remains unchanged.

Changes

Strict typing configuration and annotations

Layer / File(s) Summary
Strict module coverage
pyproject.toml
Adds a Pyright strict module list for selected core and domain files while retaining basic checking elsewhere.
Core module typing adjustments
src/bmad_loop/checks.py, src/bmad_loop/documents.py, src/bmad_loop/model.py, src/bmad_loop/policy.py, src/bmad_loop/sanitize.py, src/bmad_loop/machine.py
Uses parameterized mappings, dictionaries, and task lists in public and local annotations, and adds targeted Pyright overrides for dynamic data and stdout handling.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • bmad-code-org/bmad-loop#264: Earlier Pyright rollout that this change extends with per-module strict coverage and related annotations.

Suggested reviewers: dracic

Poem

I’m a rabbit who checks types by moonlight,
Mapping each detail neat and right.
Strict paths bloom across the code,
Unknown leaves take a gentler road.
Hop, hop—clean annotations grow!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: expanding Pyright strict checking for the pure modules in Stage 2.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/pyright-strict-pure-245

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/bmad_loop/checks.py`:
- Line 91: Normalize Finds.detail to JSON-compatible plain dict and nested
values before validate --json reaches machine.emit(), rather than passing
arbitrary Mapping objects unchanged from validate_document. Update the emission
path around machine.emit() to recursively convert supported mappings and
containers into standard JSON-serializable structures while preserving existing
detail content.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a1368931-1f08-456f-88c0-d7aa2b5a29ff

📥 Commits

Reviewing files that changed from the base of the PR and between cd12526 and 0055af6.

📒 Files selected for processing (7)
  • pyproject.toml
  • src/bmad_loop/checks.py
  • src/bmad_loop/documents.py
  • src/bmad_loop/machine.py
  • src/bmad_loop/model.py
  • src/bmad_loop/policy.py
  • src/bmad_loop/sanitize.py

Comment thread src/bmad_loop/checks.py
CodeRabbit on #268 flagged that widening `Finding.detail` to
`Mapping[str, object]` could let `validate --json` fail on a non-JSONable
detail. No caller exercises that, and the prior bare `dict` (= dict[Any, Any])
was already equally permissive of nested non-JSONable values, so this is a
regression-guard rather than a fix: it drives the exact production path
`machine.emit(validate_document(...))` with every detail shape the real gates
attach (str values, the nested `dict(role_names)` dict, str+int, install.py's
`{**detail, "marker": ...}`, and the `detail=None` leg) and asserts the whole
document still parses and each value survives.
@pbean
pbean merged commit b836830 into main Jul 23, 2026
10 checks passed
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