Skip to content

fix(agents): count explicit-route current-source sends as source replies (embedded/app-server path) - #114680

Closed
zeroaltitude wants to merge 4 commits into
openclaw:mainfrom
zeroaltitude:fix/embedded-source-reply-explicit-route
Closed

zeroaltitude wants to merge 4 commits into
openclaw:mainfrom
zeroaltitude:fix/embedded-source-reply-explicit-route

Conversation

@zeroaltitude

Copy link
Copy Markdown
Contributor

What problem this solves

App-server harnesses (claude-bridge, and any other non-CLI-runner harness — isCliProvider() returns false for them since their model provider is the vendor id, not a registered CLI backend) route tool calls through embedded-agent-subscribe.handlers.tools.ts rather than cli-runner/execute.ts. Its call to isDeliveredMessageToolOnlySourceReplyResult() never passed allowExplicitSourceRoute, so an explicit-route message send that actually reached the current source conversation was rejected as source-reply evidence — tripping stranded-reply recovery and duplicating/failing the reply — even though nothing went wrong.

This is the embedded-path sibling of #113554 (openclaw-kg9), which patched the same gap in the CLI runner only. Root-caused live in production: agents running on the Claude app-server harness were genuinely sending replies (confirmed via provenance logs, message.send calls with TOOL_TAINT_EVAL: message.send(trusted)), but [source-reply/private-final] still fired and users saw "I generated a reply but could not deliver it to this chat."

See also #103927, a related but distinct sibling in the direct reply-agent and queued-followup-retry paths (src/auto-reply/reply/agent-runner.ts, followup-runner.ts) — different dispatch surface, same defect family, not a duplicate of this PR's files.

Fix

Add embeddedSendResolvesToCurrentSource() (new file, embedded-agent-send-resolution.ts), mirroring kg9's cliSendResolvesToCurrentSource(): resolve the send's destination through the same extractMessagingToolSend() path already used for delivery evidence, and compare it to what the same action would resolve to with no explicit route. Both resolutions go through the existing applyCurrentMessageProvider() current-channel injection (now exported) so they can't drift on provider even when the agent's send omits it. When they match, allowExplicitSourceRoute lets the delivered send count as source-reply evidence; a route that resolves elsewhere still fails safe and lets stranded-reply recovery fire for real outbound side effects.

Testing

  • New dedicated test file (6 cases) mirroring kg9's execute-messaging.test.ts coverage shape.
  • 2 new regression tests in embedded-agent-subscribe.handlers.tools.test.ts: an explicit-route send to the current source now registers messageToolOnlySourceReplyDelivered; an explicit-route send to a different conversation still correctly does not (fail-safe preserved).
  • tsgo:core, tsgo:core:test clean.
  • 505 vitest tests across 17 files green (targeted messaging/tool-handler suites + all consumers of the touched exports).
  • oxlint, config:schema:check, git diff --check clean.

Fixes openclaw-p3j (root-caused by another agent session, 2026-07-27).


Written by Tank (Claude), an AI agent operated by Eddie Abrams (zeroaltitude).

…ies in the embedded/app-server dispatch path

App-server harnesses (claude-bridge, and any other non-CLI-runner harness)
route tool calls through embedded-agent-subscribe.handlers.tools.ts rather
than cli-runner/execute.ts. Its call to
isDeliveredMessageToolOnlySourceReplyResult() never passed
allowExplicitSourceRoute, so an explicit-route `message` send that actually
reached the current source conversation was rejected as source-reply
evidence -- tripping stranded-reply recovery and duplicating/failing the
reply -- even though nothing went wrong. This is the embedded-path sibling
of openclaw-kg9, which only patched the CLI runner.

Add embeddedSendResolvesToCurrentSource(), mirroring kg9's
cliSendResolvesToCurrentSource(): resolve the send's destination through the
same extractMessagingToolSend() path used for delivery evidence, and compare
it to what the same action would resolve to with no explicit route. Both
resolutions go through the existing applyCurrentMessageProvider() current-
channel injection so they can't drift on provider even when the agent's send
omits it. When they match, allowExplicitSourceRoute lets the delivered send
count as source-reply evidence; a route that resolves elsewhere still fails
safe and lets stranded-reply recovery fire for real outbound side effects.

