Merged
Size
M
Change Breakdown
Bug Fix85%
Docs10%
Testing5%
#66073Gateway/sessions: preserve shared session route on system events

Session routing preserved from synthetic system events

Heartbeat, cron, and exec events no longer overwrite shared-session routing metadata with synthetic targets, preventing phantom delivery attempts.

When system events like heartbeat polling or cron triggers ran inside a shared session, they were writing synthetic routing values like {"to":"heartbeat"} back into the session state. Later delivery attempts — including actual cron announces and user messages — would then resolve to this corrupted context instead of the real channel and recipient.

The fix introduces a guard in the session initialization logic that recognizes system event turns. When detected, the session preserves its existing route metadata (lastChannel, lastTo, lastAccountId, lastThreadId, deliveryContext) rather than recomputing from the synthetic event context. A parallel change prevents these events from deriving a synthetic origin that would overwrite the session's real delivery context.

In practice, this means Discord cron announces no longer fail with "Unknown Channel" because heartbeat state leaked into the session, webchat sessions don't lose user messages after heartbeat polling, and delivery targets resolve correctly instead of routing to internal placeholders like @heartbeat.

View Original GitHub Description

Summary

  • stop heartbeat, cron-event, and exec-event turns from overwriting shared-session route fields
  • preserve existing session origin metadata for those synthetic turns instead of persisting synthetic provider/target values
  • add focused regressions for route-less sessions and shared-session heartbeat retargeting

Testing

  • OPENCLAW_TEST_PROFILE=serial OPENCLAW_TEST_SERIAL_GATEWAY=1 pnpm test -- src/auto-reply/reply/session.test.ts src/auto-reply/reply/session.heartbeat-no-reset.test.ts
  • pnpm build

Related

  • #63733
  • #21834
  • #35300
  • adjacent but intentionally not claimed here: #65847, #45806
© 2026 · via Gitpulse