Skip to content

fix(a2a): avoid duplicate source replies after message delivery - #137923

Merged
steipete merged 4 commits into
mainfrom
codex/a2a-source-delivery-receipt
Sep 4, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/a2a-source-delivery-receipt

Conversation

@steipete

@steipete steipete commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A same-session sessions_send target can deliver through the message tool and then have A2A announce its reply again. The regression produces two requester-visible markers when the completed run reports source delivery but display history lacks the successful tool-result row.

Why This Change Was Made

The message tool now records confirmed final delivery to its resolved external source route. Pi, Codex, CLI, and nested-tool collectors preserve that fact before result middleware and carry it into the existing terminal receipt. A2A consumes the receipt and canonical terminal reply, deleting history baselines, fingerprints, mirror-boundary inference, and fallback reads.

The existing display marker cannot supply this fact: A2A enters through webchat and can resolve its external source inside the message tool. The producer therefore compares the completed delivery with the prepared source route while preserving authorization and display-marker semantics. The historical host-load trace does not establish a wait-before-write race; the demonstrated defect is deciding whether to repeat a side effect from a lossy display projection.

User Impact

Already delivered source replies are not announced again, including webchat requesters and supported reply, thread-reply, and poll actions. Progress, partial, dry-run, internal-UI, and other-destination operations do not claim final external delivery. Cross-session announcements and internal-UI forwarding remain available. A failure after delivery remains visible without recommending a resend.

Evidence

  • The actual createSessionsSendTool regression fails on pre-fix c86d5b2d270 with two markers and passes with the repair. Nested-tool regressions establish receipt capture before output transformation or rejection.
  • ClawSweeper's P1 and both rank-up moves are addressed: the existing action-specific route predicates and plugin settlement projection cover reply variants. Three final-delivery cases failed pre-fix; all 15 final/other-target/partial/progress/dry-run cases pass. The focused owner/A2A/waiter run passed 361 tests; additional A2A/waiter/Gateway and route-contract runs passed 237 and 41 tests.
  • Full OPENCLAW_BUILD_PRIVATE_QA=1 pnpm build passed. The rebased QA runtime build also passed. pnpm check:changed passed with isolated OPENCLAW_STATE_DIR, including typechecks, lint, all three dead-export scans, and runtime-cycle checks. The final test-only cleanup passed another isolated check and 104 focused tests.
  • Independent Codex autoreview found no actionable P0–P2 findings on the full rebased PR or the final fixture cleanup. Production +233/-371, net -138; tests/test support +891/-904, net -13. Docs and QA/ratchet files are separate.
  • Real Gateway mirror proof has three independent first-attempt passes on the final rebased production build, alongside the native-thread scenario. Each checks the correlated sourceReplyDelivered=true receipt and exactly one marker throughout the unchanged eight-second window. Retries are disabled. Default/disabled/allowlist A2A policy scenarios also passed. A fresh live-provider group-visible-reply-tool run passed on the same rebased production build; the A2A scenario itself uses a deterministic mock provider.

The additional native-thread scenario exposed a QA-channel target mismatch. Three new matcher cases failed before the correction, and all 37 QA-channel tests passed afterward. Main independently received the owner correction in #137964; this PR retains the negative cases and disables scenario retries without duplicating that production fix. The rebased native-thread scenario passed first attempt, suppressing fallback while preserving a distinct later final reply. Main's canonical CLI terminal outcome is retained.

CI initially exposed two test-harness mismatches, corrected with 90 passing focused tests. After rebase, the test file exceeded its size limit; consolidating 12 identical harness fixtures removed 40 lines without deleting cases or assertions. A separate CI plugin-reload test completed its assertions but timed out in teardown; the stalled cleanup owner remains unproven. An unchanged local diagnostic was interrupted after prolonged module initialization without reaching case results; it is inconclusive, not a pass. Exact-head CI 33849203084 passed on bfa70f4047e, including that shard; all 137 applicable checks pass. The earlier teardown stall remains unexplained.

No database schema, configuration, protocol-version change, retry, or timeout increase is added. ClawSweeper's stored-data warning refers to QA YAML, not runtime persistence; no migration is involved.

Named follow-ups: identify the plugin-reload teardown stall observed in CI run 33846850552; extend the QA transcript summary's currentSourceToolDeliveries projection to nested code-mode activity. The native-thread failure used a flat result, so that summary gap did not cause it.

