Skip to content

feat(query): execute Boolean session predicates (#2006) - #2010

Merged
Sinity merged 1 commit into
masterfrom
feature/feat/query-boolean-session-fields-2006
Jun 17, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/feat/query-boolean-session-fields-2006

Conversation

@Sinity

@Sinity Sinity commented Jun 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

Add the next #2006 query-DSL layer: explicit Boolean expressions now compile into a typed predicate tree and execute against archive SQL for supported session-level fields. Cross-field OR, explicit AND, NOT, grouping, and sessions where ... forms no longer reject or broaden into FTS when their leaves are SQL-backed session predicates.

Ref #2006.

Problem

After #2009, current query strings entered through Lark, but cross-field Boolean syntax was still a typed rejection. That left the new grammar unable to execute one of the most basic full-DSL requirements: (repo:x OR origin:y) style predicates over session fields. Flattening those forms into SessionQuerySpec tuple fields would silently turn OR into AND, and treating them as free text would broaden results.

Solution

  • Add polylogue.archive.query.predicate with typed QueryFieldPredicate, QueryBoolPredicate, and QueryNotPredicate nodes.
  • Extend the expression parser so explicit Boolean syntax (OR, AND, NOT, leading grouping, or sessions where) emits a predicate tree on QueryExpressionAST.
  • Keep ordinary prose such as error or timeout not retry on the FTS path unless the expression contains structured query syntax.
  • Carry the predicate through SessionQuerySpec, SessionQueryPlan, and archive execution kwargs.
  • Lower supported leaves through the existing _session_filter_clause, preserving the same SQL semantics for origin, repo, tag, title, path, cwd, tool, action, has-flags/types, message/word counts, since/until, and exact session ids.
  • Compose ordinary filters with Boolean predicates as AND at the archive store boundary.
  • Keep unsupported/non-SQL leaves typed: this PR does not pretend FTS/vector/pipeline terms are Boolean-lowerable yet.
  • Regenerate topology surfaces for the new archive-query module.

Verification

  • devtools test tests/unit/cli/test_query_expression.py — 177 passed in 13.85s.
  • devtools verify --quick — exit_code: 0.
  • Pre-push hook reran devtools verify --quick on 9d21ff04 — exit_code: 0.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

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

More reviews will be available in 14 minutes and 39 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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: f34ffc7d-5491-49c4-85a0-0ecf6450057e

📥 Commits

Reviewing files that changed from the base of the PR and between 0a4fbfd and 9d21ff0.

📒 Files selected for processing (9)
  • docs/plans/topology-target.yaml
  • docs/topology-status.md
  • polylogue/archive/query/archive_execution.py
  • polylogue/archive/query/expression.py
  • polylogue/archive/query/plan.py
  • polylogue/archive/query/predicate.py
  • polylogue/archive/query/spec.py
  • polylogue/storage/sqlite/archive_tiers/archive.py
  • tests/unit/cli/test_query_expression.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/feat/query-boolean-session-fields-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.

github-actions Bot pushed a commit that referenced this pull request Jun 17, 2026
Add a typed QueryPredicate tree for explicit Boolean query expressions and carry it through SessionQuerySpec and SessionQueryPlan. The archive store lowers supported session-level leaves through the shared SQL filter clause, so OR/AND/NOT over origin, repo, tag, title, counts, paths, tools, actions, has-flags, and date fields executes instead of being rejected or broadened into FTS.\n\nRef #2006.
@Sinity
Sinity force-pushed the feature/feat/query-boolean-session-fields-2006 branch from 14f181e to 9d21ff0 Compare June 17, 2026 01:26

@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: 14f181e51d

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

re.VERBOSE,
)

_BOOLEAN_TRIGGER_RE = re.compile(r"^\s*\(|^\s*sessions\s+where\b|\b(?:and|or|not)\b", re.IGNORECASE)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not parse ordinary AND/NOT text as Boolean SQL

This trigger matches and, or, or not anywhere in the raw expression, including normal FTS text and quoted phrases. As a result, searches such as fix and test, "foo and bar", or near:"foo and bar" are sent to the Boolean grammar, which only accepts field/count atoms, so they now raise ExpressionCompileError instead of compiling to text/semantic search terms. The Boolean path should only be selected when the operator syntax is actually between supported predicate leaves, or fall back to the flat lexer on non-Boolean text.

Useful? React with 👍 / 👎.

Comment thread polylogue/archive/query/spec.py Resolved
Comment on lines +4237 to +4240
if field == "id":
if not values:
return "", []
return f"{table_alias}.session_id = ?", [values[-1]]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve Boolean id predicates like normal id filters

This direct session_id = ? comparison makes Boolean id: leaves narrower than the existing id: filter path, which calls resolve_session_id in list_summaries and therefore accepts unique prefixes and provider/native aliases. A query such as id:abc OR title:needle will miss a session whose canonical id starts with abc (or is addressable by chatgpt:abc) even though id:abc alone works, so Boolean id should either use the same resolver semantics or be rejected until it can.

Useful? React with 👍 / 👎.

@Sinity
Sinity merged commit 5fd1652 into master Jun 17, 2026
14 checks passed
@Sinity
Sinity deleted the feature/feat/query-boolean-session-fields-2006 branch June 17, 2026 01:30
Sinity added a commit that referenced this pull request Jun 17, 2026
## Summary
Adds executable structural and sequence query predicates to the #2006
DSL path. `exists message(...)`, `exists action(...)`, and `seq(action:a
-> action:b)` now parse into the typed predicate AST and lower into
SQLite predicates against `messages`, `blocks`, the `actions` view, and
the existing ordered action-sequence lowerer.

## Problem
After #2010, Boolean predicates could combine session-level fields, but
the DSL still could not ask archive-evidence questions such as “sessions
with an assistant message mentioning timeout,” “sessions with a file
edit under this path,” or “sessions where file edit happened before a
shell run.” That left #2006's structural and sequence lowerers as
parser-only target language instead of executable query behavior.

## Solution
Introduced `QueryExistsPredicate` and `QuerySequencePredicate`, extended
the Lark Boolean grammar with `exists message(...)`, `exists
action(...)`, and `seq(...)`, and wired storage lowering to correlated
`EXISTS` clauses plus the archive's existing action-sequence SQL.
Structural fields now cover message role/type/text/words and action
tool/action/command/path/output/text, with typed unit-ownership and
value validation so malformed structural fields cannot fall through to
SQLite. Review feedback also tightened structural alternation and path
handling: `field:(a|b)` preserves OR semantics inside correlated SQL,
multi-term LIKE clauses are parenthesized, and structural path matching
normalizes backslashes like the session-level path filter.

## Verification
- `nix develop --command devtools test
tests/unit/cli/test_query_expression.py` -> `187 passed in 24.22s`
- `nix develop --command devtools verify --quick` -> `exit_code: 0`
- pre-push `devtools verify --quick` on `32ea3acf` -> `exit_code: 0`

Ref #2006
@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.

  • 59.F085 / P2: fixed-already at the checked revision: polylogue/archive/query/spec.py:678 calls query_spec_has_filters, whose wrapper at line 409 delegates to query_spec_has_selection_filters. fields.py:1042-1043 explicitly accepts a Boolean predicate, so the actual has_filters entry point no longer discards Boolean-only selection.

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