Skip to content

refactor: remove dynamic seam Any typing - #284

Merged
Sinity merged 2 commits into
masterfrom
feature/refactor/dynamic-seam-contracts
Apr 21, 2026
Merged

Sinity merged 2 commits into
masterfrom
feature/refactor/dynamic-seam-contracts

Conversation

@Sinity

@Sinity Sinity commented Apr 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Remove the remaining explicit first-party Any typing from polylogue/ and devtools/ dynamic seam modules.
  • Replace loose dynamic boundaries with protocol, typed-dict, JSON document, callable, and explicit cast contracts where runtime APIs are inherently dynamic.
  • Tighten benchmark artifact rows, schema validation inputs, tree-sitter extraction, logging, click option decorators, runtime copy/update helpers, QA capture helpers, and facade console protocols.

Problem

The mypy/refactor campaign had shrunk broad typing debt, but several boundary files still encoded dynamic behavior as explicit Any. That left strict checking less meaningful exactly at the seams where provider payloads, click decorators, rich progress IDs, benchmark JSON, schema documents, and logging adapters cross typed code.

Ref #281

Solution

  • Introduced typed artifact records for benchmark campaign output and narrowed JSON payload parsing through explicit numeric helpers.
  • Reworked schema/devtools JSON handling to use JSONDocument constructors and validation helpers instead of unchecked dictionaries.
  • Replaced loose CLI/runtime surface typing with Callable[..., object], protocol-based logger/console contracts, type-only imports, and localized casts for third-party dynamic values.
  • Updated tests to assert through the same typed JSON and benchmark artifact contracts.

Verification

  • ruff format tests/unit/devtools/test_benchmark_campaign.py devtools/benchmark_campaign.py polylogue/cli/machine_main.py polylogue/cli/run_observers.py polylogue/schemas/validator.py tests/unit/core/test_schema_validation.py
  • ruff check tests/unit/devtools/test_benchmark_campaign.py devtools/benchmark_campaign.py polylogue/cli/machine_main.py polylogue/cli/run_observers.py polylogue/schemas/validator.py tests/unit/core/test_schema_validation.py
  • mypy tests/unit/core/test_schema_validation.py tests/unit/core/test_filters_schemas.py tests/unit/cli/test_run_laws.py tests/unit/cli/test_machine_main.py tests/unit/devtools/test_benchmark_campaign.py polylogue/schemas/validator.py polylogue/cli/machine_main.py polylogue/cli/run_observers.py devtools/benchmark_campaign.py
  • pytest -q tests/unit/cli/test_machine_main.py tests/unit/cli/test_qa_requests.py tests/unit/cli/test_qa_finalization.py tests/unit/cli/test_run_laws.py tests/unit/core/test_schema_validation.py tests/unit/core/test_filters_schemas.py tests/unit/core/test_code_detection.py tests/unit/devtools/test_scenario_coverage.py tests/unit/devtools/test_artifact_graph.py tests/unit/devtools/test_benchmark_campaign.py tests/unit/core/test_config.py
  • PATH=/tmp/polylogue-281/.cache/codex-bin:$PATH devtools verify --quick
  • PATH=/tmp/polylogue-281/.cache/codex-bin:$PATH git push -u origin feature/refactor/dynamic-seam-contracts

@coderabbitai

coderabbitai Bot commented Apr 21, 2026 •

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR systematically replaces loose dict[str, Any] and Any types across the codebase with stricter, more specific type contracts including JSONDocument, concrete type signatures, and typed protocols, while preserving all runtime behavior.

Changes