Final real-Gateway verdict JSON (mock provider; unmodified step results)
[
  {
    "run": 1,
    "status": "pass",
    "steps": [
      {
        "name": "delivers target message-tool reply once without mirror re-announce",
        "status": "pass",
        "details": "outbound=group:qa-a2a-mirror-room:QA-A2A-MESSAGE-TOOL-MIRROR-OK; sourceTool={\"sessionKey\":\"agent:qa:qa-channel:group:group:qa-a2a-mirror-room\",\"message\":\"qa group visible reply tool check. Use the visible room reply path. exact marker: `QA-A2A-MESSAGE-TOOL-MIRROR-OK`\",\"timeoutSeconds\":0}; targetTool={\"action\":\"send\",\"message\":\"QA-A2A-MESSAGE-TOOL-MIRROR-OK\"}; targetRunId=534da996-5670-4b77-afe1-6a37d681e17a; sourceReplyDelivered=true; terminalReplyDisposition=empty; duplicateWindowMs=8000"
      }
    ]
  },
  {
    "run": 2,
    "status": "pass",
    "steps": [
      {
        "name": "delivers target message-tool reply once without mirror re-announce",
        "status": "pass",
        "details": "outbound=group:qa-a2a-mirror-room:QA-A2A-MESSAGE-TOOL-MIRROR-OK; sourceTool={\"sessionKey\":\"agent:qa:qa-channel:group:group:qa-a2a-mirror-room\",\"message\":\"qa group visible reply tool check. Use the visible room reply path. exact marker: `QA-A2A-MESSAGE-TOOL-MIRROR-OK`\",\"timeoutSeconds\":0}; targetTool={\"action\":\"send\",\"message\":\"QA-A2A-MESSAGE-TOOL-MIRROR-OK\"}; targetRunId=19e6b2d8-759a-4748-a1f3-c64ccf5412bd; sourceReplyDelivered=true; terminalReplyDisposition=empty; duplicateWindowMs=8000"
      }
    ]
  },
  {
    "run": 3,
    "status": "pass",
    "steps": [
      {
        "name": "delivers target message-tool reply once without mirror re-announce",
        "status": "pass",
        "details": "outbound=group:qa-a2a-mirror-room:QA-A2A-MESSAGE-TOOL-MIRROR-OK; sourceTool={\"sessionKey\":\"agent:qa:qa-channel:group:group:qa-a2a-mirror-room\",\"message\":\"qa group visible reply tool check. Use the visible room reply path. exact marker: `QA-A2A-MESSAGE-TOOL-MIRROR-OK`\",\"timeoutSeconds\":0}; targetTool={\"action\":\"send\",\"message\":\"QA-A2A-MESSAGE-TOOL-MIRROR-OK\"}; targetRunId=583078c1-abf5-4004-b235-f8d6fad98a53; sourceReplyDelivered=true; terminalReplyDisposition=empty; duplicateWindowMs=8000"
      }
    ]
  }
]

@steipete steipete self-assigned this Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling extensions: qa-lab extensions: codex size: XL maintainer Maintainer-authored PR labels Sep 4, 2026
@steipete
steipete marked this pull request as ready for review September 4, 2026 05:02
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 1:39 AM ET / 05:39 UTC.

ClawSweeper review

What this changes

The PR replaces same-session A2A transcript-history inference with a run-owned receipt that records final source-conversation delivery.

Merge readiness

⛔ Blocked before merge - 4 items remain

Keep open: the prior P1 remains unfixed. Confirmed current-source reply actions produce kind: "action", but the new receipt producer only handles kind: "send", so same-session A2A can still announce an already delivered reply.

Priority: P1
Reviewed head: 497eae29a5ac70c49a10ab8ddc46ee751ca65cb9

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The stated Gateway evidence supports the tested send flow, but a concrete reply-action variant still misses the new receipt.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: This maintainer-authored PR reports real Gateway QA for the tested send path; the outstanding reply-action omission is a functional defect rather than missing contributor proof.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR reports real Gateway QA for the tested send path; the outstanding reply-action omission is a functional defect rather than missing contributor proof.
Evidence reviewed 7 items Introduced receipt producer excludes reply actions: The new source-delivery calculation and receipt marker both require result.kind === "send"; action results cannot produce sourceReplyDelivered.
Reply action contract: The outbound owner represents reply as kind: "action" and uses its dedicated current-source predicate before marking the route.
Receipt projection omits action results: Only send, poll, and broadcast result variants are projected; an action result returns undefined.
Findings 1 actionable finding [P1] Preserve source-delivery receipts for reply actions
Security None None.

