Repository navigation
feat(query): expose context snapshots as terminal rows - #2112
Conversation
Problem #2006 made terminal query units the shared row-level query surface, but context snapshots were still only visible inside recovery projections and work-packet rendering. Runtime-transform units also accepted scoped session predicates that the in-memory summary matcher could not evaluate, which could silently broaden observed-event and context-snapshot results. What changed - Project review-injected recovery events into concrete ContextSnapshot rows. - Add context-snapshot terminal query-unit parsing, payloads, CLI rendering, API/MCP/daemon wiring, and generated docs/schemas. - Keep terminal unit expressions on query-unit routing instead of stats routing. - Make runtime-transform scoped session predicates fail closed for unsupported summary fields. Verification - devtools test focused 13-node query-unit/context-snapshot surface set: 13 passed. - devtools verify --quick: exit_code 0. Ref #2006 Ref #1882
|
Warning Review limit reached
More reviews will be available in 21 minutes and 23 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the 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 credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. 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, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughAdds Changescontext-snapshot query unit
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1ea198e57f
ℹ️ 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".
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@docs/search.md`:
- Around line 7-8: The documentation contains an inconsistency where lines 7-8
mention `assertions/observed-events/context-snapshots` as valid unit-source
forms alongside `messages/actions/blocks`, but the canonical grammar rule for
`unit-query` on line 36 only includes `messages/actions/blocks`. Update the
`unit-query` grammar rule definition to include all the unit sources that are
documented in the earlier section, specifically expanding it to cover
`sessions/messages/actions/blocks/assertions/observed-events/context-snapshots`
so the grammar matches the documented behavior.
In `@polylogue/archive/query/unit_results.py`:
- Around line 314-327: The archive.list_summaries call on line 314 has a
hardcoded limit of 1_000_000 summaries which silently truncates results in large
archives without attempting to fetch remaining summaries. Remove the fixed limit
parameter from the archive.list_summaries call and implement pagination logic to
iteratively fetch all summaries in batches until all results are consumed. This
ensures complete result sets are returned instead of silently truncating at an
arbitrary threshold.
🪄 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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 546dd551-36b2-48a3-8f22-a92a5ac445f3
📒 Files selected for processing (24)
devtools/render_cli_output_schemas.pydevtools/render_openapi.pydocs/cli-reference.mddocs/daemon.mddocs/openapi/search.yamldocs/schemas/cli-output/README.mddocs/schemas/cli-output/query-unit-envelope.schema.jsondocs/search.mdpolylogue/api/archive.pypolylogue/archive/query/expression.pypolylogue/archive/query/metadata.pypolylogue/archive/query/unit_results.pypolylogue/cli/archive_query.pypolylogue/cli/root_request.pypolylogue/daemon/http.pypolylogue/insights/run_projection.pypolylogue/mcp/archive_support.pypolylogue/surfaces/payloads.pytests/unit/api/test_facade_contracts.pytests/unit/cli/test_query_exec_laws.pytests/unit/cli/test_query_expression.pytests/unit/daemon/test_web_reader.pytests/unit/insights/test_transforms.pytests/unit/mcp/test_server_surfaces.py
Problem: review found runtime-transform unit queries treated session.path as cwd and evaluated session.since only against updated_at, diverging from normal session filter semantics.\n\nWhat changed: session.path now fails closed on runtime-transform summaries instead of aliasing to cwd, session.since/until use updated_at with created_at fallback, and completions no longer teach session.path for terminal structural units.\n\nVerification: devtools test tests/unit/cli/test_query_expression.py (249 passed); devtools verify --quick (exit 0).\n\nRef #2006
Problem: runtime-transform terminal query units scanned session summaries with a fixed million-row cap, and the DSL docs still described only the original three terminal units. Code review correctly flagged both as stale behavior/documentation for #2006. What changed: query-unit execution now pages through ArchiveStore.list_summaries for context snapshots and observed events, the search grammar documents assertion/observed-event/context-snapshot units, and focused coverage proves pagination reaches later summary pages. Verification: nix develop --command bash -c 'devtools render-pages >/tmp/plg-2112-render-pages.log 2>&1 && ruff format polylogue/archive/query/unit_results.py polylogue/archive/query/metadata.py tests/unit/cli/test_query_expression.py && ruff check polylogue/archive/query/unit_results.py polylogue/archive/query/metadata.py tests/unit/cli/test_query_expression.py && devtools test tests/unit/cli/test_query_expression.py && devtools verify --quick'
|
Addressed the latest review findings in f339ccb: docs/search.md now includes assertion, observed-event, and context-snapshot unit sources in the grammar; runtime-transform unit scans now page through ArchiveStore.list_summaries instead of using a fixed cap; the earlier session.path/session.since findings remain covered by the prior fix commit and focused tests. |
|
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. |
Summary
This PR extends the terminal query-unit surface with
context-snapshots where ...rows and projects review-injected recovery events into concrete context snapshots. It also rounds out terminal query-unit rendering for assertion/observed-event/context-snapshot rows and keeps explicit terminal-unit expressions on query-unit routing instead of root stats routing.Ref #2006
Ref #1882
Problem
The query DSL and terminal row substrate could address messages, actions, blocks, assertions, and observed events, but context snapshots were still trapped inside recovery projections/work-packet rendering. Review-injected context was represented as an observed event but not as a context boundary that API/CLI/MCP/daemon callers could query. While wiring this,
_summary_field_matches()also had a fail-open fallback for scoped session fields on runtime-transform units, so supported-but-unimplemented predicates such assession.tool:bashcould silently broaden observed-event/context-snapshot results.Solution
context-snapshotto terminal unit parsing, metadata, payload schemas, generated OpenAPI/CLI schema docs, and daemon/API/MCP error text.context-snapshots where ...by compiling recovery digests and returning typedContextSnapshotQueryRowPayloadrows.review_injected_contextrecovery events intoContextSnapshot(boundary="review_injection", inheritance_mode="injected")rows with event/object refs as segments.Intentional scope note: this branch absorbed the terminal-query rendering/routing pieces that overlap with #1883, but not #1883's assertion lifecycle/defaults work. That is prepared separately on
feature/feat/assertion-defaults-1883.Verification
nix develop --command devtools test tests/unit/insights/test_transforms.py::test_review_delivery_events_are_extracted_and_projected tests/unit/insights/test_transforms.py::test_review_injection_context_snapshot_reaches_work_packet tests/unit/api/test_facade_contracts.py::test_query_units_returns_context_snapshot_rows tests/unit/cli/test_query_expression.py::TestBooleanQueryExpression::test_terminal_context_snapshot_source_returns_runtime_rows tests/unit/cli/test_query_exec_laws.py::TestSearchQueryContracts::test_assertion_unit_source_returns_json_envelope tests/unit/cli/test_query_exec_laws.py::TestSearchQueryContracts::test_assertion_unit_source_renders_plain_rows tests/unit/cli/test_query_exec_laws.py::TestSearchQueryContracts::test_context_snapshot_unit_source_routes_to_query_units tests/unit/daemon/test_web_reader.py::TestReaderQueryUnits::test_query_units_endpoint_returns_terminal_assertion_rows tests/unit/daemon/test_web_reader.py::TestReaderQueryUnits::test_query_units_endpoint_returns_context_snapshot_rows tests/unit/daemon/test_web_reader.py::TestReaderQueryUnits::test_query_units_endpoint_rejects_session_expression tests/unit/mcp/test_server_surfaces.py::TestArchiveGenericToolSurfaces::test_query_unit_payload_returns_assertion_rows tests/unit/mcp/test_server_surfaces.py::TestArchiveGenericToolSurfaces::test_query_units_tool_returns_context_snapshot_rows_without_archive_operations tests/unit/mcp/test_server_surfaces.py::TestArchiveGenericToolSurfaces::test_query_units_tool_rejects_session_expression-> 13 passed.nix develop --command devtools verify --quick-> exit_code 0.nix develop --command devtools verify-> static/generated checks passed, then pytest-testmon selected 11,357 tests and timed out at the 2700s harness limit while still progressing at 91%; no test failure report was produced. Postmortem diagnosis:pytest_timeout, peak tree RSS ~2.8 GiB,/dev/shmremained small.Summary by CodeRabbit
Release Notes
New Features
context-snapshots where ...query syntax.Documentation
Tests