Fix DM persistence + bidirectional DM history ordering#402
Fix DM persistence + bidirectional DM history ordering#402khaliqgant wants to merge 2 commits intomainfrom
Conversation
|
Addressed Devin feedback in latest commit (
Validation run:
|
| sinceTs: queryPayload.sinceTs, | ||
| from: queryPayload.from, | ||
| to: queryPayload.to, | ||
| bidirectional: Boolean(queryPayload.from && queryPayload.to), |
There was a problem hiding this comment.
🔴 MESSAGES_QUERY unconditionally forces bidirectional mode, breaking existing unidirectional from+to queries
In the MESSAGES_QUERY handler, bidirectional is unconditionally set to true whenever both from and to are provided: bidirectional: Boolean(queryPayload.from && queryPayload.to). This changes the semantics of all existing queries that specify both fields.
Root Cause and Impact
Previously, queryMessages({ from: 'Alice', to: 'Bob' }) returned only messages sent from Alice to Bob. After this change, it also returns messages from Bob to Alice.
The MessagesQueryPayload type at packages/protocol/src/types.ts:677 does not expose a bidirectional field, so clients have no way to opt out of this behavior. Every caller that provides both from and to is affected:
- The MCP tool at
packages/mcp/src/tools/relay-messages.ts:38-45passes user-suppliedfromandtodirectly. A query like "show me messages from Alice to Bob" would now also return messages from Bob to Alice, which is semantically incorrect for that use case. - The SDK
queryMessagesmethod atpackages/sdk/src/client.ts:1451also passes both fields through.
The bidirectional flag was correctly added to the MessageQuery interface (packages/storage/src/adapter.ts:52-53) as an opt-in field, but the server forces it on for all queries. The fix should either: (a) let the client control this via a bidirectional field in MessagesQueryPayload, or (b) only enable it for DM-specific query paths rather than all MESSAGES_QUERY requests.
Prompt for agents
The bidirectional flag should not be unconditionally forced for all MESSAGES_QUERY requests. Two options:
1. (Preferred) Add a `bidirectional?: boolean` field to `MessagesQueryPayload` in packages/protocol/src/types.ts (around line 689), then in packages/daemon/src/server.ts line 1468, use `bidirectional: queryPayload.bidirectional ?? false` instead of `Boolean(queryPayload.from && queryPayload.to)`. This lets clients opt in to bidirectional queries.
2. (Quick fix) Change line 1468 in packages/daemon/src/server.ts to only pass `bidirectional: false` (or remove it entirely), and let the dashboard client explicitly request bidirectional mode when it needs DM conversation history.
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
dm:*channel messages in router storage path (including sender self-copy)getMessages()so{ from, to }queries match both directions and return chronological resultsWhy
Dashboard DM history needed sender-visible persistence plus stable server-side conversation retrieval.
Validation
npm test -- sqlite-adapter.test.ts(packages/storage)npm test -- router.test.ts(packages/daemon)Coordination