Skip to content

fix: cross-channel message routing isolation#732

Open
f-liva wants to merge 10 commits intoRightNow-AI:mainfrom
f-liva:fix/cross-channel-routing-isolation
Open

fix: cross-channel message routing isolation#732
f-liva wants to merge 10 commits intoRightNow-AI:mainfrom
f-liva:fix/cross-channel-routing-isolation

Conversation

@f-liva
Copy link

@f-liva f-liva commented Mar 18, 2026

Summary

  • Fix missing ChannelContext on image retry path in dispatch_with_blocks(): the re-resolution path called send_message_with_blocks() without channel context, losing channel_type/sender_id/sender_name. Now uses send_message_with_blocks_and_context(), matching the text path.
  • Add per-channel message origin tagging: user messages entering the session are now prefixed with [via {channel}, from {sender}] so the LLM can distinguish conversations from different channels/users in the shared canonical session. Applied to both streaming and non-streaming kernel paths.

Closes #731

Test plan

  • Verify cargo build --workspace --lib compiles
  • Verify cargo test -p openfang-channels passes (9/9)
  • Verify cargo test -p openfang-runtime -- prompt_builder passes (38/38)
  • Manual test: send messages from two different channels to the same agent, verify responses don't cross channels
  • Manual test: send an image that triggers agent re-resolution, verify response goes to the correct channel
  • Verify session history shows [via whatsapp, from X] / [via telegram, from Y] tags on user messages

🤖 Generated with Claude Code

Federico Liva and others added 10 commits March 18, 2026 09:55
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ce, identity

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ipeline

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace commit SHA and run link with the commit message subject
for cleaner, more informative notifications.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The previous rebuild accidentally locked Cargo.toml at 0.4.4.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Integrate TypingEvent into MessageDebouncer to pause flush timers
while users are still composing, preventing premature dispatch when
sending text + images in rapid succession.

- Increase default debounce_ms from 3000 to 5000 for image uploads
- Add on_typing() to MessageDebouncer: pauses timer on is_typing=true,
  restarts on is_typing=false, safety cap always enforced
- Add typing_events() to ChannelAdapter trait (optional, default None)
- Wire typing event stream into start_adapter() select loop
- Telegram: add typing_tx/rx infrastructure, detect chat_action updates,
  auto-expire typing after 6s, emit is_typing=false on message arrival
- WhatsApp: add TODO for Baileys presence.update integration
- Add 4 unit tests for debouncer typing behavior
- Add 2 Telegram typing event tests
- Fix ChannelBridgeHandle mock for send_message_with_context

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fix two related bugs causing agents to confuse conversations across
different channels (e.g. responding in a WhatsApp group with a message
meant for a private Telegram chat):

1. Missing ChannelContext on image retry path: dispatch_with_blocks()
   called send_message_with_blocks() without channel context on agent
   re-resolution, losing channel_type/sender_id/sender_name. The text
   path (dispatch_message) already handled this correctly.

2. No per-channel message tagging in shared session: the canonical
   session merges all channels into one context by design, but Message
   structs carry no channel/sender metadata. Added tag_message_with_origin()
   to prefix user messages with [via {channel}, from {sender}] so the
   LLM can distinguish conversations from different channels/users.

Closes RightNow-AI#731

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Member

@jaberjaber23 jaberjaber23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR bundles too many unrelated changes and has critical issues. Please split into separate PRs.

Critical issues found:

  1. WhatsApp sendMessage JID regression — group JIDs (@g.us) are stripped and replaced with @s.whatsapp.net, breaking all group sends.
  2. Removal of has_any_content() guard causes unnecessary LLM retries for Thinking-only responses.
  3. Hot-reload drops tool_allowlist/tool_blocklist change detection (security-relevant fields).
  4. owner_ids settable via unauthenticated PATCH — anyone can change who gets "full access" verdicts.
  5. Removal of load_dotenv_files() from desktop app breaks API key loading.
  6. Removal of MCP env var resolution from vault breaks MCP subprocess credentials.
  7. WhatsApp adapter removes error checking on API responses — failed calls silently succeed.
  8. Hardcoded Italian strings in core runtime (invia, manda, al signore) — not appropriate for a language-agnostic agent OS.
  9. Default 5s debounce for ALL channels adds latency to every interaction.
  10. Hardcoded /tmp path instead of std::env::temp_dir().

Should be split into: (1) routing fix, (2) debouncer, (3) owner verification, (4) WhatsApp gateway, (5) Docker/CI — and each reviewed separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent responds in wrong channel — cross-channel context contamination

2 participants