Repository navigation
feat(query): execute structural and sequence predicates (#2006) - #2011
Conversation
📝 WalkthroughWalkthroughAdds ChangesStructural query predicates: exists() and seq()
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
6034958 to
7d70c05
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 60349589a3
ℹ️ 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".
7d70c05 to
3752fef
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
3752fef to
64645fb
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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 `@polylogue/archive/query/expression.py`:
- Around line 588-600: The current validation in _validate_predicate_context
function only checks if the field name is supported but does not validate the
actual predicate values. Add validation logic after the field membership check
to validate the predicate.value attribute, ensuring that structural values are
of the correct type (e.g., numeric values where required) and are not empty,
which would prevent invalid inputs from reaching the SQLite lowering phase and
causing failures like malformed SQL with dangling AND operators or type
conversion errors.
In `@polylogue/storage/sqlite/archive_tiers/archive.py`:
- Around line 4377-4382: The path filtering in the action_column dictionary for
the "path" key does not normalize path separators, which causes archived paths
with backslashes (Windows-style) to be missed when matching forward slash
predicates. Apply path normalization (converting backslashes to forward slashes)
in the COALESCE expression for the "path" field in the action_column dictionary
at line 4379, similar to how session-level path filters normalize paths. Also
apply the same normalization fix to the similar path comparison code at lines
4403-4404 to ensure consistent path matching across all structural predicate
clauses.
- Around line 4327-4332: The _like_clause function currently joins multiple LIKE
conditions with AND, but the documented behavior for field:(a|b) syntax requires
OR logic instead. Change the join operation in the return statement of
_like_clause from " AND ".join(clauses) to " OR ".join(clauses) so that
expressions like message(text:(timeout|failure)) will match text containing
either term rather than requiring both terms to be present.
🪄 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: e57cf8d2-5d50-48ed-9f91-8fc969df9ef6
📒 Files selected for processing (4)
polylogue/archive/query/expression.pypolylogue/archive/query/predicate.pypolylogue/storage/sqlite/archive_tiers/archive.pytests/unit/cli/test_query_expression.py
64645fb to
32ea3ac
Compare
|
Review follow-up on CodeRabbit's final actionable set:
Verification after these fixes: ============================= test session starts ============================== tests/unit/cli/test_query_expression.py ................................ [ 17%] ============================= 187 passed in 22.36s ============================= -> 187 passed; { |
|
Corrected review follow-up for CodeRabbit's final actionable set:
Verification after these fixes: |
## Summary Adds executable lexical predicates to the #2006 Boolean DSL. `~term` and `~"quoted phrase"` now parse into a typed `QueryTextPredicate` and lower into a correlated FTS5 filter against `messages_fts` joined through `blocks`. ## Problem After #2011, the DSL could execute session fields, structural `exists(...)`, and action `seq(...)`, but lexical text inside Boolean predicates was still not representable. That meant users could not write queries such as `sessions where origin:chatgpt-export AND ~"timeout failure"` without dropping back to the older flat ranked FTS path. ## Solution Introduced `QueryTextPredicate`, extended the Lark Boolean grammar with `~text` / `~"phrase"`, and wired the archive Boolean lowerer to `messages_fts MATCH ?`. Because `messages_fts` is contentless and its unindexed columns read back as NULL, the lowerer joins `blocks` by rowid for session correlation, matching the existing search path's storage reality. This PR gives Boolean FTS filter semantics; the existing flat query-term path remains the ranked lexical search path. ## Verification - `nix develop --command devtools test tests/unit/cli/test_query_expression.py` -> `190 passed in 24.52s` - `nix develop --command devtools verify --quick` -> `exit_code: 0` - pre-push `devtools verify --quick` on pushed branch -> `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. |
|
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
Adds executable structural and sequence query predicates to the #2006 DSL path.
exists message(...),exists action(...), andseq(action:a -> action:b)now parse into the typed predicate AST and lower into SQLite predicates againstmessages,blocks, theactionsview, 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
QueryExistsPredicateandQuerySequencePredicate, extended the Lark Boolean grammar withexists message(...),exists action(...), andseq(...), and wired storage lowering to correlatedEXISTSclauses 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.22snix develop --command devtools verify --quick->exit_code: 0devtools verify --quickon32ea3acf->exit_code: 0Ref #2006