Skip to content

fix(query): reject terminal-only unit selectors (#2006) - #2161

Merged
Sinity merged 1 commit into
masterfrom
feature/feat/query-dsl-grammar-2006
Jun 19, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/feat/query-dsl-grammar-2006

Conversation

@Sinity

@Sinity Sinity commented Jun 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

This tightens the #2006 query grammar boundary for runtime-transform unit sources. runs where ..., observed-events where ..., and context-snapshots where ... remain valid terminal row queries, but session-selector paths now reject them with a typed error instead of manufacturing an unlowerable or ambiguous exists ... predicate. The branch also registers the context_pack_payload API method added by #2160 in the archive facade route catalog, which the broad seed surfaced.

Problem

The full query DSL issue distinguishes terminal row sources from structural session selectors. Runtime-transform units are generated from recovery/run projections today; they do not have durable SQL lowerers that can support exists run(...), exists observed-event(...), or exists context-snapshot(...) session predicates. Before this change, runs where ... could leak into the session compiler as an EXISTS predicate that storage cannot lower, while observed-event/context-snapshot forms could fall through to weaker parse behavior.

#2160 also added a public async Polylogue.context_pack_payload(...) method without updating the archive-route catalog used by polylogue ops status, so facade coverage and the JSON status snapshot drifted.

Solution

  • Add a typed terminal-only error in polylogue.archive.query.expression for runtime-transform unit sources used as session selectors.
  • Keep parse_unit_source_expression(...) behavior intact for terminal CLI/API/MCP/daemon query-unit routes.
  • Document runs alongside the existing terminal units and clarify that runtime-transform units are terminal-only until real durable lowerers exist.
  • Add focused parser and daemon HTTP coverage for the rejected session-selector path.
  • Register context_pack_payload as an index-routed archive facade method and refresh the affected status snapshot.

Verification

  • nix develop --command devtools test tests/unit/cli/test_query_expression.py tests/unit/daemon/test_web_reader.py -k 'terminal_only_unit_sources_do_not_compile_to_session_selectors or session_list_rejects_terminal_only_unit_query or parse_run_source_expression_preserves_terminal_unit or query_units_endpoint_returns_run_rows'
  • nix develop --command devtools test tests/unit/cli/test_status.py::test_archive_facade_route_catalog_covers_public_async_facade tests/unit/api/test_facade_contracts.py::test_no_undiscovered_async_methods
  • nix develop --command devtools test tests/unit/cli/test_plain_cli_snapshots.py::test_json_status_snapshot --snapshot-update
  • nix develop --command devtools test tests/unit/cli/test_plain_cli_snapshots.py::test_json_status_snapshot
  • nix develop --command devtools verify --quick
  • git diff --check

nix develop --command devtools verify --seed-testmon --skip-slow (detached to avoid foreground session SIGTERM): 11,504 selected, 11,503 passed, 1 xfailed; peak pytest RSS 3,168 MiB.

  • nix develop --command devtools verify: 7 affected tests passed; peak pytest RSS 125 MiB.

Closes part of #2006.

Summary by CodeRabbit

  • New Features

    • Extended query DSL to support runs as a selectable terminal unit alongside other units.
    • Added new context_pack_payload method to the facade API.
  • Bug Fixes

    • Improved error handling to provide clearer messages when terminal-only units are used incorrectly in session queries.
  • Documentation

    • Updated query documentation with runs examples and expanded structural unit coverage.

Problem: runtime-transform unit sources such as runs, observed-events, and context-snapshots are executable terminal row queries, but they do not have durable SQL lowerers for session-selector EXISTS predicates. Letting them enter the session compiler either produced an unlowerable predicate or weaker parse behavior.\n\nWhat changed: session-selector compilation now raises a typed terminal-only error for those runtime-transform unit sources while preserving parse_unit_source_expression for CLI/API/MCP/daemon terminal query-unit routes. docs/search.md documents runs alongside the terminal units and states the structural boundary explicitly. The branch also registers context_pack_payload in the archive facade route catalog after the seed run exposed the #2160 coverage drift.\n\nVerification: focused parser/daemon query-unit tests, facade catalog tests, status snapshot update/rerun, devtools verify --quick, detached devtools verify --seed-testmon --skip-slow, default devtools verify, and git diff --check all passed.\n\nRef #2006
@coderabbitai

coderabbitai Bot commented Jun 19, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: d9d099a5-a33f-4034-8552-de4a5302d3a6

📥 Commits

Reviewing files that changed from the base of the PR and between 9af1edc and b78606e.

📒 Files selected for processing (7)
  • docs/search.md
  • polylogue/archive/query/expression.py
  • polylogue/cli/commands/status.py
  • tests/unit/api/test_facade_contracts.py
  • tests/unit/cli/__snapshots__/test_plain_cli_snapshots.ambr
  • tests/unit/cli/test_query_expression.py
  • tests/unit/daemon/test_web_reader.py

📝 Walkthrough

Walkthrough

The PR adds runs as a formally recognized terminal unit in the query DSL: the compiler now raises ExpressionCompileError (instead of silently returning None) when runs where … is used as a session selector, and documentation is extended to cover runs and assertion in the grammar and predicate tables. Separately, context_pack_payload is registered as an archive_routed/index-tier facade route with matching contract-test and snapshot updates.

Changes

runs terminal-unit compile error and docs

Layer / File(s) Summary
Compile-time rejection of terminal-only unit sources
polylogue/archive/query/expression.py, tests/unit/cli/test_query_expression.py, tests/unit/daemon/test_web_reader.py
New _terminal_only_unit_source_error helper constructs a typed ExpressionCompileError; _parse_source_where_predicate now raises it for run, observed-event, and context-snapshot (previously the latter two silently returned None, and run was unhandled). New parametrized unit test and HTTP 400 regression test cover the rejection.
Query DSL grammar and docs extended for runs and assertion
docs/search.md
Grammar adds runs to unit-query and assertion to structural-unit. Structural predicates table gains an assertion row. Terminal-unit examples and narrative prose are updated to include runs as a first-class terminal row source.

context_pack_payload facade route registration

Layer / File(s) Summary
context_pack_payload route registration and contract coverage
polylogue/cli/commands/status.py, tests/unit/api/test_facade_contracts.py, tests/unit/cli/__snapshots__/test_plain_cli_snapshots.ambr
Adds context_pack_payload to _ARCHIVE_FACADE_ROUTES (archive_routed, index tier). Adds the method name to BESPOKE_METHODS in the facade contract allowlist. CLI snapshots reflect incremented archive_routed, index, and total method counts.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • Sinity/polylogue#1861: Introduced the shared compiler infrastructure in polylogue/archive/query/expression.py that this PR builds on to add the run terminal-unit compile error.
  • Sinity/polylogue#2112: Added context-snapshot as a queryable terminal row via the same DSL plumbing that this PR now enforces via _parse_source_where_predicate.
  • Sinity/polylogue#2151: Also extends polylogue/cli/commands/status.py archive facade route catalog and whitelists new async facade helpers in tests/unit/api/test_facade_contracts.py, following the same pattern as this PR's context_pack_payload addition.

Poem

🐇 A little rabbit hops through the query land,
Where runs where … once slipped by unplanned—
Now compile-time stands guard with an error in hand.
And context_pack_payload joins the archive brigade,
Every route counted, every snapshot remade.
No silent None where a clear error should stay—
The DSL sharpens its claws, hip-hip-hooray! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% 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 accurately reflects the main change: rejecting terminal-only unit selectors in query expressions, specifically addressing the #2006 issue.
Description check ✅ Passed The PR description covers all required template sections with thorough detail: Summary explains the change, Problem describes the underlying issue, Solution outlines key modules affected, Verification lists exact test commands, and Risks section appropriately omitted as none exist.
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/feat/query-dsl-grammar-2006

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.

@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: b78606ee37

ℹ️ 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".

Comment thread docs/search.md Resolved
github-actions Bot pushed a commit that referenced this pull request Jun 19, 2026
@Sinity
Sinity merged commit 05feeed into master Jun 19, 2026
14 of 15 checks passed
@Sinity
Sinity deleted the feature/feat/query-dsl-grammar-2006 branch June 19, 2026 11:33
@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.

  • 57.F110 / P2: fixed-already at the checked revision: The Boolean detector now derives exists prefixes from every structural_query_units entry at polylogue/archive/query/expression.py:2115. Its prefix branch at polylogue/archive/query/expression.py:2120 therefore includes the registered assertion unit instead of hard-coding only message/action/block.

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