Repository navigation
fix: datetime UTC, MCP filter wiring, export fields, paste role guard - #821
Conversation
Problem: - _iso_to_epoch interpreted naive datetimes in local time (not UTC), shifting --since/--until by the local offset (#820 item 1) - detect_paste() ran on all messages, flagging assistant code blocks as paste and inflating Codex paste rate to 92% (#801 item 1) - ConversationMessagePayload dropped content_blocks, provider_meta, and parent_id from JSON/YAML/JSONL exports (#811) - 15+ filter dimensions from ConversationQuerySpec had zero MCP tool parameter instrumentation — defined but never activatable from any MCP client (#819 item 1) - has_paste alias missing from MCP query param normalization, so MCP clients could never filter by paste (#819) Solution: - _iso_to_epoch: attach timezone.utc to naive datetimes before calling .timestamp() — dates are now UTC-correct - materialization_runtime.py: guard detect_paste() behind msg.role == "user" so only user messages are paste-evaluated - ConversationMessagePayload: add content_blocks, provider_meta, parent_id fields and populate from Message model - MCP search + list_conversations: expose all missing filter params (contains, exclude_text, exclude_provider, exclude_tag, has_type, conv_id, until, latest, reverse, sample, has_paste, typed_only, max_messages, similar_text, since_session_id) - query_contracts.py: add has_paste → filter_has_paste alias - fields.py: add mcp_names to 13 field descriptors that lacked them - Regenerate MCP tool schema witness to match expanded signatures Fixes #820 (partial — FK and INSERT OR IGNORE deferred) Fixes #801 (item 1 — role guard; ground-truth calibration deferred) Fixes #811 (export field gaps) Fixes #819 (item 1 — filter wiring; pagination + error handling next) Co-Authored-By: Claude Opus 4.7 <[email protected]>
📝 WalkthroughWalkthroughThis PR expands the MCP query interface with additional optional filter and constraint parameters (such as ChangesMCP Query Interface Expansion
Paste Detection Scope Adjustment
UTC Timezone Normalization
Message Payload Enrichment
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
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 |
There was a problem hiding this comment.
Pull request overview
This PR fixes four archive/MCP surface regressions: UTC handling for date filters, paste detection scoping, richer exported message payloads, and missing MCP query filter wiring. It mainly tightens how existing query/export infrastructure exposes and serializes conversation data across storage, rendering, and MCP tool surfaces.
Changes:
- Fixes naive ISO timestamp handling in SQLite filter pushdown and limits paste detection to user messages.
- Expands conversation/message surface payloads and MCP query contracts to expose more stored fields and filters.
- Regenerates the MCP tool-schema witness to match the updated public MCP tool parameters.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
tests/data/witnesses/mcp-tool-schemas.json |
Updates the committed MCP tool JSON Schema witness for the expanded query parameters. |
polylogue/surfaces/payloads.py |
Extends message payload serialization with structured blocks, provider metadata, and parent linkage. |
polylogue/storage/sqlite/queries/filter_builder.py |
Fixes naive ISO datetime conversion to interpret unzoned timestamps as UTC. |
polylogue/pipeline/materialization_runtime.py |
Restricts paste detection to user-authored messages during materialization. |
polylogue/mcp/server_tools.py |
Adds many missing MCP query parameters to search and list_conversations. |
polylogue/mcp/query_contracts.py |
Threads the new MCP parameters into query-spec construction and adds alias normalization. |
polylogue/archive/query/fields.py |
Registers MCP-facing names for previously unwired query-field descriptors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| sort: str | None = None, | ||
| reverse: bool = False, | ||
| latest: str | None = None, |
| content_blocks=message.content_blocks, | ||
| provider_meta=message.provider_meta, |
| sort: str | None = None, | ||
| reverse: bool = False, | ||
| latest: str | None = None, |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6cbb49c5fd
ℹ️ 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".
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@polylogue/mcp/query_contracts.py`:
- Around line 69-70: The MCP contracts treat latest as a boolean presence flag
but are currently typed as str | None; change the latest field in
MCPConversationQueryRequest and MCPArchiveQueryRequest to be latest: bool =
False (not str | None) so generated schemas mark it as a boolean, and update the
corresponding function signatures in server_tools.py to accept latest: bool =
False (replace any str | None or Optional[str] usages) so callers and schema
coercion won't convert "false" strings into True. Ensure any related default
handling or docstrings still assume a boolean presence flag.
🪄 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: 5746cd84-9942-4550-b769-fad44e709ac2
📒 Files selected for processing (7)
polylogue/archive/query/fields.pypolylogue/mcp/query_contracts.pypolylogue/mcp/server_tools.pypolylogue/pipeline/materialization_runtime.pypolylogue/storage/sqlite/queries/filter_builder.pypolylogue/surfaces/payloads.pytests/data/witnesses/mcp-tool-schemas.json
| reverse: bool = False | ||
| latest: str | None = None |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
rg -nP --type=py '\blatest\s*:' polylogue/mcp/query_contracts.py polylogue/mcp/server_tools.py polylogue/archive/query/spec.py polylogue/archive/query/fields.pyRepository: Sinity/polylogue
Length of output: 380
🏁 Script executed:
#!/bin/bash
# Check lines 111-114 in query_contracts.py to see if there's another occurrence
head -115 polylogue/mcp/query_contracts.py | tail -20Repository: Sinity/polylogue
Length of output: 849
🏁 Script executed:
#!/bin/bash
# Get more context around the latest usage in archive/query/spec.py
head -380 polylogue/archive/query/spec.py | tail -15Repository: Sinity/polylogue
Length of output: 589
🏁 Script executed:
#!/bin/bash
# Search for how latest is used in the query modules
rg -B2 -A2 'latest' polylogue/archive/query/spec.py | head -50Repository: Sinity/polylogue
Length of output: 675
🏁 Script executed:
#!/bin/bash
# Check what's at lines 111-114 in query_contracts.py to see the complete picture
sed -n '105,120p' polylogue/mcp/query_contracts.pyRepository: Sinity/polylogue
Length of output: 695
🏁 Script executed:
#!/bin/bash
# Verify server_tools.py occurrences at lines 67 and 157
rg -B3 -A3 'latest.*str.*None' polylogue/mcp/server_tools.pyRepository: Sinity/polylogue
Length of output: 553
Make latest a boolean flag across all MCP request types.
The query stack treats latest as a boolean presence switch, but MCP contracts expose it as str | None. This creates a type mismatch that generates incorrect MCP schemas and coerces string values like "false" to True when converted with bool().
Fix both MCPConversationQueryRequest (lines 69–70) and MCPArchiveQueryRequest (lines 111–114) in query_contracts.py, as well as the corresponding function signatures in server_tools.py:
Suggested fixes
- latest: str | None = None
+ latest: bool = FalseThis change should be applied to:
polylogue/mcp/query_contracts.py:70(MCPConversationQueryRequest)polylogue/mcp/query_contracts.py:111-114(MCPArchiveQueryRequest)polylogue/mcp/server_tools.py:67(function parameter)polylogue/mcp/server_tools.py:157(function parameter)
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| reverse: bool = False | |
| latest: str | None = None | |
| reverse: bool = False | |
| latest: bool = False |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@polylogue/mcp/query_contracts.py` around lines 69 - 70, The MCP contracts
treat latest as a boolean presence flag but are currently typed as str | None;
change the latest field in MCPConversationQueryRequest and
MCPArchiveQueryRequest to be latest: bool = False (not str | None) so generated
schemas mark it as a boolean, and update the corresponding function signatures
in server_tools.py to accept latest: bool = False (replace any str | None or
Optional[str] usages) so callers and schema coercion won't convert "false"
strings into True. Ensure any related default handling or docstrings still
assume a boolean presence flag.
|
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
Fixes 4 bugs across datetime handling, export payloads, paste detection, and MCP filter instrumentation. Closes 3 issues fully and 1 partially.
Problem
_iso_to_epochinterpreted naive ISO dates in local time — midnight UTC shifted hours when--since/--untilfilters ran against SQLite epoch valuesdetect_paste()ran on all message roles — assistant code blocks were flagged as paste, inflating Codex paste rate to 92%ConversationMessagePayloadserialized onlyid,role,text,timestamp,message_type— droppingcontent_blocks(thinking, tool_use, tool_result),provider_meta(API duration, model, usage), andparent_idfrom all JSON/YAML/JSONL exportsConversationQuerySpechad zero MCP tool parameter instrumentation — defined in the query model but never activatable from any MCP clientSolution
filter_builder.py: Attachtimezone.utcto naive datetimes before.timestamp()materialization_runtime.py: Guarddetect_paste()behindmsg.role == "user"surfaces/payloads.py: Addcontent_blocks,provider_meta,parent_idtoConversationMessagePayloadmcp/server_tools.py: Expose 17 missing filter params on bothsearchandlist_conversationstoolsmcp/query_contracts.py: Add missing fields toMCPConversationQueryRequest, addhas_paste→filter_has_pastealiasarchive/query/fields.py: Addmcp_namesto 13 field descriptorstests/data/witnesses/: Regenerate MCP tool schema witnessVerification
Ref #820, #801, #811, #819
🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
contains,exclude_text,exclude_provider,exclude_tag,has_type,conv_id,until,reverse,latest,max_messages,sample, andsimilar_text.Bug Fixes