Repository navigation
feat(query): execute Boolean session predicates (#2006) - #2010
Conversation
|
Warning Review limit reached
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 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 selected for processing (9)
✨ 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 |
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.
14f181e to
9d21ff0
Compare
There was a problem hiding this comment.
💡 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) |
There was a problem hiding this comment.
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 👍 / 👎.
| if field == "id": | ||
| if not values: | ||
| return "", [] | ||
| return f"{table_alias}.session_id = ?", [values[-1]] |
There was a problem hiding this comment.
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 👍 / 👎.
## 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
|
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
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, explicitAND,NOT, grouping, andsessions 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 intoSessionQuerySpectuple fields would silently turn OR into AND, and treating them as free text would broaden results.Solution
polylogue.archive.query.predicatewith typedQueryFieldPredicate,QueryBoolPredicate, andQueryNotPredicatenodes.OR,AND,NOT, leading grouping, orsessions where) emits a predicate tree onQueryExpressionAST.error or timeout not retryon the FTS path unless the expression contains structured query syntax.SessionQuerySpec,SessionQueryPlan, and archive execution kwargs._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.Verification
devtools test tests/unit/cli/test_query_expression.py—177 passed in 13.85s.devtools verify --quick—exit_code: 0.devtools verify --quickon9d21ff04—exit_code: 0.