Skip to content

fix(delivery): keep route fields paired to channel during context merge#17337

Closed
Glucksberg wants to merge 1 commit intoopenclaw:mainfrom
Glucksberg:fix/13332-telegram
Closed

fix(delivery): keep route fields paired to channel during context merge#17337
Glucksberg wants to merge 1 commit intoopenclaw:mainfrom
Glucksberg:fix/13332-telegram

Conversation

@Glucksberg
Copy link
Copy Markdown
Contributor

@Glucksberg Glucksberg commented Feb 15, 2026

Fixes #13332

Problem

When Telegram and webchat share the same session (agent:main:main), mergeDeliveryContext() would inherit route fields (to, accountId, threadId) from the fallback context even when the primary and fallback contexts named different channels. This caused a Telegram-originated reply to pick up webchat's to/accountId values, mis-routing the response to the webchat UI instead of back to Telegram.

Fix

Added a channelsConflict guard in mergeDeliveryContext() — when both primary and fallback specify different channel names, route fields (to, accountId, threadId) are not inherited from the fallback. They remain paired to the selected channel.

This is a 13-line logic change in src/utils/delivery-context.ts.

Changed files

  • src/utils/delivery-context.ts — added channel-conflict check before fallback inheritance
  • src/utils/delivery-context.test.ts — 3 new test cases:
    • Cross-channel fields are NOT inherited (telegram vs discord)
    • Same-channel fields ARE inherited normally
    • Missing channel in fallback still merges normally
    • Updated normalizeSessionDeliveryFields test to verify cross-channel carryover is blocked

Tests

All 3 new unit tests pass. Existing delivery-context tests updated and passing.

Greptile Summary

Adds cross-channel conflict detection to mergeDeliveryContext() to prevent route field mis-pairing when Telegram and webchat share the same session. When primary and fallback contexts specify different channels, route fields (to, accountId, threadId) are not inherited from fallback, keeping them paired to the selected channel.

  • Fixes mis-routing issue where Telegram replies inherited webchat's route fields
  • Logic change is minimal (13 lines) and well-tested with 3 new test cases
  • Preserves existing behavior when channels match or when either context lacks a channel
  • Updated integration test verifies cross-channel carryover is blocked

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is targeted, well-tested, and solves a specific cross-channel routing bug. The logic is sound: it only blocks route field inheritance when both contexts explicitly specify different channels, preserving all existing behavior for same-channel and missing-channel scenarios. Three new unit tests directly validate the fix, and an integration test confirms the end-to-end behavior.
  • No files require special attention

Last reviewed commit: 4248f11

@Takhoffman
Copy link
Copy Markdown
Contributor

Superseded by #33786.

The synthesis PR carries forward the channel-paired delivery-context merge invariants with consolidated regression coverage.

@Takhoffman
Copy link
Copy Markdown
Contributor

Thanks again for this work.

This PR was triaged and merged using an AI-assisted review/synthesis workflow.

This landed indirectly via the synthesized PR #33786, and your contribution is credited in the changelog and as a co-author on the merge commit.

Closing this PR as superseded by #33786 (reason: superseded). If anything here looks incorrect or incomplete, reply to reopen and we can reassess.

@Takhoffman
Copy link
Copy Markdown
Contributor

Correction for accuracy: the synthesized work is credited in the changelog, but the squash merge commit for #33786 does not include explicit Co-authored-by trailers.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reply routes to webchat instead of originating Telegram channel

3 participants