Cohort / File(s) Summary
JSON Document Type Narrowing
devtools/benchmark_campaign.py, devtools/scenario_coverage.py, polylogue/schemas/code_detection_extractors.py, polylogue/cli/inject_semantic_annotations.py
Replaced loose dict[str, Any]/list[dict[str, Any]] with JSONDocument types; added numeric-field validation helpers (_number_value, _float_field, _int_field) and json_document()/json_document_list() wrappers around payload structures. benchmark_campaign.py also introduced BenchmarkStatRecord and RegressionRecord TypedDicts with stricter baseline-comparison flow.
Any → object Type Narrowing
polylogue/cli/click_option_groups.py, polylogue/cli/machine_main.py, polylogue/lib/conversation_runtime.py, polylogue/schemas/validator.py, polylogue/ui/facade_console.py
Changed callable return/parameter types and mapping value types from Any to object, narrowing the declared type surface without affecting runtime logic.
Concrete Parameter Types
polylogue/cli/qa_capture.py, polylogue/cli/qa_snapshot.py
Replaced untyped Any parameters with concrete types: env: AppEnv and showcase_result: ShowcaseResult (TYPE_CHECKING-guarded import), improving call-site type safety.
Protocol Introduction & Tightening
polylogue/cli/run_observers.py, polylogue/logging.py, polylogue/schemas/code_detection_tree_sitter.py
Introduced typed protocols (_ProgressHandle → Progress/TaskID, new BoundLoggerLike, new TreeSitterNodeLike) with TYPE_CHECKING guards and runtime casts to replace broad Any and dict-based typing in structural abstractions.
Internal Logic & Helpers
polylogue/lib/filter_builder.py
Replaced cast(Any, replace) chain with direct dataclasses.replace() and # type: ignore[arg-type] annotation for dynamic keyword updates in fluent builder.
Test Updates
tests/unit/devtools/test_benchmark_campaign.py, tests/unit/core/test_schema_validation.py
Added _benchmark_record(...) test helper and normalized assertions to use json_document(...) wrappers, aligning test fixtures with the new type contracts.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 Hops with glee through types so bright,
Dict and Any now held tight!
Protocols dance, JSONDocuments gleam,
Type safety—a rabbit's dream! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 29.41% 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
Title check ✅ Passed The title 'refactor: remove dynamic seam Any typing' clearly and concisely summarizes the main change in the changeset: replacing Any typing with stricter type contracts across dynamic seam modules.
Description check ✅ Passed The PR description covers all required sections of the template: Summary explains what changed and why (removing Any typing), Problem states the necessity (strict checking at seams), Solution details the approach (protocols, TypedDicts, JSONDocument, etc.), and Verification lists exact commands run.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/refactor/dynamic-seam-contracts

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 and usage tips.

@Sinity
Sinity merged commit dd31b9d into master Apr 21, 2026
13 of 14 checks passed
@Sinity
Sinity deleted the feature/refactor/dynamic-seam-contracts branch April 21, 2026 07:28
Sinity added a commit that referenced this pull request Apr 22, 2026
## Summary
- Remove the remaining explicit first-party `Any` typing from `polylogue/` and `devtools/` dynamic seam modules.
- Replace loose dynamic boundaries with protocol, typed-dict, JSON document, callable, and explicit cast contracts where runtime APIs are inherently dynamic.
- Tighten benchmark artifact rows, schema validation inputs, tree-sitter extraction, logging, click option decorators, runtime copy/update helpers, QA capture helpers, and facade console protocols.

## Problem
The mypy/refactor campaign had shrunk broad typing debt, but several boundary files still encoded dynamic behavior as explicit `Any`. That left strict checking less meaningful exactly at the seams where provider payloads, click decorators, rich progress IDs, benchmark JSON, schema documents, and logging adapters cross typed code.

Ref #281

## Solution
- Introduced typed artifact records for benchmark campaign output and narrowed JSON payload parsing through explicit numeric helpers.
- Reworked schema/devtools JSON handling to use `JSONDocument` constructors and validation helpers instead of unchecked dictionaries.
- Replaced loose CLI/runtime surface typing with `Callable[..., object]`, protocol-based logger/console contracts, type-only imports, and localized casts for third-party dynamic values.
- Updated tests to assert through the same typed JSON and benchmark artifact contracts.

## Verification
- `ruff format tests/unit/devtools/test_benchmark_campaign.py devtools/benchmark_campaign.py polylogue/cli/machine_main.py polylogue/cli/run_observers.py polylogue/schemas/validator.py tests/unit/core/test_schema_validation.py`
- `ruff check tests/unit/devtools/test_benchmark_campaign.py devtools/benchmark_campaign.py polylogue/cli/machine_main.py polylogue/cli/run_observers.py polylogue/schemas/validator.py tests/unit/core/test_schema_validation.py`
- `mypy tests/unit/core/test_schema_validation.py tests/unit/core/test_filters_schemas.py tests/unit/cli/test_run_laws.py tests/unit/cli/test_machine_main.py tests/unit/devtools/test_benchmark_campaign.py polylogue/schemas/validator.py polylogue/cli/machine_main.py polylogue/cli/run_observers.py devtools/benchmark_campaign.py`
- `pytest -q tests/unit/cli/test_machine_main.py tests/unit/cli/test_qa_requests.py tests/unit/cli/test_qa_finalization.py tests/unit/cli/test_run_laws.py tests/unit/core/test_schema_validation.py tests/unit/core/test_filters_schemas.py tests/unit/core/test_code_detection.py tests/unit/devtools/test_scenario_coverage.py tests/unit/devtools/test_artifact_graph.py tests/unit/devtools/test_benchmark_campaign.py tests/unit/core/test_config.py`
- `PATH=/tmp/polylogue-281/.cache/codex-bin:$PATH devtools verify --quick`
- `PATH=/tmp/polylogue-281/.cache/codex-bin:$PATH git push -u origin feature/refactor/dynamic-seam-contracts`
@Sinity Sinity added area:qa QA area:schema Schema tool:claude Claude type:refactor Code restructuring labels Apr 22, 2026
Sinity added a commit that referenced this pull request Apr 22, 2026
The mypy/refactor campaign had shrunk broad typing debt, but
several boundary files still encoded dynamic behavior as explicit
`Any`. Strict checking was less meaningful exactly at the seams
where provider payloads, Click decorators, Rich progress IDs,
benchmark JSON, schema documents, and logging adapters cross typed
code.

