fix(chat): honor to: end-to-end — derive dm:<sorted> channel + preserve through cloud sync#1322
Merged
Conversation
…erve through cloud sync The `to:` field was accepted at the chat send boundary but never consulted for routing — every DM fell through to #general: // before const channel = message.channel || 'general' This wires `to:` to a stable `dm:<sorted endpoints>` channel when no explicit channel is provided, so a→b and b→a hash to the same thread. Cloud sync now preserves `to:` over the wire alongside the dm channel (belt-and-suspenders; cloud schema unchanged, handler ignores `to` for now). Inbox routing already DM-aware, no changes there. Pairs with the openclaw plugin fix (sendText was hardcoding "general" and dropping ctx.to). Together those two cuts close the routing lie without schema/inbox/UI/auth/backfill changes. Tests: 7 new in chat-dm-routing.test.ts cover sorted-endpoint derivation, case/whitespace normalization, explicit-channel precedence, and that non-DM messages still default to #general. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3 tasks
Internal-names guard caught the example name in the comment block. Same intent, generic phrasing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Wires the chat send
to:field to a real routing destination so DMs stop falling through to#general.chat.ts— whento:is set andchannelis absent, derive a stabledm:<sorted endpoints>channel (a→b and b→a hash to the same thread, lowercased + trimmed)cloud.ts— preserveto:over the cloud sync wire alongside the dm channel (belt-and-suspenders; cloud schema unchanged, handler ignorestofor now)tests/chat-dm-routing.test.ts(7 tests)No schema change · no inbox change · no UI in this PR · no auth/model rewrite · no backfill.
This is PR1 of the DM lane — pairs with the openclaw plugin fix (
reflectt-channel-openclaw#TBD) whereoutbound.sendTextwas hardcoding"general"and droppingctx.to. Together those two cuts close the routing lie at the source. PR2 will be the minimal canvas/UI subscribe seam for current-userdm:*threads.Routing truth proven
outbound.sendText({ to: "kai", ... })) → lands indm:<sorted>, not#general(after openclaw PR)send_message({ from, to, content })) → lands indm:<sorted>, not#generalto:on the wire (cloud handleChatSync silently drops the field for now — future schema add can pick it up additively)inbox.ts:320(if (message.to === agent) return { priority: 'high', reason: 'dm' }); no change neededTest plan
npx vitest run tests/chat-dm-routing.test.ts— 7/7 passnpx tsc --noEmit— cleane4e35463-…): two agents DM each other, observedm:<sorted>inchat_messages, observe absence in#general🤖 Generated with Claude Code