Fixes openclaw-p3j (root-caused by Tabitha, 2026-07-27, Discord #openclaw).
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 27, 2026
@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. labels Jul 27, 2026
@clawsweeper

clawsweeper Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 3, 2026, 12:07 AM ET / 04:07 UTC.

ClawSweeper review

What this changes

The branch resolves explicit embedded/app-server message destinations and lets a delivered send count as a source reply when it appears to target the active conversation.

Merge readiness

⛔ Blocked until real behavior proof is added - 8 items remain

This PR targets a real embedded delivery-evidence gap, but the existing P1 blocker remains: it treats sends as replies based only on provider and target, even though the shared resolver also distinguishes account and thread routing. It also still needs redacted after-fix embedded/app-server proof before merge.

Priority: P1
Reviewed head: 653d577d13325e1ef17c2f9794d0f35707841ab0

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The branch has focused test coverage but retains a high-impact route-identity defect and lacks required real embedded-runtime proof.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The PR body reports tests but contains no inspectable redacted after-fix app-server transcript, terminal output, runtime log, recording, or linked artifact showing delivery evidence and absence of stranded-reply fallback. 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.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR body reports tests but contains no inspectable redacted after-fix app-server transcript, terminal output, runtime log, recording, or linked artifact showing delivery evidence and absence of stranded-reply fallback. 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 7 items Current main lacks explicit-route verification: The embedded tool handler calls the source-reply predicate without allowExplicitSourceRoute; current main therefore rejects explicit routes unless the result already has the trusted current-source marker.
Incomplete destination comparison: The proposed helper accepts a route when only normalized to and provider match, omitting account and thread routing fields.
Resolver carries additional identity fields: extractMessagingToolSend resolves account, thread, implicit-thread, and thread-suppression information in addition to provider and target, so those fields are part of the destination identity that the PR is meant to verify.
Findings 1 actionable finding [P1] Compare every resolved route identity field
Security None None.

How this fits together

Embedded agent tool events turn model message calls into channel sends. The source-reply tracker records a successful reply so stranded-reply recovery does not emit a fallback for a message that already reached the source conversation.

flowchart LR
  A[Embedded app-server tool event] --> B[Message send arguments]
  B --> C[Resolve delivery destination]
  C --> D[Compare active source route]
  D --> E[Source-reply evidence]
  E --> F[Normal completion or recovery]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR body reports tests but contains no inspectable redacted after-fix app-server transcript, terminal output, runtime log, recording, or linked artifact showing delivery evidence and absence of stranded-reply fallback. 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.
  • Compare every resolved route identity field (P1) - The helper treats matching to and provider as the same source route, but extractMessagingToolSend also resolves accountId, threadId, and thread state. A send to another account or thread in the same chat can therefore mark messageToolOnlySourceReplyDelivered and suppress the fallback even though the active source was not answered. The previous review raised this full-destination requirement, and this unchanged head still omits it.
  • Resolve merge risk (P1) - A same-provider, same-target send to a different account or thread can be recorded as a source reply, suppressing stranded-reply recovery even though the actual source conversation was not answered.
  • Resolve merge risk (P2) - The PR body supplies test claims but no inspectable redacted embedded/app-server run proving that delivery evidence is recorded and the fallback is suppressed after the fix.
  • Resolve merge risk (P1) - The broader open PR fix(agents): prevent duplicate recovery after explicit source replies #113554 overlaps this handler path and another embedded path; landing parallel implementations could create divergent route-evidence logic.
  • Complete next step (P2) - A bounded mechanical repair can make route equivalence use the complete resolved destination and add regression coverage; contributor-supplied real runtime proof remains required before merge.
  • Improve patch quality - Compare the full resolved destination identity and add same-target/different-account and same-target/different-thread regression cases.
  • Improve patch quality - Post a redacted after-fix embedded/app-server transcript, terminal capture, or runtime log showing delivery evidence and no stranded-reply fallback.

Findings

  • [P1] Compare every resolved route identity field — src/agents/embedded-agent-send-resolution.ts:75-78
Agent review details

Security

None.

PR surface

Source +88, Tests +189. Total +277 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 89 1 +88
Tests 2 189 0 +189
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 278 1 +277

Review metrics

Metric Value Why it matters
Production vs test delta production +89/-1, tests +189/-0 The added production helper creates delivery-routing policy, so its complete destination contract needs explicit regression coverage before merge.

Merge-risk options

Maintainer options:

  1. Compare complete resolved destinations (recommended)
    Repair the helper to reject routes whose account, thread, or threading mode differs from the active source, add regression coverage, and provide redacted after-fix embedded-runtime proof.
  2. Consolidate with the broader embedded work
    Pause this narrower branch in favor of one shared resolver only after the overlapping open PR has a correct, proof-positive implementation.

Technical review

Best possible solution:

Compare the complete resolved send identity using the canonical messaging-send representation, including account and thread semantics, cover non-source account/thread cases, and then prove the repaired embedded/app-server flow with redacted runtime output.

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

Yes, from source: current main rejects explicit routes in this embedded call path without trusted route evidence, and the proposed helper can be inspected with same-target/different-account or thread inputs. A live app-server reproduction has not been supplied.

Is this the best way to solve the issue?

No. The route-equivalence check is incomplete because the canonical resolver includes account and threading fields that the PR does not compare; the fix should reuse or compare the full resolved destination contract.

Full review comments:

  • [P1] Compare every resolved route identity field — src/agents/embedded-agent-send-resolution.ts:75-78
    The helper treats matching to and provider as the same source route, but extractMessagingToolSend also resolves accountId, threadId, and thread state. A send to another account or thread in the same chat can therefore mark messageToolOnlySourceReplyDelivered and suppress the fallback even though the active source was not answered. The previous review raised this full-destination requirement, and this unchanged head still omits it.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: A false positive in source-reply delivery evidence can suppress recovery after a reply was sent to the wrong account or thread.
  • merge-risk: 🚨 message-delivery: The patch changes the decision that determines whether a send is considered delivered to the source conversation.
  • 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: The PR body reports tests but contains no inspectable redacted after-fix app-server transcript, terminal output, runtime log, recording, or linked artifact showing delivery evidence and absence of stranded-reply fallback. 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

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/agents/embedded-agent-send-resolution.test.ts.
  • [P1] node scripts/run-vitest.mjs src/agents/embedded-agent-subscribe.handlers.tools.test.ts.
  • [P1] git diff --check.

What I checked:

Likely related people:

  • Peter Steinberger: Current-main blame attributes the delivery-evidence call site to this contributor’s commit; the local partial history does not establish a stronger feature-owner trail. (role: recent current-main contributor; confidence: medium; commits: 443821f49b63; files: src/agents/embedded-agent-subscribe.handlers.tools.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (5 earlier review cycles)
  • reviewed 2026-07-27T18:32:34.141Z sha 836881c :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-30T07:39:36.360Z sha d83d1f8 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-31T04:39:55.060Z sha 41ceda7 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-01T23:48:34.458Z sha 653d577 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-02T06:57:41.743Z sha 653d577 :: needs real behavior proof before merge. :: [P1] Compare the full resolved destination before accepting a source reply

zeroaltitude added a commit to zeroaltitude/openclaw that referenced this pull request Jul 27, 2026
…ite-#3

A separately-dispatched session opened openclaw#114680 for the same defect
(embedded-agent-subscribe.handlers.tools.ts's isDeliveredMessageToolOnlySourceReplyResult
call missing allowExplicitSourceRoute) before this branch's fix for the
same call site landed here, then openclaw#114680 was merged into origin/integration.
Landing both would leave two different implementations touching the same
lines.

Revert this branch's embedded-agent-subscribe.handlers.tools.ts (+ test)
changes back to their pre-fix state, since openclaw#114680's embeddedSendResolvesToCurrentSource
already covers that call site and is deployed. Keep everything else from
this branch's embedded-agent work: messagingToolSendResolvesToCurrentSource
(embedded-agent-subscribe.tools.ts) and its wiring into
message-tool-terminal.ts's installMessageToolOnlyTerminalHook (call site #3,
the native agent-loop afterToolCall terminal hook) — openclaw#114680 never touched
that file, so it's still a real, unfixed gap this branch closes.

Net result: this branch now covers the original CLI-runner fix (openclaw-kg9)
plus call site #3 only; openclaw#114680 covers call site #1. No overlap, no
duplicate implementations of the same check.

Beads: openclaw-yob
…eply-explicit-route

# Conflicts:
#	src/agents/embedded-agent-subscribe.handlers.tools.ts
@vincentkoc

Copy link
Copy Markdown
Member

Closing as a duplicate of #113554.

#113554 is the older same-author branch and already owns the CLI runner plus both embedded-agent send-resolution surfaces covered here. Keeping both open would split one invariant across overlapping implementations.

The canonical branch still needs repair before landing: explicit-route reply accounting must compare the full effective route, including provider/account, destination, thread, and suppression state. This close is consolidation, not a claim that the underlying bug is fixed.

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. 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: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants