Skip to content

fix(agent): preserve explicit recipient sessions#101507

Merged
steipete merged 15 commits into
mainfrom
codex/pr-73403-replay
Jul 7, 2026
Merged

fix(agent): preserve explicit recipient sessions#101507
steipete merged 15 commits into
mainfrom
codex/pr-73403-replay

Conversation

@steipete

@steipete steipete commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #41483. openclaw agent --agent ... --channel ... --to ... currently selects the agent main session before the explicit recipient can participate in routing, so configured DM isolation is ignored.

This is a maintainer replay of #73403 and the earlier focused #41557 because the current PR branch cannot be updated by maintainers.

Why This Change Was Made

  • Route explicit agent/channel/recipient requests through the existing channel-owned outbound session-route contract.
  • Respect session.dmScope, binding-level scope, identityLinks, configured mainKey, provider-native target forms, and account identity; do not hard-code a new scope or break the shipped main default.
  • Preserve explicit --session-key and --session-id precedence.
  • Resolve the canonical recipient session in the running Gateway, while embedded CLI runs use the same outbound route boundary after materializing required channel SecretRefs.
  • Scope session-only SecretRef materialization to the selected channel/account while retaining agent model/tool credentials.
  • Reserve Gateway idempotency before asynchronous target normalization, preserve exact-run cancellation during that pending lookup, and clear the reservation on routing or unavailable-session failures.
  • Require bundled providers to classify routes explicitly: canonical inbound identity, a bounded direct alias, a stable outbound-only delivery identity, or ambiguous. Ambiguous/mutable identities fail closed instead of leaking conversation context.

Canonical recipient keys use the same session-key format already used for inbound routing. Direct aliases are accepted only when configuration deliberately shares the selected main session and no binding can isolate peers. Stable outbound-only identities must be provider-namespaced and isolated from the agent main session; Synology Chat uses that form because Chat API recipient IDs and incoming-webhook sender IDs are separate namespaces.

User Impact

Configured shared-inbox isolation now applies consistently to Gateway-backed and embedded openclaw agent runs. Existing installations using session.dmScope: "main" keep main-session continuity where the provider can prove the direct-chat contract; isolated scopes produce canonical provider-owned keys. Public-channel aliases and ambiguous recipient identities no longer select a potentially unrelated session.

Evidence

  • Runtime-exact parent d385eb76355: Blacksmith Testbox passed 889 assertions across all 32 changed test files in 21 Vitest shards; the final commits only remove the release-owned changelog line and move the SMS helper import onto the current dedicated SDK facade.
  • Current head: the exact CI-reported channel shape guard and SMS route tests pass on Blacksmith Testbox (28 assertions); oxfmt --check and fresh local-patch Codex autoreview are clean.
  • Patch-equivalent Blacksmith Testbox: full pnpm check:changed green, including core/core-test/extension typechecks, changed-file lint, docs/changelog, import-cycle, storage, runtime, and repository guards.
  • Rebase range-diff: all 13 commits patch-equivalent after the final main refresh.
  • Fresh whole-branch Codex autoreview: no accepted or actionable findings after the provider-identity, binding-scope, cancellation, and SecretRef corrections.

Co-authored-by: vincentkoc [email protected]
Co-authored-by: pingfanfan [email protected]

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord channel: googlechat Channel integration: googlechat channel: imessage Channel integration: imessage channel: line Channel integration: line channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: msteams Channel integration: msteams channel: nextcloud-talk Channel integration: nextcloud-talk channel: nostr Channel integration: nostr channel: signal Channel integration: signal channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: tlon Channel integration: tlon channel: whatsapp-web Channel integration: whatsapp-web channel: zalo Channel integration: zalo channel: zalouser Channel integration: zalouser labels Jul 7, 2026
@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime cli CLI command changes commands Command implementations agents Agent runtime and tooling channel: feishu Channel integration: feishu channel: twitch Channel integration: twitch channel: irc channel: qqbot channel: qa-channel Channel integration: qa-channel channel: synology-chat channel: sms Channel integration: sms size: XL maintainer Maintainer-authored PR labels Jul 7, 2026
@clawsweeper

clawsweeper Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(agent): preserve explicit recipient sessions This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@steipete

steipete commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready proof for exact head 2d262aba66b4ff242a6586f9b4e78aefba2d5b78:

  • Exact-head hosted CI: 57/57 jobs green in https://github.com/openclaw/openclaw/actions/runs/28854044175.
  • Blacksmith Testbox lease tbx_01kwxsm2y0zbpdxw3tfb6b70fv: runtime-exact parent passed every changed test file, 32 files in 21 Vitest shards, 889 assertions.
  • Broad patch-equivalent gate: pnpm check:changed passed core/core-test/extension typechecks, changed-file lint, docs, import-cycle, storage, runtime, and repository guards.
  • Current-head correction proof:
    • node scripts/crabbox-wrapper.mjs run --id tbx_01kwxsm2y0zbpdxw3tfb6b70fv -- corepack pnpm exec oxfmt --check extensions/sms/src/channel.ts
    • node scripts/crabbox-wrapper.mjs run --id tbx_01kwxsm2y0zbpdxw3tfb6b70fv -- node scripts/run-vitest.mjs src/channels/plugins/bundled.shape-guard.test.ts extensions/sms/src/session-route.test.ts (28 assertions)
    • .agents/skills/autoreview/scripts/autoreview --mode local (clean, overall correct 0.99)
  • Native landing gate: OPENCLAW_TESTBOX=1 scripts/pr prepare-run 101507 passed with hosted exact-or-recent-rebase mode.

Before: explicit --agent --channel --to could select the agent main session before the recipient participated in routing, mixing distinct recipients. After: Gateway and embedded runs use provider-owned canonical routes; bounded shared-main aliases are accepted only under deliberate shared-main configuration, stable delivery-only identities remain channel-namespaced, and ambiguous/public/mutable aliases fail closed.

Known proof gap: no authenticated live Chatwoot/Instagram bridge was available. Coverage instead exercises the shared Gateway/embedded entry points, outbound routing, cancellation/idempotency, SecretRef scoping, and bundled provider route contracts, with exact-head hosted CI green.

@steipete
steipete merged commit a2a68d1 into main Jul 7, 2026
109 checks passed
@steipete
steipete deleted the codex/pr-73403-replay branch July 7, 2026 09:07
@steipete

steipete commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 8, 2026
* fix(agent): honor recipient session routing

Co-authored-by: vincentkoc <[email protected]>
Co-authored-by: pingfanfan <[email protected]>

* fix(agent): preserve canonical recipient routes

* fix(agent): require exact recipient routes

Co-authored-by: vincentkoc <[email protected]>

Co-authored-by: pingfanfan <[email protected]>

* fix(agent): harden recipient route resolution

* fix(imessage): require canonical recipient handles

* fix(agent): refine provider recipient exactness

* fix(agent): bound direct alias session routing

* fix(signal): preserve direct alias route type

* fix(agent): honor binding-scoped recipient sessions

* fix(routing): honor configured main session aliases

* fix(clickclack): align account-owned session routes

* fix(twitch): preserve canonical recipient sessions

* fix(routing): isolate stable outbound identities

* chore: defer recipient session changelog

* fix(sms): use dedicated channel SDK facade

---------

Co-authored-by: vincentkoc <[email protected]>
Co-authored-by: pingfanfan <[email protected]>
giodl73-repo pushed a commit to giodl73-repo/openclaw that referenced this pull request Jul 8, 2026
* fix(agent): honor recipient session routing

Co-authored-by: vincentkoc <[email protected]>
Co-authored-by: pingfanfan <[email protected]>

* fix(agent): preserve canonical recipient routes

* fix(agent): require exact recipient routes

Co-authored-by: vincentkoc <[email protected]>

Co-authored-by: pingfanfan <[email protected]>

* fix(agent): harden recipient route resolution

* fix(imessage): require canonical recipient handles

* fix(agent): refine provider recipient exactness

* fix(agent): bound direct alias session routing

* fix(signal): preserve direct alias route type

* fix(agent): honor binding-scoped recipient sessions

* fix(routing): honor configured main session aliases

* fix(clickclack): align account-owned session routes

* fix(twitch): preserve canonical recipient sessions

* fix(routing): isolate stable outbound identities

* chore: defer recipient session changelog

* fix(sms): use dedicated channel SDK facade

---------

Co-authored-by: vincentkoc <[email protected]>
Co-authored-by: pingfanfan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui channel: discord Channel integration: discord channel: feishu Channel integration: feishu channel: googlechat Channel integration: googlechat channel: imessage Channel integration: imessage channel: irc channel: line Channel integration: line channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: msteams Channel integration: msteams channel: nextcloud-talk Channel integration: nextcloud-talk channel: nostr Channel integration: nostr channel: qa-channel Channel integration: qa-channel channel: qqbot channel: signal Channel integration: signal channel: slack Channel integration: slack channel: sms Channel integration: sms channel: synology-chat channel: telegram Channel integration: telegram channel: tlon Channel integration: tlon channel: twitch Channel integration: twitch channel: whatsapp-web Channel integration: whatsapp-web channel: zalo Channel integration: zalo channel: zalouser Channel integration: zalouser cli CLI command changes commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: --to flag ignored when using --agent with custom channel, all sessions map to main

1 participant