Skip to content

fix(sessions-send): normalize sourceSessionKey to dmScope-resolved canonical key - #107469

Closed
ChengKe771 wants to merge 1 commit into
openclaw:mainfrom
ChengKe771:ChengKe771/issue107399
Closed

ChengKe771 wants to merge 1 commit into
openclaw:mainfrom
ChengKe771:ChengKe771/issue107399

Conversation

@ChengKe771

Copy link
Copy Markdown
Contributor

What Problem This Solves

When session.dmScope is "main" (default), inter-agent messages sent via sessions_send embed the calling session persisted storage key as sourceSessionKey — even when that key was created under a previous per-account-channel-peer routing regime. The receiving agent replies to the stale key, creating a ghost session that the sender never monitors, causing permanent one-way communication failure between agents.

Split path:

  1. Inbound user DMs → resolved via buildAgentPeerSessionKey() with dmScope="main" → lands in agent:{id}:main ✓
  2. Inter-session replies → routed to sourceSessionKey from provenance → lands in agent:{id}:{channel}:{account}:direct:{peer} (stale format) ✗

Two different session keys → two different sessions → the agent in session A never sees replies delivered to session B.

Why This Change Was Made

The sessions_send tool passed opts.agentSessionKey verbatim into inputProvenance.sourceSessionKey. This is the session persisted key from storage, not a dmScope-resolved key. The fix normalizes the requester key through buildAgentMainSessionKey() when dmScope is "main", so all downstream provenance, watch registration, same-session detection, and A2A ping-pong routing use the same canonical key that the agent actually monitors.

User Impact

Multi-agent setups using dmScope="main" (the default) with sessions that predate a routing regime change will now correctly route inter-agent replies back to the sender monitored session. No config changes required. Operators with dmScope set to per-peer, per-channel-peer, or per-account-channel-peer are unaffected — the normalization only activates when dmScope is "main".

Evidence

  • sessions-send-helpers.test.ts: 10/10 passed
  • sessions-send-tool.a2a.test.ts: 25/25 passed
  • oxfmt and git diff --check clean

Fixes #107399

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Jul 14, 2026
@ChengKe771

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review,pls

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 14, 2026
@clawsweeper

clawsweeper Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 16, 2026, 7:34 AM ET / 11:34 UTC.

Summary
The PR canonicalizes legacy DM requester session keys to the agent main session under dmScope="main" for provenance, watch registration, same-session detection, and inter-agent replies.

PR surface: Source +26. Total +26 across 1 file.

Reproducibility: no. live current-main reproduction was established during this review, but the source path and linked production report provide a high-confidence source reproduction: stale DM provenance directs replies to a different persisted session key.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: serialized state: src/agents/tools/sessions-send-tool.ts, unknown-data-model-change: src/agents/tools/sessions-send-tool.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #107399
Summary: This PR is the proposed fix for the canonical stale sourceSessionKey routing issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🦪 silver shellfish
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Replace the direct token test with complete structural recognition of supported legacy DM routes and add regression cases for every marker.
  • [P1] Resolve the current main conflict and provide redacted after-fix multi-agent runtime evidence.

Proof guidance:

  • [P1] Needs real behavior proof before merge: Only focused automated tests and static checks are reported; before merge, add a redacted live multi-agent transcript, terminal output, or runtime log showing a stale DM requester receiving the reply in its monitored main session while a non-DM caller remains unchanged. Updating the PR body should trigger review, or a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] Legacy requester keys using another recognized DM marker can still route replies into an unmonitored ghost session after this patch.
  • [P1] The branch conflicts with current main; resolving that conflict may alter the reviewed session-routing behavior and requires a fresh review.

Maintainer options:

  1. Complete the route classifier before merge (recommended)
    Replace the single-token check with structural legacy-DM recognition, add coverage for every accepted DM marker and unaffected non-DM routes, resolve the conflict, and attach redacted live proof.

Next step before merge

  • [P1] The contributor should resolve the repeated route-classification finding, refresh the conflicted branch, and supply real after-fix proof; contributor-environment proof cannot be produced by the repair lane.

Security
Cleared: The focused runtime change adds no dependency, secret, permission, download, workflow, or supply-chain surface, and no concrete security regression was found.

Review findings

  • [P1] Recognize every legacy DM route before canonicalizing — src/agents/tools/sessions-send-tool.ts:577
Review details

Best possible solution:

Use a shared structural session-route classifier that recognizes every supported legacy DM key shape, canonicalize only those routes under dmScope="main", cover each accepted legacy marker plus unchanged non-DM callers, and demonstrate the result in a real multi-agent run.

Do we have a high-confidence way to reproduce the issue?

No live current-main reproduction was established during this review, but the source path and linked production report provide a high-confidence source reproduction: stale DM provenance directs replies to a different persisted session key.

Is this the best way to solve the issue?

No. Canonicalizing legacy DM requesters at the sessions_send boundary is appropriately narrow, but the current literal-token heuristic does not cover every recognized legacy DM route; a shared structural classifier is safer.

Full review comments:

  • [P1] Recognize every legacy DM route before canonicalizing — src/agents/tools/sessions-send-tool.ts:577
    The new classifier only accepts remainders containing direct, but OpenClaw also recognizes the legacy dm peer-kind terminology. A requester key using that accepted marker remains unnormalized under dmScope="main", so the reply can still enter the ghost session this PR intends to eliminate. Use the shared structural route classification and cover both recognized markers. This is the prior P1 finding on the unchanged head, not a late discovery.
    Confidence: 0.93

Overall correctness: patch is incorrect
Overall confidence: 0.93

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against f7a665aaa14d.

Label changes

Label justifications:

  • P1: The unresolved bug can permanently prevent inter-agent replies from reaching the session an affected user monitors.
  • merge-risk: 🚨 message-delivery: Incomplete requester-key classification can continue routing replies to the wrong session rather than the active sender session.
  • merge-risk: 🚨 session-state: The patch changes the canonical session identity used for provenance, watch registration, same-session checks, and A2A bookkeeping.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Only focused automated tests and static checks are reported; before merge, add a redacted live multi-agent transcript, terminal output, or runtime log showing a stale DM requester receiving the reply in its monitored main session while a non-DM caller remains unchanged. Updating the PR body should trigger review, or a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +26. Total +26 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 33 7 +26
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 33 7 +26

What I checked:

Likely related people:

  • steipete: Recent merged history attributes substantial sessions_send routing, validation, and A2A behavior around this tool to work merged under commit 7130e56f872a. (role: recent adjacent owner; confidence: medium; commits: 7130e56f872a; files: src/agents/tools/sessions-send-tool.ts, src/agents/tools/sessions-send-tool.a2a.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (2 earlier review cycles)
  • reviewed 2026-07-14T16:03:30.175Z sha a0c14adbcecc35df335002ca93df45564d7f2705 :: needs real behavior proof before merge. :: [P1] Limit normalization to legacy DM requester keys
  • reviewed 2026-07-16T02:26:32.014Z sha 83f0190 :: needs real behavior proof before merge. :: [P1] Handle every recognized legacy DM route

…esolved canonical key

Parse the requester key and only canonicalize when the rest contains a
"direct" peer-kind segment (legacy per-peer / per-channel-peer /
per-account-channel-peer DM keys). Group, cron, hook, subagent, and
other non-DM callers preserve their exact session key for correct
routing, watch registration, and A2A ping-pong bookkeeping.

Fixes openclaw#107399
@ChengKe771
ChengKe771 force-pushed the ChengKe771/issue107399 branch from a0c14ad to 83f0190 Compare July 15, 2026 02:57
@ChengKe771

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review,pls

@ChengKe771 ChengKe771 closed this Jul 16, 2026
@ChengKe771
ChengKe771 deleted the ChengKe771/issue107399 branch July 16, 2026 07:51
@ChengKe771
ChengKe771 restored the ChengKe771/issue107399 branch July 16, 2026 11:27
@ChengKe771 ChengKe771 reopened this Jul 16, 2026

Copy link
Copy Markdown
Contributor

Thank you, @ChengKe771, for identifying and working on this fix. The issue is now resolved by #115756, merged as 81171d0. Your contribution is credited in the landed commit with a Co-authored-by trailer. The final implementation also includes regression coverage for both direct and dm session keys, real authenticated Gateway behavior, isolated binding/account routes, and the SQLite session lifecycle. Closing this PR as superseded by the merged, credited fix. Thank you again!

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

Labels

agents Agent runtime and tooling merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: sessions_send sourceSessionKey ignores dmScope — stale key causes permanent inter-agent communication failure

2 participants