Skip to content

refactor(storage): share run projection relation reads - #2523

Merged
Sinity merged 2 commits into
masterfrom
feature/refactor/run-projection-source-relations
Jul 4, 2026
Merged

Sinity merged 2 commits into
masterfrom
feature/refactor/run-projection-source-relations

Conversation

@Sinity

@Sinity Sinity commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Summary

Run-projection reads now use one shared source-derived SQLite relation substrate instead of separate ArchiveStore and repository/query-store implementations. The direct repository read APIs return useful source rows even when the materialized cache tables are empty or absent, while existing materialized subagent/enrichment rows still participate when those tables exist.

Problem

The run, observed-event, and context-snapshot terminal lowerers already synthesized rows from durable sessions and blocks evidence, but repository/query-store reads selected only from session_runs, session_observed_events, and session_context_snapshots. That split made the cache tables more load-bearing than they should be and duplicated a large SQL relation inside archive.py.

Internal task: Bead polylogue-x5l.

Solution

Added polylogue/storage/sqlite/run_projection_relations.py as the shared relation and row-mapping module for run-projection reads. ArchiveStore terminal queries, structural exists run/observed-event/context-snapshot(...) selectors, and async query-store list_* APIs now compose through the same source-derived CTEs with optional materialized branches guarded by table existence where the read path can inspect it.

The old archive-local relation constants and mappers were removed. The generated topology projection was refreshed to register the new storage module.

Verification

  • ruff format / ruff check on touched files.
  • python -m py_compile polylogue/storage/sqlite/run_projection_relations.py polylogue/storage/sqlite/queries/session_insight_run_projection_reads.py polylogue/storage/sqlite/archive_tiers/archive.py
  • mypy polylogue/storage/sqlite/run_projection_relations.py polylogue/storage/sqlite/queries/session_insight_run_projection_reads.py
  • devtools test tests/unit/insights/test_run_projection_materialization.py tests/unit/cli/test_query_expression.py::TestBooleanQueryExpression::test_exists_run_projection_predicates_select_sessions tests/unit/cli/test_query_expression.py::TestBooleanQueryExpression::test_exists_run_projection_predicates_use_source_relations -> 6 passed in 76.2s.
  • Pre-push devtools verify --quick at 5b86a3b4d6c1f8578e6cabd8c0448c20ad3609ee -> passed in 11.57s.

Changelog

Skipped: internal storage/query refactor.

Risks and Follow-ups

The materialized cache tables still exist and are still written by rebuild/materialization; this PR only makes read paths less dependent on them. Follow-up Bead polylogue-dab owns removing the cache write/readiness/DDL surface after parity is fully established.

@coderabbitai

coderabbitai Bot commented Jul 3, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

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

Next review available in: 51 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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e4a8c5c2-25f1-4720-a0f1-5d8a6f4c6b7d

📥 Commits

Reviewing files that changed from the base of the PR and between 0c8d8b1 and dbbed3b.

📒 Files selected for processing (6)
  • docs/plans/topology-target.yaml
  • docs/topology-status.md
  • polylogue/storage/sqlite/archive_tiers/archive.py
  • polylogue/storage/sqlite/queries/session_insight_run_projection_reads.py
  • polylogue/storage/sqlite/run_projection_relations.py
  • tests/unit/insights/test_run_projection_materialization.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/refactor/run-projection-source-relations

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.

github-actions Bot pushed a commit that referenced this pull request Jul 3, 2026

@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: 5b86a3b4d6

ℹ️ 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 added 2 commits July 4, 2026 23:05
Problem: run, observed-event, and context-snapshot reads had two query substrates. ArchiveStore terminal queries synthesized source rows from sessions/blocks, while repository/query-store reads selected only the materialized session_* cache tables. The duplicated SQL also meant absent cache tables failed even when source evidence was enough to answer the query.

What changed: add a shared run_projection_relations module with source-derived relation builders, optional materialized branches, and row mappers. Route ArchiveStore terminal queries, structural exists selectors, and async query-store list APIs through that shared relation. Keep materialized subagent/enrichment rows when the cache tables exist, while direct repository reads still return source rows when the tables are empty or absent.

Verification: ruff format/check on touched files; python -m py_compile for archive/query/shared modules; mypy on the shared and async query modules; devtools test tests/unit/insights/test_run_projection_materialization.py tests/unit/cli/test_query_expression.py::TestBooleanQueryExpression::test_exists_run_projection_predicates_select_sessions tests/unit/cli/test_query_expression.py::TestBooleanQueryExpression::test_exists_run_projection_predicates_use_source_relations -> 6 passed in 76.2s.
@Sinity
Sinity force-pushed the feature/refactor/run-projection-source-relations branch from 5b86a3b to dbbed3b Compare July 4, 2026 21:08
@Sinity
Sinity merged commit 972cc69 into master Jul 4, 2026
14 checks passed
@Sinity
Sinity deleted the feature/refactor/run-projection-source-relations branch July 4, 2026 21:09
github-actions Bot pushed a commit that referenced this pull request Jul 4, 2026
Sinity added a commit that referenced this pull request Jul 12, 2026
## Summary

Remove four literal-zero-coverage modules that have no remaining
production reachability. Refresh the generated topology projection.

## Problem

The coverage audit exposed fully unexecuted files. Static imports,
dynamic import registries, and CLI/MCP/API registrations showed these
were stale implementations, not live behavior lacking tests.

## Solution

- `archive/semantic/outlook.py`: dead; replaced by the registered
`cost.outlook` surface.
- `context/assertion_claims.py`: dead after the context-image refactor.
- `publication/__init__.py`: isolated and unregistered.
- `mappers_run_projection.py`: dead; #2523 moved active hydration to
`run_projection_relations.py`.

The generated topology projection and status now omit the removed paths.

## Verification

- `nix develop --command devtools test
tests/unit/insights/test_run_projection_materialization.py` — 6 passed.
This existing real-route test exercises
`session_insight_run_projection_reads` through
`run_projection_relations`; removing its active mapper/hydration path
would fail it.
- `nix develop --command devtools verify --quick` — all 15 checks
passed.
- Pre-push reran `devtools verify --quick` for each commit; all checks
passed.

## Acceptance criteria

`polylogue-kp4q`: satisfied. All four files are verdict `dead/delete`;
no untested-but-live or unwired files remained.

## Adversarial review notes

- Iteration 1: independent cold review of the fetched full branch diff,
Bead AC, import/registration reachability, and PR feedback found no
legitimate gaps.
- No substantive automated-review comments were present; CodeRabbit was
rate-limited and Codex posted no suggestions.

Ref polylogue-kp4q.

---------

Co-authored-by: Codex <[email protected]>
Co-authored-by: Claude <[email protected]>
@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.

  • 75.F051 / P2: fixed-already at the checked revision: Run projection defaults to source-only SQL at polylogue/storage/sqlite/run_projection_relations.py:148 and reads sessions in its source_runs CTE. The removed cache is no longer part of default relation construction; explicit include_materialized=True is refused at :156-159 instead of emitting a reference to a missing session_runs table.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant