Skip to content

refactor: split query stats route helpers - #305

Merged
Sinity merged 3 commits into
masterfrom
feature/refactor/query-route-dispatch
Apr 21, 2026
Merged

Sinity merged 3 commits into
masterfrom
feature/refactor/query-route-dispatch

Conversation

@Sinity

@Sinity Sinity commented Apr 21, 2026

Copy link
Copy Markdown
Owner

Summary

  • Extracts query stats route helper functions from the main query execution branch chain.
  • Centralizes stats dimension fallback and summary-vs-query-backed summary loading for semantic/profile grouped stats.
  • Keeps existing route behavior and output calls intact.

Problem

polylogue/cli/query.py repeated summary loading and query-plan fallback logic across semantic and profile stats routes. The main execution function was doing orchestration plus low-level route bookkeeping inline, which made it harder to reason about branch equivalence.

Solution

  • Add a typed QueryExecutionStore protocol for the combined repository surface used by query execution.
  • Add _stats_dimension, _semantic_stats_summaries, and _profile_stats_summaries helpers.
  • Replace duplicated route branches with helper calls while preserving fallback to hydrated conversation stats when action-event-backed stats are unavailable.

Ref #270

Verification

  • ruff format polylogue/cli/query.py
  • ruff check polylogue/cli/query.py
  • mypy polylogue/cli/query.py tests/unit/cli/test_query_exec_laws.py tests/unit/cli/test_query_exec.py
  • pytest -q tests/unit/cli/test_query_exec_laws.py tests/unit/cli/test_query_exec.py -k 'stats_by or route or query_route or semantic or profile'
  • push hook: devtools verify --quick

@coderabbitai

coderabbitai Bot commented Apr 21, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 04d6a06b-3d61-4e83-bfbf-2d1dd84beb25

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/refactor/query-route-dispatch

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 force-pushed the feature/refactor/query-output-formatting branch from 89c5957 to 656b998 Compare April 21, 2026 14:39
@Sinity
Sinity force-pushed the feature/refactor/query-route-dispatch branch from 8dd8628 to 94927b4 Compare April 21, 2026 14:41
Base automatically changed from feature/refactor/query-output-formatting to master April 21, 2026 16:50
@Sinity
Sinity merged commit 6acf186 into master Apr 21, 2026
3 checks passed
@Sinity
Sinity deleted the feature/refactor/query-route-dispatch branch April 21, 2026 16:50
Sinity added a commit that referenced this pull request Apr 22, 2026
## Summary
- Extracts query stats route helper functions from the main query execution branch chain.
- Centralizes stats dimension fallback and summary-vs-query-backed summary loading for semantic/profile grouped stats.
- Keeps existing route behavior and output calls intact.

## Problem
`polylogue/cli/query.py` repeated summary loading and query-plan fallback logic across semantic and profile stats routes. The main execution function was doing orchestration plus low-level route bookkeeping inline, which made it harder to reason about branch equivalence.

## Solution
- Add a typed `QueryExecutionStore` protocol for the combined repository surface used by query execution.
- Add `_stats_dimension`, `_semantic_stats_summaries`, and `_profile_stats_summaries` helpers.
- Replace duplicated route branches with helper calls while preserving fallback to hydrated conversation stats when action-event-backed stats are unavailable.

Ref #270

## Verification
- `ruff format polylogue/cli/query.py`
- `ruff check polylogue/cli/query.py`
- `mypy polylogue/cli/query.py tests/unit/cli/test_query_exec_laws.py tests/unit/cli/test_query_exec.py`
- `pytest -q tests/unit/cli/test_query_exec_laws.py tests/unit/cli/test_query_exec.py -k 'stats_by or route or query_route or semantic or profile'`
- push hook: `devtools verify --quick`
Sinity added a commit that referenced this pull request Apr 22, 2026
## Summary
- Replace the schema-local JSON alias module with the canonical runtime JSON contract in polylogue.lib.json.
- Update schema, MCP, surface, CLI, and test imports to use the canonical JSON types and coercion helpers.
- Tighten readiness, repair, maintenance, and check-command machine payloads to return canonical JSONDocument values.
- Remove polylogue/schemas/json_types.py so new schema code cannot drift back to the unsafe cast-only helper.