Replaces loose dynamic boundaries with protocol, TypedDict, JSON
document, callable, and explicit cast contracts where runtime APIs
are inherently dynamic. Introduces typed artifact records for
benchmark campaign output and narrows JSON payload parsing through
explicit numeric helpers. Reworks schema/devtools JSON handling to
use `JSONDocument` constructors and validation helpers instead of
unchecked dictionaries. Replaces loose CLI/runtime surface typing
with `Callable[..., object]`, protocol-based logger/console
contracts, type-only imports, and localized casts for third-party
dynamic values. Tightens benchmark artifact rows, schema validation
inputs, tree-sitter extraction, logging, click option decorators,
runtime copy/update helpers, QA capture helpers, and facade console
protocols.

Verification: ruff + mypy + pytest over CLI, schema validation,
benchmark, and artifact-graph suites; devtools verify --quick
green.

Ref #281
Sinity added a commit that referenced this pull request Apr 22, 2026
The mypy/refactor campaign had shrunk broad typing debt, but
several boundary files still encoded dynamic behavior as explicit
`Any`. Strict checking was less meaningful exactly at the seams
where provider payloads, Click decorators, Rich progress IDs,
benchmark JSON, schema documents, and logging adapters cross typed
code.

Replaces loose dynamic boundaries with protocol, TypedDict, JSON
document, callable, and explicit cast contracts where runtime APIs
are inherently dynamic. Introduces typed artifact records for
benchmark campaign output and narrows JSON payload parsing through
explicit numeric helpers. Reworks schema/devtools JSON handling to
use `JSONDocument` constructors and validation helpers instead of
unchecked dictionaries. Replaces loose CLI/runtime surface typing
with `Callable[..., object]`, protocol-based logger/console
contracts, type-only imports, and localized casts for third-party
dynamic values. Tightens benchmark artifact rows, schema validation
inputs, tree-sitter extraction, logging, click option decorators,
runtime copy/update helpers, QA capture helpers, and facade console
protocols.

Verification: ruff + mypy + pytest over CLI, schema validation,
benchmark, and artifact-graph suites; devtools verify --quick
green.

Ref #281
Sinity added a commit that referenced this pull request Apr 22, 2026
The mypy/refactor campaign had shrunk broad typing debt, but
several boundary files still encoded dynamic behavior as explicit
`Any`. Strict checking was less meaningful exactly at the seams
where provider payloads, Click decorators, Rich progress IDs,
benchmark JSON, schema documents, and logging adapters cross typed
code.

Replaces loose dynamic boundaries with protocol, TypedDict, JSON
document, callable, and explicit cast contracts where runtime APIs
are inherently dynamic. Introduces typed artifact records for
benchmark campaign output and narrows JSON payload parsing through
explicit numeric helpers. Reworks schema/devtools JSON handling to
use `JSONDocument` constructors and validation helpers instead of
unchecked dictionaries. Replaces loose CLI/runtime surface typing
with `Callable[..., object]`, protocol-based logger/console
contracts, type-only imports, and localized casts for third-party
dynamic values. Tightens benchmark artifact rows, schema validation
inputs, tree-sitter extraction, logging, click option decorators,
runtime copy/update helpers, QA capture helpers, and facade console
protocols.

Verification: ruff + mypy + pytest over CLI, schema validation,
benchmark, and artifact-graph suites; devtools verify --quick
green.

Ref #281
@Sinity

Sinity commented May 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Sinity
Sinity requested review from Copilot and removed request for Copilot May 1, 2026 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant