Repository navigation
feat(query): parse query expressions with Lark (#2006) - #2009
Conversation
Problem: the query DSL still relied on a hand-rolled whitespace scanner and regex token splitter, which is the wrong substrate for the full AST/pipeline grammar tracked in #2006. What changed: add Lark as a runtime dependency, define a Lark grammar for the current query-expression clauses, expose parse_expression_ast(), keep _lex() as a compatibility projection, and preserve existing SessionQuerySpec lowering behavior. Verification: devtools test tests/unit/cli/test_query_expression.py (166 passed); devtools verify --quick (exit_code 0).
|
Warning Review limit reached
More reviews will be available in 37 minutes and 48 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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (4)
✨ 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 |
Problem: #2006's first implementation layer needs a concrete way to inspect source text, parsed clauses, lowering path, and execution plan details, not only an internal parser swap. What changed: add QueryExpressionExplanation / QueryExpressionExplainClause plus explain_expression(), covering both Lark query expressions and direct JSON specs, with payload conversion for future CLI/API exposure. Verification: devtools test tests/unit/cli/test_query_expression.py (168 passed); devtools verify --quick (exit_code 0).
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 02c99ca528
ℹ️ 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".
Clarify that the Lark grammar and AST are the query language for #2006. The current flat-expression behavior is parity evidence and a temporary lowering target, not a separate floor grammar to preserve.
pip-audit flagged cryptography 48.0.0 via GHSA-537c-gmf6-5ccf / CVE-2026-39892. Raise the declared floor to 48.0.1 and refresh uv.lock, which resolves to 49.0.0.
Address review findings on the query grammar bridge. Malformed count filters now reject as count/filter errors instead of tokenizing into a valid count plus broad FTS term, and unquoted code-like search tokens such as foo(bar), array[0], and dict{key} continue to compile as FTS terms.
## 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`.
|
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
Introduce Lark as the canonical query-expression grammar substrate, expose a typed parse envelope for current query strings, and add a query-expression explanation payload. Current
compile_expression()callers keep working because the new Lark AST lowers intoSessionQuerySpec; that is a migration bridge, not a separate floor grammar.Ref #2006.
Problem
The query DSL was still rooted in a hand-rolled whitespace scanner plus regex token splitting. That works for the old flat conjunction language, but it is the wrong foundation for the full query AST/pipeline grammar in #2006: precedence, grouping, quoted strings, literals, and diagnostics need to belong to one real grammar. The first implementation layer also needs an inspectable parse/lower/plan envelope so later CLI/MCP/API surfaces do not invent their own explanation formats.
CI also surfaced a dependency-audit failure on
cryptography==48.0.0(GHSA-537c-gmf6-5ccf/CVE-2026-39892) after the lockfile refresh.Solution
lark>=1.3.1,<2.0as a runtime dependency and updateuv.lock.polylogue/archive/query/expression.pywith a Lark grammar for current query clauses.QueryExpressionASTandparse_expression_ast()as the typed parse boundary._lex()through the Lark AST only as a projection into the current clause lowerer; the durable direction is one grammar and one AST/lowering pipeline.QueryExpressionExplanation,QueryExpressionExplainClause, andexplain_expression()covering source text, clauses, lowerer name, lowered spec, plan descriptions, and unsupported-node placeholders.foo(bar),array[0], anddict{key}while still rejecting leading Boolean/group syntax.messages:>=10xinstead of splitting them into a valid count plus broad FTS term.cryptographyfloor to>=48.0.1; the refreshed lock resolves to49.0.0.This is the first working replacement layer, not the full DSL: existing query strings now enter through the Lark grammar and still lower to today's executable
SessionQuerySpecpath while the next PRs add Boolean/structural lowerers.Verification
uv run pip-audit --strict --vulnerability-service osv --disable-pip -r .cache/requirements-audit-local.txt—No known vulnerabilities found.devtools test tests/unit/cli/test_query_expression.py—171 passed in 9.56s.devtools verify --quick—exit_code: 0.devtools verify --quickon3d330d3e—exit_code: 0; the push of the review-fix commit will rerun the same quick gate.