## Problem
- The codebase carried two JSON helper modules: polylogue.lib.json, which validates JSON values at runtime, and polylogue.schemas.json_types, which duplicated the type aliases but used cast-only coercion.
- That split made schema code depend on a weaker, path-dependent contract and left check/maintenance JSON renderers with object-shaped payloads instead of explicit JSON contracts.

## Solution
- Standardize internal imports on polylogue.lib.json across the schema/tooling/tests surface.
- Convert readiness, repair, maintenance, and check rendering payload outputs to canonical JSONDocument coercion.
- Delete the duplicate schema-local helper module instead of keeping a compatibility wrapper.

## Verification
- ruff check polylogue tests/infra tests/unit
- mypy polylogue tests/infra tests/unit
- pytest -q tests/unit/core/test_schema_laws.py tests/unit/core/test_schema_registry.py tests/unit/core/test_schema_cluster_assignment.py tests/unit/core/test_schema_annotation_contracts.py tests/unit/pipeline/test_prepare_semantic.py tests/unit/pipeline/test_run_sources.py tests/unit/sources/test_source_laws.py tests/unit/sources/test_drive_ops.py
- mypy polylogue/maintenance_models.py polylogue/readiness.py polylogue/storage/repair.py polylogue/cli/check_models.py polylogue/cli/check_rendering_json.py
- pytest -q tests/unit/cli/test_check.py tests/unit/storage/test_repair.py tests/unit/core/test_health_core.py tests/unit/core/test_maintenance_targets.py
- git push hook: devtools verify --quick

Stacked on #305. Ref #300.
@Sinity Sinity added area:cli CLI tool:claude Claude type:refactor Code restructuring labels Apr 22, 2026
Sinity added a commit that referenced this pull request Apr 22, 2026
`cli/query.py` repeated summary loading and query-plan fallback
logic across semantic and profile stats routes. The main execution
function was doing orchestration plus low-level route bookkeeping
inline, which made branch equivalence harder to reason about.

Extracts stats route helper functions from the main query execution
branch chain. Centralizes stats dimension fallback and
summary-vs-query-backed summary loading for semantic/profile
grouped stats. Adds a typed `QueryExecutionStore` protocol for the
combined repository surface used by query execution; adds
`_stats_dimension`, `_semantic_stats_summaries`, and
`_profile_stats_summaries` helpers. Replaces duplicated route
branches with helper calls while preserving fallback to hydrated
conversation stats when action-event-backed stats are unavailable.

Verification: ruff + mypy + pytest over query-exec / query-exec-laws
stats/route/semantic/profile coverage; devtools verify --quick
green.

Ref #270
Sinity added a commit that referenced this pull request Apr 22, 2026
The codebase carried two JSON helper modules: `polylogue.lib.json`
validates JSON values at runtime, while `polylogue.schemas.json_types`
duplicated the type aliases but used cast-only coercion. Schema
code depended on a weaker, path-dependent contract, and
check/maintenance JSON renderers carried object-shaped payloads
instead of explicit JSON contracts.

Standardizes internal imports on `polylogue.lib.json` across the
schema / tooling / tests surface. Updates schema, MCP, surface,
CLI, and test imports to use the canonical JSON types and coercion
helpers. Tightens readiness, repair, maintenance, and check-command
machine payloads to return canonical `JSONDocument` values.
Deletes `polylogue/schemas/json_types.py` so new schema code cannot
drift back to the unsafe cast-only helper (no compatibility
wrapper).

Verification: ruff + mypy + pytest over schema / pipeline / source /
check / repair / health-core / maintenance-targets suites; devtools
verify --quick green.