How this fits together

A sessions_send request starts or waits for a target agent run, and A2A decides whether to announce that run’s terminal reply. The receipt is meant to carry confirmed message-tool delivery to that decision so an external reply is not sent twice.

flowchart LR
  Requester[Requester session] --> Send[sessions_send]
  Send --> Run[Target agent run]
  Run --> Tool[Message tool]
  Tool --> Receipt[Terminal delivery receipt]
  Receipt --> Decide[A2A announcement decision]
  Decide --> Reply[Requester-visible reply]
Loading

Before merge

  • Preserve source-delivery receipts for reply actions (P1) - This re-raises the prior P1. runMessageAction represents successful channel reply and thread-reply operations as kind: "action", but this new branch rejects all action results, so it never attaches messageDelivery.sourceReplyDelivered. Same-session A2A therefore cannot suppress the delivered reply. Project settled reply-action results using the existing action predicates and add the A2A regression.
  • Resolve merge risk (P1) - Merging leaves successful current-source reply and thread-reply actions without the terminal receipt that suppresses duplicate same-session A2A delivery.
  • Complete next step (P2) - Preserve confirmed delivery for reply-type message actions and prove same-session A2A suppresses their duplicate announcement.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.

Findings

  • [P1] Preserve source-delivery receipts for reply actions — src/agents/tools/message-tool-execution.ts:682-706
Agent review details

Security

None.

PR surface

Source -145, Tests -59, Docs +15, Other +26. Total -163 across 52 files.

View PR surface stats
Area Files Added Removed Net
Source 27 227 372 -145
Tests 20 790 849 -59
Docs 3 16 1 +15
Config 0 0 0 0
Generated 0 0 0 0
Other 2 30 4 +26
Total 52 1063 1226 -163

Review metrics

Metric Value Why it matters
Production versus test delta production +227/-372, net -145; tests/test support +790/-849, net -59 The broad refactor is net-negative, but its new receipt producer still omits the pre-existing reply-action result variant.

Stored data model

Persistent data-model change detected: serialized state: qa/scenarios/channels/a2a-message-tool-mirror-dedupe.yaml, unknown-data-model-change: qa/scenarios/channels/a2a-message-tool-mirror-dedupe.yaml. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Cover reply-action delivery (recommended)
    Preserve settled delivery for confirmed current-source reply actions and add an end-to-end same-session A2A regression before merge.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Project confirmed source delivery for reply-type message actions using the existing action predicates, then cover same-session A2A suppression.

Technical review

Best possible solution:

Project confirmed reply-type action delivery through the existing source-route predicates, set the final receipt only for settled non-partial delivery, and retain receipt-only A2A suppression.

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

Yes. The source proves that reply actions use kind: "action" while the introduced receipt producer accepts only kind: "send"; the same-session A2A consumer then lacks its suppression fact.

Is this the best way to solve the issue?

No. Run-owned delivery evidence is the right solution, but the producer must cover established reply-type action results instead of only send results.

Full review comments:

  • [P1] Preserve source-delivery receipts for reply actions — src/agents/tools/message-tool-execution.ts:682-706
    This re-raises the prior P1. runMessageAction represents successful channel reply and thread-reply operations as kind: "action", but this new branch rejects all action results, so it never attaches messageDelivery.sourceReplyDelivered. Same-session A2A therefore cannot suppress the delivered reply. Project settled reply-action results using the existing action predicates and add the A2A regression.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: A supported current-source reply action can still produce a duplicate user-visible A2A message.
  • merge-risk: 🚨 message-delivery: The new receipt directly determines whether an external reply is suppressed or announced again.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR reports real Gateway QA for the tested send path; the outstanding reply-action omission is a functional defect rather than missing contributor proof.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/agents/tools/message-tool.test.ts.
  • [P1] node scripts/run-vitest.mjs src/agents/tools/sessions-send-tool.a2a.test.ts.
  • [P1] node scripts/run-vitest.mjs src/agents/run-wait.test.ts.
  • [P1] git diff --check.

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • chelsealong: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add receipt coverage for a settled current-source reply action.
  • Extend same-session A2A proof to show an already delivered reply action is not announced again.

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 (1 earlier review cycle)
  • reviewed 2026-09-04T05:13:00.999Z sha dfc3ae2 :: blocked before merge. :: [P1] Preserve source-delivery receipts for reply actions

Record confirmed final external source delivery in the run terminal receipt and consume it with the terminal reply. Remove history snapshots, fingerprints, and mirror inference from A2A; preserve internal forwarding and delivery facts through Pi, Codex, CLI, and nested tools.
Use the existing action-specific route predicates and settled plugin results for final source-delivery receipts. Add regressions for duplicate announcements, other targets, progress, partial sends, and dry runs. Recheck QA native target matching without scenario retries.
@steipete
steipete force-pushed the codex/a2a-source-delivery-receipt branch from 497eae2 to 16fc7bf Compare September 4, 2026 07:01
@openclaw-barnacle openclaw-barnacle Bot added the channel: qa-channel Channel integration: qa-channel label Sep 4, 2026
@steipete
steipete merged commit fa70549 into main Sep 4, 2026
195 checks passed
@steipete
steipete deleted the codex/a2a-source-delivery-receipt branch September 4, 2026 07:50
@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
…claw#137923)

* fix(a2a): avoid duplicate source replies after message delivery

Record confirmed final external source delivery in the run terminal receipt and consume it with the terminal reply. Remove history snapshots, fingerprints, and mirror inference from A2A; preserve internal forwarding and delivery facts through Pi, Codex, CLI, and nested tools.

* test(a2a): align delivery harnesses with settled receipts

* fix(agents): retain source delivery for replies and polls

Use the existing action-specific route predicates and settled plugin results for final source-delivery receipts. Add regressions for duplicate announcements, other targets, progress, partial sends, and dry runs. Recheck QA native target matching without scenario retries.

* test(agents): reuse direct harness fixtures
steipete added a commit that referenced this pull request Sep 5, 2026
Answer the detached reply and announce steps with the file's existing
REPLY_SKIP/ANNOUNCE_SKIP idiom so each agent-targeting row settles after
the single turn it asserts on. Drops the QA scenario changes superseded
by #137923.
steipete added a commit that referenced this pull request Sep 5, 2026
…37731)

* test(sessions): make cross-agent send rows and mirror scenario deterministic

The `sessions_send agent targeting` rows mocked every target turn with the same
reply, so the detached announce tail ran the full five-turn ping-pong after each
row and overran the row budget under host load. Only the first target turn now
returns the awaited reply; later mocked turns answer REPLY_SKIP, which the
announce flow already treats as "stop", so the tail ends after one step.

The a2a-message-tool-mirror-dedupe qa-lab scenario retried a duplicate marker
away on a loaded host. It now runs with retryCount 0 so a duplicate fails the
run, and the assertion message carries a duplicateAttribution snapshot (outbound
ids, timing, reply linkage, projected history rows with mirror flags, mock
requests) so the next occurrence is attributable instead of retried.

Follow-up to #136755. No production code changes.

* test(gateway): end the detached A2A tail in cross-agent send rows

Answer the detached reply and announce steps with the file's existing
REPLY_SKIP/ANNOUNCE_SKIP idiom so each agent-targeting row settles after
the single turn it asserts on. Drops the QA scenario changes superseded
by #137923.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 6, 2026
…enclaw#137731)

* test(sessions): make cross-agent send rows and mirror scenario deterministic

The `sessions_send agent targeting` rows mocked every target turn with the same
reply, so the detached announce tail ran the full five-turn ping-pong after each
row and overran the row budget under host load. Only the first target turn now
returns the awaited reply; later mocked turns answer REPLY_SKIP, which the
announce flow already treats as "stop", so the tail ends after one step.

The a2a-message-tool-mirror-dedupe qa-lab scenario retried a duplicate marker
away on a loaded host. It now runs with retryCount 0 so a duplicate fails the
run, and the assertion message carries a duplicateAttribution snapshot (outbound
ids, timing, reply linkage, projected history rows with mirror flags, mock
requests) so the next occurrence is attributable instead of retried.

Follow-up to openclaw#136755. No production code changes.

* test(gateway): end the detached A2A tail in cross-agent send rows

Answer the detached reply and announce steps with the file's existing
REPLY_SKIP/ANNOUNCE_SKIP idiom so each agent-targeting row settles after
the single turn it asserts on. Drops the QA scenario changes superseded
by openclaw#137923.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: qa-channel Channel integration: qa-channel docs Improvements or additions to documentation extensions: codex extensions: qa-lab gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant