Repository navigation
fix(query): tighten message and cwd filters - #692
Conversation
Problem: query/read filters still used forgiving provider coercion and plain string prefix matching at user-facing boundaries. Unknown since-session IDs broadened to every conversation, unknown-cwd candidates stayed in same-cwd recall, message_type typos collapsed to normal messages, and cwd_prefix matched sibling repositories.\n\nWhat changed: add strict message-type filter validation for query/API/MCP/storage paths while preserving forgiving parser normalization, add a path-component bounded cwd prefix primitive, use it in runtime and SQL filters, make unknown since-session references return no results, and exclude unknown-cwd candidates when a reference session has cwd evidence.\n\nVerification: pytest focused query/storage/API/MCP suite, ruff, mypy on changed source files, devtools render-all --check, topology/layering/test-ownership checks, and devtools verify --quick.\n\nRef #621\n\nCo-Authored-By: Claude <[email protected]>
Problem: ConversationQuerySpec.from_params still accepted invalid message_type values and deferred failure until storage or runtime filtering. MCP query requests already flow through the spec layer, so the boundary should be strict there too.\n\nWhat changed: add optional_message_type normalization that validates user-supplied values through the strict message-type filter validator and raises QuerySpecError for invalid tokens. Extend query-field tests to cover valid hyphenated input, normal message filters, and invalid spec construction.\n\nVerification: focused query/API/MCP/storage tests, ruff, and mypy on changed query source files.\n\nRef #621\n\nCo-Authored-By: Claude <[email protected]>
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis PR adds stricter validation for message-type filters and introduces path-prefix filtering for conversations. Message types are now validated at parse time to catch invalid inputs, and a new "message" content type is added. Path-prefix matching uses component-bounded semantics to prevent partial substring matches. These changes are integrated across query planning, CLI, MCP, storage, and test suites. ChangesMessage Type Validation & Path-Prefix Filtering
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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. Review rate limit: 0/1 reviews remaining, refill in 60 minutes.Comment |
Polylogue Proof PackRefs: Affected Domains
Additional routed domains with zero affected claims
Focused Gates
Required PR Gates
Optional Confidence Gates
Known Gaps
Additional gaps in zero-claim routed domains
Oracle / Cost
|
There was a problem hiding this comment.
Pull request overview
This PR tightens archive query/read filtering so user-facing message-type filters are validated strictly and cwd-based filters use path-component-bounded matching across runtime and SQL paths. It fits into the archive query stack by aligning CLI/MCP/API/spec/storage behavior around the canonical query contract tracked in #621.
Changes:
- Added strict validation for
message_typefilters across query spec construction, MCP query/read surfaces, runtime filtering, and SQL/message reads. - Introduced shared cwd path-prefix matching helpers and applied them to runtime filters and SQL pushdown to avoid sibling-path false positives.
- Expanded unit coverage and regenerated CLI/topology docs to reflect the tightened filter contract.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/storage/test_message_query_reads.py | Adds storage-level tests for strict message-type filtering and message support. |
| tests/unit/mcp/test_tool_contracts.py | Adds MCP tool tests for rejecting unknown message_type values. |
| tests/unit/core/test_query_fields.py | Covers strict query-spec normalization for message_type. |
| tests/unit/core/test_message_types.py | Tests the new strict message-type validation helper. |
| tests/unit/core/test_facade_api.py | Verifies facade read API rejects invalid message-type filters. |
| tests/unit/core/test_cwd_prefix_filter.py | Adds SQL cwd-prefix behavior tests and updates expected SQL patterns. |
| tests/unit/archive/test_query_runtime_filters.py | Expands runtime-filter coverage for strict message types and bounded cwd/since-session behavior. |
| polylogue/storage/backends/queries/message_query_reads.py | Switches message reads to strict message_type validation and adds message to the accepted literal set. |
| polylogue/storage/backends/queries/filter_builder.py | Applies strict message-type validation and bounded cwd SQL matching. |
| polylogue/mcp/server_tools.py | Validates get_messages MCP message_type input before dispatching reads. |
| polylogue/mcp/query_contracts.py | Validates MCP query message_type inputs before building query specs. |
| polylogue/cli/click_option_groups.py | Updates root query CLI option choices/docs to include message. |
| polylogue/archive/query/spec.py | Adds strict optional message_type normalization for query-spec params. |
| polylogue/archive/query/runtime_filters.py | Enforces strict runtime message-type validation and bounded cwd/since-session filtering. |
| polylogue/archive/query/path_prefix.py | Introduces shared path-prefix normalization/matching helpers for cwd filters. |
| polylogue/archive/message/types.py | Separates forgiving provider normalization from strict user-filter validation. |
| docs/topology-status.md | Regenerated topology status counts for the new query helper file. |
| docs/plans/topology-target.yaml | Registers the new query helper and updates generated LOC metadata. |
| docs/cli-reference.md | Regenerates CLI docs to show message as an allowed root query filter value. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| def normalize_path_prefix(value: object) -> str: | ||
| """Normalize a user path prefix for component-bounded comparison.""" | ||
| raw = str(value).strip().replace("\\", "/") | ||
| while "//" in raw: | ||
| raw = raw.replace("//", "/") |
| "--message-type", | ||
| "message_type", | ||
| type=click.Choice(["summary", "tool_use", "tool_result", "thinking"]), | ||
| help="Filter by message content type (summary, tool_use, tool_result, thinking)", | ||
| type=click.Choice([message_type.value for message_type in MessageType]), | ||
| help="Filter by message content type (message, summary, tool_use, tool_result, thinking)", |
Summary Tighten query/read message-type and cwd-scoped filter semantics. Problem Invalid message_type values were accepted at user/API/MCP boundaries and could collapse to normal messages. Unknown since_session references broadened runtime results, same-cwd recall included unknown-cwd candidates, and cwd_prefix used string-prefix semantics that could include sibling repositories. Solution Add strict message-type filter validation while preserving forgiving parser normalization. Validate message_type in query specs, MCP query contracts, MCP get_messages, storage message reads, SQL filters, and runtime filters. Add path-component bounded cwd matching and use it for runtime since_session, runtime cwd_prefix, and SQL cwd_prefix pushdown. Unknown since_session references now produce no runtime-filter matches, and unknown-cwd candidates are excluded when the reference session has cwd evidence. Verification pytest -q tests/unit/core/test_query_fields.py tests/unit/core/test_cwd_prefix_filter.py tests/unit/archive/test_query_runtime_filters.py tests/unit/core/test_message_types.py tests/unit/storage/test_message_query_reads.py tests/unit/core/test_facade_api.py tests/unit/mcp/test_tool_contracts.py ruff check on changed query/storage/MCP/test files mypy polylogue/archive/query/spec.py polylogue/archive/message/types.py polylogue/archive/query/path_prefix.py polylogue/archive/query/runtime_filters.py polylogue/storage/backends/queries/filter_builder.py polylogue/storage/backends/queries/message_query_reads.py polylogue/mcp/query_contracts.py polylogue/mcp/server_tools.py devtools render-all --check devtools verify-topology && devtools verify-layering && devtools verify-test-ownership devtools verify --quick CI note: showcase-verify failed in GitHub Actions and was explicitly ignored per user instruction on 2026-05-02; local quick verification and focused tests passed. Ref #621
Summary
Tightens the query/read filter contract for message types and cwd-scoped session filters.
Problem
#621 tracks several query/read correctness gaps. This slice addresses the executable filter bugs: invalid
message_typevalues were accepted at user/API/MCP boundaries and normalized to normal messages; unknownsince_sessionreferences broadened to the full result set;since_sessionincluded no-cwd candidates even when the reference session had cwd evidence; andcwd_prefixused plain prefix matching that could include sibling repositories such as/repo/foo2when filtering/repo/foo.Solution
Add strict message-type filter validation while preserving forgiving parser/provider normalization.
ConversationQuerySpec.from_params(), MCP query requests, MCPget_messages, storage message reads, SQL conversation filters, and runtime filters now reject unknown message-type filters instead of collapsing them tomessage.Add a shared path-component bounded cwd prefix helper and use it in both runtime filters and SQL pushdown.
cwd_prefixnow matches exact paths and child paths only, andsince_sessioncwd matching uses the same semantics. Unknownsince_sessionreferences now return no runtime-filter matches, and unknown-cwd candidates are excluded when the reference session has cwd evidence.The CLI message-type choice and generated CLI docs now include
message, since normal-message filtering is now a supported strict filter value.Verification
pytest -q tests/unit/core/test_query_fields.py tests/unit/core/test_cwd_prefix_filter.py tests/unit/archive/test_query_runtime_filters.py tests/unit/core/test_message_types.py tests/unit/storage/test_message_query_reads.py tests/unit/core/test_facade_api.py tests/unit/mcp/test_tool_contracts.py(119 passed)ruff checkon changed query/storage/MCP/API test filesmypy polylogue/archive/query/spec.py polylogue/archive/message/types.py polylogue/archive/query/path_prefix.py polylogue/archive/query/runtime_filters.py polylogue/storage/backends/queries/filter_builder.py polylogue/storage/backends/queries/message_query_reads.py polylogue/mcp/query_contracts.py polylogue/mcp/server_tools.pydevtools render-all --checkdevtools verify-topology && devtools verify-layering && devtools verify-test-ownershipdevtools verify --quickdevtools verify --quickagain via pre-push hookRef #621
Summary by CodeRabbit
New Features
Bug Fixes
Tests