Stacked on #305. Ref #300
Sinity added a commit that referenced this pull request Apr 22, 2026
`cli/query.py` repeated summary loading and query-plan fallback
logic across semantic and profile stats routes. The main execution
function was doing orchestration plus low-level route bookkeeping
inline, which made branch equivalence harder to reason about.

Extracts stats route helper functions from the main query execution
branch chain. Centralizes stats dimension fallback and
summary-vs-query-backed summary loading for semantic/profile
grouped stats. Adds a typed `QueryExecutionStore` protocol for the
combined repository surface used by query execution; adds
`_stats_dimension`, `_semantic_stats_summaries`, and
`_profile_stats_summaries` helpers. Replaces duplicated route
branches with helper calls while preserving fallback to hydrated
conversation stats when action-event-backed stats are unavailable.

Verification: ruff + mypy + pytest over query-exec / query-exec-laws
stats/route/semantic/profile coverage; devtools verify --quick
green.

Ref #270
Sinity added a commit that referenced this pull request Apr 22, 2026
The codebase carried two JSON helper modules: `polylogue.lib.json`
validates JSON values at runtime, while `polylogue.schemas.json_types`
duplicated the type aliases but used cast-only coercion. Schema
code depended on a weaker, path-dependent contract, and
check/maintenance JSON renderers carried object-shaped payloads
instead of explicit JSON contracts.

Standardizes internal imports on `polylogue.lib.json` across the
schema / tooling / tests surface. Updates schema, MCP, surface,
CLI, and test imports to use the canonical JSON types and coercion
helpers. Tightens readiness, repair, maintenance, and check-command
machine payloads to return canonical `JSONDocument` values.
Deletes `polylogue/schemas/json_types.py` so new schema code cannot
drift back to the unsafe cast-only helper (no compatibility
wrapper).

Verification: ruff + mypy + pytest over schema / pipeline / source /
check / repair / health-core / maintenance-targets suites; devtools
verify --quick green.

Stacked on #305. Ref #300
Sinity added a commit that referenced this pull request Apr 22, 2026
`cli/query.py` repeated summary loading and query-plan fallback
logic across semantic and profile stats routes. The main execution
function was doing orchestration plus low-level route bookkeeping
inline, which made branch equivalence harder to reason about.

Extracts stats route helper functions from the main query execution
branch chain. Centralizes stats dimension fallback and
summary-vs-query-backed summary loading for semantic/profile
grouped stats. Adds a typed `QueryExecutionStore` protocol for the
combined repository surface used by query execution; adds
`_stats_dimension`, `_semantic_stats_summaries`, and
`_profile_stats_summaries` helpers. Replaces duplicated route
branches with helper calls while preserving fallback to hydrated
conversation stats when action-event-backed stats are unavailable.

Verification: ruff + mypy + pytest over query-exec / query-exec-laws
stats/route/semantic/profile coverage; devtools verify --quick
green.

Ref #270
Sinity added a commit that referenced this pull request Apr 22, 2026
The codebase carried two JSON helper modules: `polylogue.lib.json`
validates JSON values at runtime, while `polylogue.schemas.json_types`
duplicated the type aliases but used cast-only coercion. Schema
code depended on a weaker, path-dependent contract, and
check/maintenance JSON renderers carried object-shaped payloads
instead of explicit JSON contracts.

Standardizes internal imports on `polylogue.lib.json` across the
schema / tooling / tests surface. Updates schema, MCP, surface,
CLI, and test imports to use the canonical JSON types and coercion
helpers. Tightens readiness, repair, maintenance, and check-command
machine payloads to return canonical `JSONDocument` values.
Deletes `polylogue/schemas/json_types.py` so new schema code cannot
drift back to the unsafe cast-only helper (no compatibility
wrapper).

Verification: ruff + mypy + pytest over schema / pipeline / source /
check / repair / health-core / maintenance-targets suites; devtools
verify --quick green.

Stacked on #305. Ref #300
@Sinity

Sinity commented May 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

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

Labels

area:cli CLI tool:claude Claude type:refactor Code restructuring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant