Skip to content

refactor: rebuild storage and product runtime boundary contracts - #260

Merged
Sinity merged 4 commits into
masterfrom
feature/refactor/storage-product-runtime-boundaries
Apr 20, 2026
Merged

Sinity merged 4 commits into
masterfrom
feature/refactor/storage-product-runtime-boundaries

Conversation

@Sinity

@Sinity Sinity commented Apr 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • rebuild the archive-product query/provenance surface around explicit shared product contracts
  • align runtime state, artifact, and session-product helpers with the newer typed payload boundaries
  • widen run-activity accounting to the actual CLI/runtime count surface used across the repo

Problem

Closes #259

The next remaining architectural pressure after the schema/source and audit tranches was concentrated in the storage and durable-product boundary layer. Runtime state updates, product registry rendering, and session-product hydration still carried broad object-shaped plumbing and repeated provenance/query wiring even though those shapes were already known.

Solution

  • rewrote the archive-product contract layer in polylogue/archive_products.py and polylogue/operations/archive.py so query models inherit from explicit shared bases, search-active behavior is modeled directly, aggregate pagination is centralized, and product provenance/inference provenance construction is no longer repeated in every product type
  • tightened polylogue/products/registry.py around ArchiveProductModel instead of generic object payloads so product accessors and JSON rendering operate over explicit product contracts
  • aligned runtime/storage follow-through in polylogue/storage/raw_state_models.py, polylogue/storage/artifact_views.py, polylogue/storage/repository_contracts.py, polylogue/storage/session_product_profiles.py, and polylogue/storage/session_product_threads.py so typed payloads are normalized at the boundary instead of reconstructed through loose dict plumbing
  • fixed the repo-wide count-surface mismatch in polylogue/lib/run_activity.py so CLI formatting and run observers consume the tightened run-count contracts without backsliding to weaker helpers

Verification

  • ruff check polylogue/archive_products.py polylogue/operations/archive.py polylogue/products/registry.py polylogue/storage/raw_state_models.py polylogue/storage/artifact_views.py polylogue/storage/repository_contracts.py polylogue/storage/session_product_profiles.py polylogue/storage/session_product_threads.py
  • mypy polylogue/archive_products.py polylogue/operations/archive.py polylogue/products/registry.py polylogue/storage/raw_state_models.py polylogue/storage/artifact_views.py polylogue/storage/repository_contracts.py polylogue/storage/session_product_profiles.py polylogue/storage/session_product_threads.py
  • pytest -q tests/unit/storage/test_session_product_profiles.py tests/unit/storage/test_product_materialization_laws.py tests/unit/storage/test_session_product_refresh.py tests/unit/cli/test_products.py tests/unit/cli/test_analytics.py
  • pytest -q tests/unit/storage/test_parse_tracking.py tests/unit/cli/test_check.py -k "parse or artifact"
  • ruff check polylogue/lib/run_activity.py polylogue/cli/formatting.py
  • mypy polylogue/lib/run_activity.py polylogue/cli/formatting.py
  • devtools verify

@Sinity
Sinity merged commit 386e483 into master Apr 20, 2026
11 of 12 checks passed
@coderabbitai

coderabbitai Bot commented Apr 20, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 79513e21-e088-4df7-8197-ea57fcfda6c8

📥 Commits

Reviewing files that changed from the base of the PR and between a88ed40 and 8f6ab89.

📒 Files selected for processing (16)
  • polylogue/archive_products.py
  • polylogue/lib/run_activity.py
  • polylogue/lib/session_profile_models.py
  • polylogue/lib/threads.py
  • polylogue/lib/work_event_extraction.py
  • polylogue/operations/archive.py
  • polylogue/products/registry.py
  • polylogue/storage/artifact_views.py
  • polylogue/storage/backends/queries/conversations_search.py
  • polylogue/storage/raw_state_models.py
  • polylogue/storage/repository_contracts.py
  • polylogue/storage/run_state.py
  • polylogue/storage/search_query_builders.py
  • polylogue/storage/search_runtime.py
  • polylogue/storage/session_product_profiles.py
  • polylogue/storage/session_product_threads.py

📝 Walkthrough

Walkthrough

This PR refactors the storage and product runtime boundary contracts throughout the codebase to replace generic object-typed plumbing with explicit typed state and product contracts. Changes introduce TypedDict payloads, narrow function signatures, consolidate helper functions, and refactor payload serialization/hydration across archive products, library models, storage layers, and registry code.

Changes

Cohort / File(s) Summary
Archive Products Query Hierarchy
polylogue/archive_products.py
Introduced a 7-level query class hierarchy (PaginatedProductQuery, TimeWindowProductQuery, SearchableTimeWindowProductQuery, ProviderTimeWindowProductQuery, ProviderSearchProductQuery, SessionWindowProductQuery, ConversationTimelineWindowProductQuery) with shared limit/offset defaults. Reshaped existing query classes to inherit from appropriate bases, preserving tier/limit/category overrides; added provenance helper protocol and functions.
Library Model Type Payloads
polylogue/lib/session_profile_models.py, polylogue/lib/threads.py, polylogue/lib/work_event_extraction.py
Added TypedDict payload schemas (SessionPhasePayload, SessionProfilePayload, WorkThreadPayload, WorkEventPayload) and narrowed to_dict() return types from dict[str, object] to their respective typed payloads. Expanded work-event extraction with immutable intermediate dataclasses (MessageRange, WorkEventSignalBundle, WorkEventClassifiedRange, etc.).
Run Activity Type Aliases
polylogue/lib/run_activity.py
Introduced RunCountLike and RunDriftLike type aliases to accept both legacy mapping forms and new payload types in conversation_activity_counts. Adjusted internal helpers to accept these broader types.
Product Registry Type Narrowing
polylogue/products/registry.py
Narrowed ProductAccessor from Callable[[object], str] to Callable[[ArchiveProductModel], str] and updated render_product_items to accept Sequence[ArchiveProductModel]. Removed runtime BaseModel checks from _model_payload, consolidating type safety.
Storage Query Builder Refactoring
polylogue/storage/search_query_builders.py
Replaced raw (sql, params) tuple returns with RankedSearchQuery immutable dataclass. Extracted _build_ranked_search_query() generic helper to consolidate SQL construction across conversation and action queries.
Storage State Model Consolidation
polylogue/storage/run_state.py
Unified two dict-to-int base classes into single _IntPayloadModel with _exclude_none_payload control. Refactored validator coercion with shared helpers (_coerce_model, _coerce_stage_sequence_payload, _coerce_cursor_state_payload) across PlanResult and RunResult. Simplified RunDrift mapping methods.
Raw State & Artifact Validation
polylogue/storage/raw_state_models.py, polylogue/storage/artifact_views.py
Added coercion helpers (_coerce_update_provider, _coerce_update_status, _coerce_update_mode) and __post_init__ logic to normalize enum/string inputs. Added field validators for sample_source_paths coercion and support_status input handling.
Repository & Query Contracts
polylogue/storage/repository_contracts.py, polylogue/storage/backends/queries/conversations_search.py, polylogue/storage/search_runtime.py
Narrowed async context manager return types from AbstractAsyncContextManager[object] to AbstractAsyncContextManager[None]. Updated query spec unpacking to use explicit attribute access (query_spec.sql, query_spec.params) instead of tuple unpacking.
Archive Operations & Session Persistence
polylogue/operations/archive.py, polylogue/storage/session_product_profiles.py, polylogue/storage/session_product_threads.py
Introduced generic helpers (_default_query, _query_wants_search, _slice_products) in archive.py to centralize defaulting and pagination. Refactored session profile and thread payload serialization/hydration with intermediate typed documents and explicit field mapping instead of model_dump() merges.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

area:storage, area:runtime, refactor

Poem

🐰 A hierarchy of queries now stands tall,
With typed payloads answering the call,
No more object dust on ancient shelves,
The storage layer speaks its truths itself!
Contracts clear from rim to rim,
The rabbit's work is never grim. ✨

✨ 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/storage-product-runtime-boundaries

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 deleted the feature/refactor/storage-product-runtime-boundaries branch April 20, 2026 08:46
Sinity added a commit that referenced this pull request Apr 22, 2026
## Summary

- rebuild the archive-product query/provenance surface around explicit shared product contracts
- align runtime state, artifact, and session-product helpers with the newer typed payload boundaries
- widen run-activity accounting to the actual CLI/runtime count surface used across the repo

## Problem

Closes #259

The next remaining architectural pressure after the schema/source and audit tranches was concentrated in the storage and durable-product boundary layer. Runtime state updates, product registry rendering, and session-product hydration still carried broad object-shaped plumbing and repeated provenance/query wiring even though those shapes were already known.

## Solution

- rewrote the archive-product contract layer in `polylogue/archive_products.py` and `polylogue/operations/archive.py` so query models inherit from explicit shared bases, search-active behavior is modeled directly, aggregate pagination is centralized, and product provenance/inference provenance construction is no longer repeated in every product type
- tightened `polylogue/products/registry.py` around `ArchiveProductModel` instead of generic object payloads so product accessors and JSON rendering operate over explicit product contracts
- aligned runtime/storage follow-through in `polylogue/storage/raw_state_models.py`, `polylogue/storage/artifact_views.py`, `polylogue/storage/repository_contracts.py`, `polylogue/storage/session_product_profiles.py`, and `polylogue/storage/session_product_threads.py` so typed payloads are normalized at the boundary instead of reconstructed through loose dict plumbing
- fixed the repo-wide count-surface mismatch in `polylogue/lib/run_activity.py` so CLI formatting and run observers consume the tightened run-count contracts without backsliding to weaker helpers

## Verification

- `ruff check polylogue/archive_products.py polylogue/operations/archive.py polylogue/products/registry.py polylogue/storage/raw_state_models.py polylogue/storage/artifact_views.py polylogue/storage/repository_contracts.py polylogue/storage/session_product_profiles.py polylogue/storage/session_product_threads.py`
- `mypy polylogue/archive_products.py polylogue/operations/archive.py polylogue/products/registry.py polylogue/storage/raw_state_models.py polylogue/storage/artifact_views.py polylogue/storage/repository_contracts.py polylogue/storage/session_product_profiles.py polylogue/storage/session_product_threads.py`
- `pytest -q tests/unit/storage/test_session_product_profiles.py tests/unit/storage/test_product_materialization_laws.py tests/unit/storage/test_session_product_refresh.py tests/unit/cli/test_products.py tests/unit/cli/test_analytics.py`
- `pytest -q tests/unit/storage/test_parse_tracking.py tests/unit/cli/test_check.py -k "parse or artifact"`
- `ruff check polylogue/lib/run_activity.py polylogue/cli/formatting.py`
- `mypy polylogue/lib/run_activity.py polylogue/cli/formatting.py`
- `devtools verify`
@Sinity Sinity added area:cli CLI area:schema Schema area:storage Storage tool:claude Claude type:refactor Code restructuring labels Apr 22, 2026
Sinity added a commit that referenced this pull request Apr 22, 2026
After the schema/source and audit tranches, architectural pressure
concentrated on the storage and durable-product boundary. Runtime
state updates, product registry rendering, and session-product
hydration still carried broad object-shaped plumbing and repeated
provenance/query wiring even though those shapes were already
known.

Rewrites the archive-product contract layer in `archive_products.py`
and `operations/archive.py` so query models inherit from explicit
shared bases, search-active behavior is modeled directly, aggregate
pagination is centralized, and product provenance / inference
provenance construction is no longer repeated in every product type.
Tightens `products/registry.py` around `ArchiveProductModel` instead
of generic object payloads so product accessors and JSON rendering
operate over explicit product contracts. Aligns runtime/storage
follow-through in `storage/raw_state_models.py`, `artifact_views.py`,
`repository_contracts.py`, `session_product_profiles.py`, and
`session_product_threads.py` so typed payloads are normalized at
the boundary instead of reconstructed through loose dict plumbing.
Fixes the repo-wide count-surface mismatch in `lib/run_activity.py`
so CLI formatting and run observers consume the tightened run-count
contracts.

Verification: ruff + mypy + pytest over storage / product / CLI
formatting surfaces; devtools verify green.

Closes #259
Sinity added a commit that referenced this pull request Apr 22, 2026
After the schema/source and audit tranches, architectural pressure
concentrated on the storage and durable-product boundary. Runtime
state updates, product registry rendering, and session-product
hydration still carried broad object-shaped plumbing and repeated
provenance/query wiring even though those shapes were already
known.

Rewrites the archive-product contract layer in `archive_products.py`
and `operations/archive.py` so query models inherit from explicit
shared bases, search-active behavior is modeled directly, aggregate
pagination is centralized, and product provenance / inference
provenance construction is no longer repeated in every product type.
Tightens `products/registry.py` around `ArchiveProductModel` instead
of generic object payloads so product accessors and JSON rendering
operate over explicit product contracts. Aligns runtime/storage
follow-through in `storage/raw_state_models.py`, `artifact_views.py`,
`repository_contracts.py`, `session_product_profiles.py`, and
`session_product_threads.py` so typed payloads are normalized at
the boundary instead of reconstructed through loose dict plumbing.
Fixes the repo-wide count-surface mismatch in `lib/run_activity.py`
so CLI formatting and run observers consume the tightened run-count
contracts.

Verification: ruff + mypy + pytest over storage / product / CLI
formatting surfaces; devtools verify green.

Closes #259
Sinity added a commit that referenced this pull request Apr 22, 2026
After the schema/source and audit tranches, architectural pressure
concentrated on the storage and durable-product boundary. Runtime
state updates, product registry rendering, and session-product
hydration still carried broad object-shaped plumbing and repeated
provenance/query wiring even though those shapes were already
known.

Rewrites the archive-product contract layer in `archive_products.py`
and `operations/archive.py` so query models inherit from explicit
shared bases, search-active behavior is modeled directly, aggregate
pagination is centralized, and product provenance / inference
provenance construction is no longer repeated in every product type.
Tightens `products/registry.py` around `ArchiveProductModel` instead
of generic object payloads so product accessors and JSON rendering
operate over explicit product contracts. Aligns runtime/storage
follow-through in `storage/raw_state_models.py`, `artifact_views.py`,
`repository_contracts.py`, `session_product_profiles.py`, and
`session_product_threads.py` so typed payloads are normalized at
the boundary instead of reconstructed through loose dict plumbing.
Fixes the repo-wide count-surface mismatch in `lib/run_activity.py`
so CLI formatting and run observers consume the tightened run-count
contracts.

Verification: ruff + mypy + pytest over storage / product / CLI
formatting surfaces; devtools verify green.

Closes #259
@Sinity

Sinity commented May 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@Sinity
Sinity requested a review from Copilot May 1, 2026 01:52

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 386e483861

ℹ️ 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 removed the request for review from Copilot May 1, 2026 02:15
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

Only the rows listed above are dispositioned. Held findings remain open.

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.

refactor: rebuild storage and product runtime boundary contracts

1 participant