Skip to content

fix(agents): stop messaging dedupe from dropping final replies that quote a short tool send - #118178

Merged
steipete merged 1 commit into
openclaw:mainfrom
yetval:fix/messaging-dedupe-forward-ratio
Aug 5, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
yetval:fix/messaging-dedupe-forward-ratio

Conversation

@yetval

@yetval yetval commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

When an agent posts a short interim update through the message tool (for example "Checking the deploy logs now.") and then restates that line at the start of its final answer, the messaging dedupe filter classifies the entire final reply as a duplicate and drops it. With block streaming off (the default), the final payload set is the only delivery of the answer, so the user receives the 29 character interim line and never sees the full reply. The text survives only in the session transcript, which a channel-only user cannot access.

Root cause is in src/agents/embedded-agent-helpers/messaging-dedupe.ts. The forward substring check treats any reply that contains a prior tool send as a duplicate with no length floor:

if (normalized.includes(normalizedSent)) {
  return true;
}
return (
  normalizedSent.includes(normalized) &&
  normalized.length >= normalizedSent.length * MIN_REVERSE_SUBSTRING_DUPLICATE_RATIO
);

The reverse direction already carries a deliberate 0.5 length ratio floor, so proportionality was reasoned about and then omitted in the forward direction. A 29 character send suppresses a 316 character reply at a 0.09 overlap ratio.

Why This Change Was Made

Apply the same 0.5 ratio floor to the forward direction, so a reply is deduped only when the prior send covers at least half of it:

if (normalized.includes(normalizedSent)) {
  return normalizedSent.length >= normalized.length * MIN_SUBSTRING_DUPLICATE_RATIO;
}

This is the right boundary because every dedupe consumer routes through isMessagingToolDuplicateNormalized: the final payload filter (src/auto-reply/reply/reply-payloads-dedupe.ts via agent-runner-payloads.ts), the follow-up delivery filter (src/auto-reply/reply/followup-delivery-payloads.ts), and both streamed chunk suppression sites (src/agents/embedded-agent-subscribe.ts, src/agents/embedded-agent-subscribe.handlers.messages.ts). One fix in the shared predicate covers all of them; no sibling call site needs its own change.

Intended dedupe behavior is preserved: exact restatements (ratio 1), narrations like I sent the message: "..." (ratio 0.58, pinned by the existing test), and short suffix additions such as the sent text plus "All good!" (ratio 0.74) are still suppressed. Only replies with substantial content beyond the tool send are now delivered.

Closest prior art: #97513 (closed, trailing acks after tool sends) and #54061 (closed, whole-turn inline text suppression). Neither touches the substring direction asymmetry.

User Impact

Final answers on Telegram, WhatsApp, Signal, Slack, and every other channel are no longer silently withheld when they open with or quote a short interim update the agent already sent. This was a silent failure: the user saw only the interim line with no indication anything was dropped.

Evidence

Driving the real reply payload assembly (buildReplyPayloads in src/auto-reply/reply/agent-runner-payloads.ts, the production function the agent runner uses to build the final delivery set) with a Telegram routed turn: one 316 character final assistant reply that opens with a 29 character message-tool send recorded for the same route. No seams were replaced; the route matching, dedupe decision, and filtering are the production code paths.

Before (pristine main a8b114b):

interim tool send: "Checking the deploy logs now." (29 chars)
final assistant reply chars: 316
delivered payload count: 0
delivered chars: 0
unique final-answer content delivered: false

After (this patch, identical inputs):

interim tool send: "Checking the deploy logs now." (29 chars)
final assistant reply chars: 316
delivered payload count: 1
delivered chars: 316
unique final-answer content delivered: true

Verification:

  • New regression cases in src/agents/embedded-agent-helpers.sanitizeuserfacingtext.test.ts: the long reply quoting a short send must be delivered, and a short restatement plus "All good!" must still dedupe. The suite fails on pristine main (1 failed, 113 passed) and passes with the patch (114 passed).
  • Adjacent suites pass: src/auto-reply/reply/agent-runner-payloads.test.ts, src/auto-reply/reply/reply-payloads.test.ts, src/agents/embedded-agent-subscribe.handlers.messages.test.ts.
  • scripts/run-oxlint.mjs and oxfmt --check clean on both changed files.
  • Not tested locally: tsgo typecheck lanes (left to CI) and a live channel send; the proof drives the payload assembly seam rather than a live Telegram bot.

…uote a short tool send

The forward substring check in isMessagingToolDuplicateNormalized treated any
reply containing a prior message-tool send as a duplicate, with no length
floor. A short interim update sent via the message tool then suppressed the
entire final reply that restated it, and the user never received the answer.
The reverse direction already carried a 0.5 length ratio floor. Apply the same
floor to the forward direction so a reply is only deduped when the prior send
covers at least half of it.
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Aug 2, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 4, 2026, 11:18 AM ET / 15:18 UTC.

ClawSweeper review

What this changes

The PR makes message-tool text deduplication require a prior send to cover at least half of a final reply before suppressing that reply.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open: current main and the latest release still suppress a substantive final reply whenever it contains a prior short message-tool send. The PR repairs that shared decision point with no blocking finding.

Priority: P1
Reviewed head: 25d17958d449606c0958ae772b22e0832c3acc04

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused shared-boundary repair with production-path before/after evidence and targeted regression coverage.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body records before/after production final-payload assembly with identical Telegram-routed inputs, showing zero payloads before and one substantive payload after.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body records before/after production final-payload assembly with identical Telegram-routed inputs, showing zero payloads before and one substantive payload after.
Evidence reviewed 5 items Current-main defect: The forward containment branch returns true whenever final text contains a prior sent text, with no proportionality check.
Shared delivery owner: Final payload construction applies the shared text filter after same-route dedupe resolution; streamed block and message-end paths use the same normalized predicate.
Patch scope: The PR adds the forward 50% containment floor and two focused table cases, retaining exact and near-restatement suppression.
Findings None None.
Security None None.

How this fits together

OpenClaw records text sent through the agent message tool, then passes final and streamed assistant text through shared deduplication before channel delivery. The decision determines whether users receive an already-sent reply or the remaining substantive response.

flowchart LR
A[Channel message] --> B[Agent runtime]
B --> C[Message-tool send record]
B --> D[Final or streamed reply]
C --> E[Shared text deduplication]
D --> E
E --> F{Prior send covers reply?}
F -->|Yes| G[Suppress duplicate]
F -->|No| H[Deliver reply]
Loading

Before merge

  • Resolve merge risk (P1) - The PR is behind current main; refresh normal merge-ref or exact-current-base validation before landing because this shared predicate affects final, follow-up, and streamed message delivery.
  • Complete next step (P2) - No mechanical repair is indicated; this PR needs only normal current-merge validation and maintainer landing review.
Agent review details

Security

None.

PR surface

Source 0, Tests +11. Total +11 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 3 0
Tests 1 11 0 +11
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 14 3 +11

Review metrics

Metric Value Why it matters
Production versus test delta production +3/-3, tests +11/-0 The behavior change remains in the canonical predicate and adds focused regression cases without expanding the delivery architecture.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/agents/embedded-agent-helpers.sanitizeuserfacingtext.test.ts. Confirm migration or upgrade compatibility proof before merge.

Mantis proof suggestion

Optional Telegram Desktop proof would add transport-level confirmation that the substantive final reply remains visible after an interim tool send. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis telegram desktop proof: verify a short message-tool update followed by a longer final reply delivers the substantive final reply once.

Merge-risk options

Maintainer options:

  1. Refresh merge-ref validation (recommended)
    Validate the clean merged result against current main before landing because the shared predicate controls final and streamed channel delivery.

Technical review

Best possible solution:

Land one symmetric containment rule at the shared dedupe owner after current-merge validation, preserving suppression for close restatements while delivering substantive replies.

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

Yes. Current main’s forward containment branch suppresses any final reply that includes a prior send, and the PR provides before/after production payload-assembly output for the affected routed path.

Is this the best way to solve the issue?

Yes. Applying the threshold in the shared predicate is the narrowest maintainable repair because final, follow-up, and streaming consumers already route through it.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The defect can silently leave a channel user with only an interim update instead of the substantive final answer.
  • merge-risk: 🚨 message-delivery: The shared predicate determines suppression across final-payload, follow-up, and streamed reply delivery.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body records before/after production final-payload assembly with identical Telegram-routed inputs, showing zero payloads before and one substantive payload after.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body records before/after production final-payload assembly with identical Telegram-routed inputs, showing zero payloads before and one substantive payload after.
  • mantis: telegram-visible-proof: Mantis should capture Telegram visible proof. The change directly affects the final reply visible to Telegram users and can be demonstrated in a short Telegram Desktop recording.

Evidence

What I checked:

Likely related people:

  • Vincent Koc: Authored a prior message-tool completion-payload dedupe repair and is the current-main blame attribution for the shared helper in this shallow checkout. (role: recent area contributor; confidence: high; commits: b9d3e65f74db, ee397f0c59fe; files: src/agents/embedded-agent-helpers/messaging-dedupe.ts, src/auto-reply/reply/reply-payloads-dedupe.ts)
  • Ayaan Zaidi: Authored the recent source-routed message-tool dedupe matcher used to scope delivery suppression by route. (role: adjacent route-deduplication contributor; confidence: medium; commits: 9641377979f5; files: src/auto-reply/reply/reply-payloads-dedupe.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 (2 earlier review cycles)
  • reviewed 2026-08-02T20:22:01.867Z sha 25d1795 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-03T15:48:52.137Z sha 25d1795 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. mantis: telegram-visible-proof Mantis should capture Telegram visible proof. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 3, 2026
@steipete
steipete marked this pull request as draft August 5, 2026 17:48
@steipete
steipete marked this pull request as ready for review August 5, 2026 17:48
@steipete
steipete merged commit e69c3df into openclaw:main Aug 5, 2026
340 of 365 checks passed
@steipete

steipete commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

vincentkoc added a commit to VACInc/openclaw that referenced this pull request Aug 5, 2026
…cope

* origin/main: (70 commits)
  fix(clickclack): preserve MIME extension for unnamed uploads (openclaw#119646)
  fix(memory): keep post-ready RPCs responsive (openclaw#119710)
  fix(browser): preserve locale, timezone, and device overrides (openclaw#119695)
  fix(agents): stop messaging dedupe from dropping final replies that quote a short tool send (openclaw#118178)
  test(agents): batch code mode budget proof (openclaw#119699)
  fix(memory): keep gateway RPCs responsive during startup (openclaw#119676)
  improve(ui): trail transient session status beside row actions (openclaw#119560)
  refactor(msteams): consolidate channel action target resolution (openclaw#119632)
  fix: tail context answers the current user message (openclaw#117364)
  fix(whatsapp): exercise descriptor-safe credential persistence (openclaw#119621)
  fix(diagnostics-otel): route OTLP endpoints by signal (openclaw#101655)
  refactor(skills): consolidate workshop transcript and record normalization (openclaw#119643)
  fix(video): harden DashScope task and media lifecycle (openclaw#117303)
  refactor(transcripts): consolidate persistence and export ownership (openclaw#119634)
  fix: preserve ClickClack discussion state contracts (openclaw#118851)
  fix(matrix): retire shared E2EE clients safely (openclaw#119570)
  refactor(cron): unify catch-up persistence and payload encoding (openclaw#119636)
  refactor(ui): centralize composer attachment and capability controls (openclaw#119650)
  refactor(daemon): consolidate managed service lifecycle ownership (openclaw#119647)
  fix(browser): honor explicit navigation timeouts across browser drivers (openclaw#119654)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 6, 2026
…uote a short tool send (openclaw#118178)

The forward substring check in isMessagingToolDuplicateNormalized treated any
reply containing a prior message-tool send as a duplicate, with no length
floor. A short interim update sent via the message tool then suppressed the
entire final reply that restated it, and the user never received the answer.
The reverse direction already carried a 0.5 length ratio floor. Apply the same
floor to the forward direction so a reply is only deduped when the prior send
covers at least half of it.
amittell added a commit to amittell/openclaw that referenced this pull request Sep 22, 2026
…a tool send

isMessagingToolDuplicateNormalized calls text a duplicate when it contains a
prior message-tool send that covers at least half of it (the 0.5 ratio from
openclaw#118178). A reply that opens with the send and adds one short sentence clears
that ratio, so the sentence never reaches the channel, even when it corrects
the send:

    sent   "Deployment finished."
    reply  "Deployment finished. Actually it failed."   -> dropped

No length ratio separates "<sent> All good!" from "<sent> Actually it failed.",
since both are the send plus a short tail.

When the text starts with the prior send and the rest has a letter or digit, it
is no longer a duplicate. A punctuation-only tail ("Deployment finished!!!")
still goes through the ratio and stays a duplicate. A send quoted later in the
text ('I sent the message: "..."') and the reverse direction are unchanged. The
new branch can only return false, so nothing delivered before is dropped now.

Deliberate test change: the "Checking the deploy logs now. All good!" row from
openclaw#118178 flips from true to false. It is the same shape as the correction.

Verified on the M4 at cecf47a + this change:
  sanitizeuserfacingtext.test.ts   124 passed; with messaging-dedupe.ts
                                   reverted to main, 3 failed (expected true
                                   to be false), 121 passed
  94 test files that reference the dedupe helpers, their callers or
  messagingToolSentTexts: main 3400 passed, 1 skipped; this change 3403
  passed, 1 skipped; the only per-file difference is the 3 rows above
obviyus added a commit that referenced this pull request Nov 29, 2026
… text only (#208260)

## Problem

When the agent sent a message with the `message` tool and its final reply repeated that text inside new text, OpenClaw could drop the final reply. `isMessagingToolDuplicateNormalized` judged overlap by a 50% substring ratio after lowercasing and emoji stripping. This is a code judge on model output. It has already lost real answers (#118178: "the user never received the answer"), and each earlier fix added another ratio.

Base-side Telegram proof (below): the user got the interim tool message, then `No answer was returned. Ask again if you still need one.` The answer was gone.

## Change

- Final payload dedupe (`src/auto-reply/reply/reply-payloads-dedupe.ts`): keep only trimmed exact equality against sends on the matching route. That branch was already the first check.
- Block streaming (`src/agents/embedded-agent-subscribe.stream-rendering.ts`): same trimmed exact equality against committed sent texts.
- Deleted `isMessagingToolDuplicate`, `isMessagingToolDuplicateNormalized`, `hasTextBeyondSentTexts`, `MIN_DUPLICATE_TEXT_LENGTH`, `MIN_SUBSTRING_DUPLICATE_RATIO`, the `messagingToolSentTextsNormalized` run state that only fed them, and their ratio tests.
- Unchanged: `resolveCurrentSourceMessagingToolPartial` (prefix equality), the `/btw` rendered-text equality, media dedupe.

## Impact (what the user sees)

- A final reply that adds anything to a tool send is now delivered.
- An exact repeat of a tool send on the same route is still suppressed.
- Accepted edge cases (visible and recoverable, not silent loss):
  - A model that paraphrases its own tool send (case, punctuation, emoji changes included) shows the user both messages.
  - A send recorded without a route (for example `sessions_send` to another session) no longer suppresses an identical final in this chat. The user in this chat did not see that send, so delivering the final is correct.

## Decisions recorded

- **`NO_REPLY` sentence in the `message` tool result: not added.** A same-chat send with `final` omitted or `true` already ends the turn structurally (`sourceReplyDeliveryState = "delivered"` suppresses later output, and the `final` parameter documents "A confirmed final source reply ends the turn"). A `final: false` send is progress, and the model is expected to answer after it, so telling it to end with `NO_REPLY` there would be wrong. No prompt, tool description or snapshot changes.
- **Red test shape.** The brief's literal case (tool text as prefix plus a short result) was already delivered on base since #151921 (`hasTextBeyondSentTexts`). The red tests use the tool text embedded in a reply (`Sent "Deploy started, checking logs now". Logs clean.`), which base drops by the 50% ratio.

## Evidence

Tests (red on base `d9cc195ce70f`, green on head):
- `src/auto-reply/reply/agent-runner-payloads.test.ts`: embedded repeat on the matching route is delivered; unrouted exact repeat is delivered; routed exact repeat stays suppressed.
- `src/agents/embedded-agent-subscribe.subscribe-embedded-agent-session.source-reply-suppression.test.ts`: streamed final that embeds the tool send is delivered.
- Removed table rows in `followup-delivery.test.ts` and `agent-runner.misc.runreplyagent.test.ts` that asserted the unrouted ratio drop (they expected the "no answer" notice); the remaining unrouted rows cover the contract.

Telegram E2E (Test Server, real user via TDLib, `--source-gateway`, scripted mock model over `openai-completions`: turn 1 calls `message` `{action: "send", message: "Deploy started, checking logs now", final: false}`, turn 2 replies `Sent "Deploy started, checking logs now". Logs clean.`):

Base `d9cc195ce70f`:
```
user  Deploy and report back. EXACTDEDUPE-BASE2
bot   Deploy started, checking logs now
bot   Working / ✉️ Message running
bot   No answer was returned. Ask again if you still need one.
```

Head:
```
user  Deploy and report back. EXACTDEDUPE-HEAD3
bot   Deploy started, checking logs now
bot   Working / ✉️ Message
bot   Sent "Deploy started, checking logs now". Logs clean.
```

Local: `ocx test` on touched tests plus every test importing a changed source (58 files, green after the last code change); `pnpm check:changed` green except `dead export scan`, which flags unrelated files (`src/agents/command/types.ts`, `src/plugins/native-module-require.ts`, `ui/src/...`, `update.test-harness.ts`) that this PR does not touch.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 29, 2026
… text only (#208260)

## Problem

When the agent sent a message with the `message` tool and its final reply repeated that text inside new text, OpenClaw could drop the final reply. `isMessagingToolDuplicateNormalized` judged overlap by a 50% substring ratio after lowercasing and emoji stripping. This is a code judge on model output. It has already lost real answers (#118178: "the user never received the answer"), and each earlier fix added another ratio.

Base-side Telegram proof (below): the user got the interim tool message, then `No answer was returned. Ask again if you still need one.` The answer was gone.

## Change

- Final payload dedupe (`src/auto-reply/reply/reply-payloads-dedupe.ts`): keep only trimmed exact equality against sends on the matching route. That branch was already the first check.
- Block streaming (`src/agents/embedded-agent-subscribe.stream-rendering.ts`): same trimmed exact equality against committed sent texts.
- Deleted `isMessagingToolDuplicate`, `isMessagingToolDuplicateNormalized`, `hasTextBeyondSentTexts`, `MIN_DUPLICATE_TEXT_LENGTH`, `MIN_SUBSTRING_DUPLICATE_RATIO`, the `messagingToolSentTextsNormalized` run state that only fed them, and their ratio tests.
- Unchanged: `resolveCurrentSourceMessagingToolPartial` (prefix equality), the `/btw` rendered-text equality, media dedupe.

## Impact (what the user sees)

- A final reply that adds anything to a tool send is now delivered.
- An exact repeat of a tool send on the same route is still suppressed.
- Accepted edge cases (visible and recoverable, not silent loss):
  - A model that paraphrases its own tool send (case, punctuation, emoji changes included) shows the user both messages.
  - A send recorded without a route (for example `sessions_send` to another session) no longer suppresses an identical final in this chat. The user in this chat did not see that send, so delivering the final is correct.

## Decisions recorded

- **`NO_REPLY` sentence in the `message` tool result: not added.** A same-chat send with `final` omitted or `true` already ends the turn structurally (`sourceReplyDeliveryState = "delivered"` suppresses later output, and the `final` parameter documents "A confirmed final source reply ends the turn"). A `final: false` send is progress, and the model is expected to answer after it, so telling it to end with `NO_REPLY` there would be wrong. No prompt, tool description or snapshot changes.
- **Red test shape.** The brief's literal case (tool text as prefix plus a short result) was already delivered on base since #151921 (`hasTextBeyondSentTexts`). The red tests use the tool text embedded in a reply (`Sent "Deploy started, checking logs now". Logs clean.`), which base drops by the 50% ratio.

## Evidence

Tests (red on base `d9cc195ce70f`, green on head):
- `src/auto-reply/reply/agent-runner-payloads.test.ts`: embedded repeat on the matching route is delivered; unrouted exact repeat is delivered; routed exact repeat stays suppressed.
- `src/agents/embedded-agent-subscribe.subscribe-embedded-agent-session.source-reply-suppression.test.ts`: streamed final that embeds the tool send is delivered.
- Removed table rows in `followup-delivery.test.ts` and `agent-runner.misc.runreplyagent.test.ts` that asserted the unrouted ratio drop (they expected the "no answer" notice); the remaining unrouted rows cover the contract.

Telegram E2E (Test Server, real user via TDLib, `--source-gateway`, scripted mock model over `openai-completions`: turn 1 calls `message` `{action: "send", message: "Deploy started, checking logs now", final: false}`, turn 2 replies `Sent "Deploy started, checking logs now". Logs clean.`):

Base `d9cc195ce70f`:
```
user  Deploy and report back. EXACTDEDUPE-BASE2
bot   Deploy started, checking logs now
bot   Working / ✉️ Message running
bot   No answer was returned. Ask again if you still need one.
```

Head:
```
user  Deploy and report back. EXACTDEDUPE-HEAD3
bot   Deploy started, checking logs now
bot   Working / ✉️ Message
bot   Sent "Deploy started, checking logs now". Logs clean.
```

Local: `ocx test` on touched tests plus every test importing a changed source (58 files, green after the last code change); `pnpm check:changed` green except `dead export scan`, which flags unrelated files (`src/agents/command/types.ts`, `src/plugins/native-module-require.ts`, `ui/src/...`, `update.test-harness.ts`) that this PR does not touch.

Co-authored-by: Ayaan Zaidi <[email protected]>

Follow-up scan: 34d4f8f improve: list Docker streams and flag unconfirmed cleanup in Doctor (#201292); 21786f6 refactor(ui): stop sending 28 additional unused labels to translators (#207982); 9cec330 refactor(workboard): group session tiles without rescanning each column (#207380); 16a2d4b refactor(ui): lowercase log search text only once (#207383). Other hits are not required by this focused beta.2 fix.

(cherry picked from commit 5ba0e69)

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
… text only (#208260)

## Problem

When the agent sent a message with the `message` tool and its final reply repeated that text inside new text, OpenClaw could drop the final reply. `isMessagingToolDuplicateNormalized` judged overlap by a 50% substring ratio after lowercasing and emoji stripping. This is a code judge on model output. It has already lost real answers (#118178: "the user never received the answer"), and each earlier fix added another ratio.

Base-side Telegram proof (below): the user got the interim tool message, then `No answer was returned. Ask again if you still need one.` The answer was gone.

## Change

- Final payload dedupe (`src/auto-reply/reply/reply-payloads-dedupe.ts`): keep only trimmed exact equality against sends on the matching route. That branch was already the first check.
- Block streaming (`src/agents/embedded-agent-subscribe.stream-rendering.ts`): same trimmed exact equality against committed sent texts.
- Deleted `isMessagingToolDuplicate`, `isMessagingToolDuplicateNormalized`, `hasTextBeyondSentTexts`, `MIN_DUPLICATE_TEXT_LENGTH`, `MIN_SUBSTRING_DUPLICATE_RATIO`, the `messagingToolSentTextsNormalized` run state that only fed them, and their ratio tests.
- Unchanged: `resolveCurrentSourceMessagingToolPartial` (prefix equality), the `/btw` rendered-text equality, media dedupe.

## Impact (what the user sees)

- A final reply that adds anything to a tool send is now delivered.
- An exact repeat of a tool send on the same route is still suppressed.
- Accepted edge cases (visible and recoverable, not silent loss):
  - A model that paraphrases its own tool send (case, punctuation, emoji changes included) shows the user both messages.
  - A send recorded without a route (for example `sessions_send` to another session) no longer suppresses an identical final in this chat. The user in this chat did not see that send, so delivering the final is correct.

## Decisions recorded

- **`NO_REPLY` sentence in the `message` tool result: not added.** A same-chat send with `final` omitted or `true` already ends the turn structurally (`sourceReplyDeliveryState = "delivered"` suppresses later output, and the `final` parameter documents "A confirmed final source reply ends the turn"). A `final: false` send is progress, and the model is expected to answer after it, so telling it to end with `NO_REPLY` there would be wrong. No prompt, tool description or snapshot changes.
- **Red test shape.** The brief's literal case (tool text as prefix plus a short result) was already delivered on base since #151921 (`hasTextBeyondSentTexts`). The red tests use the tool text embedded in a reply (`Sent "Deploy started, checking logs now". Logs clean.`), which base drops by the 50% ratio.

## Evidence

Tests (red on base `d9cc195ce70f`, green on head):
- `src/auto-reply/reply/agent-runner-payloads.test.ts`: embedded repeat on the matching route is delivered; unrouted exact repeat is delivered; routed exact repeat stays suppressed.
- `src/agents/embedded-agent-subscribe.subscribe-embedded-agent-session.source-reply-suppression.test.ts`: streamed final that embeds the tool send is delivered.
- Removed table rows in `followup-delivery.test.ts` and `agent-runner.misc.runreplyagent.test.ts` that asserted the unrouted ratio drop (they expected the "no answer" notice); the remaining unrouted rows cover the contract.

Telegram E2E (Test Server, real user via TDLib, `--source-gateway`, scripted mock model over `openai-completions`: turn 1 calls `message` `{action: "send", message: "Deploy started, checking logs now", final: false}`, turn 2 replies `Sent "Deploy started, checking logs now". Logs clean.`):

Base `d9cc195ce70f`:
```
user  Deploy and report back. EXACTDEDUPE-BASE2
bot   Deploy started, checking logs now
bot   Working / ✉️ Message running
bot   No answer was returned. Ask again if you still need one.
```

Head:
```
user  Deploy and report back. EXACTDEDUPE-HEAD3
bot   Deploy started, checking logs now
bot   Working / ✉️ Message
bot   Sent "Deploy started, checking logs now". Logs clean.
```

Local: `ocx test` on touched tests plus every test importing a changed source (58 files, green after the last code change); `pnpm check:changed` green except `dead export scan`, which flags unrelated files (`src/agents/command/types.ts`, `src/plugins/native-module-require.ts`, `ui/src/...`, `update.test-harness.ts`) that this PR does not touch.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 5ba0e69)

Follow-ups: 16a2d4b refactor(ui): lowercase log search text only once (#207383) [not selected for this narrow backport]; 21786f6 refactor(ui): stop sending 28 additional unused labels to translators (#207982) [not selected for this narrow backport]; 34d4f8f improve: list Docker streams and flag unconfirmed cleanup in Doctor (#201292) [not selected for this narrow backport]; 9cec330 refactor(workboard): group session tiles without rescanning each column (#207380) [not selected for this narrow backport]

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 30, 2026
… text only (openclaw#208260)

## Problem

When the agent sent a message with the `message` tool and its final reply repeated that text inside new text, OpenClaw could drop the final reply. `isMessagingToolDuplicateNormalized` judged overlap by a 50% substring ratio after lowercasing and emoji stripping. This is a code judge on model output. It has already lost real answers (openclaw#118178: "the user never received the answer"), and each earlier fix added another ratio.

Base-side Telegram proof (below): the user got the interim tool message, then `No answer was returned. Ask again if you still need one.` The answer was gone.

## Change

- Final payload dedupe (`src/auto-reply/reply/reply-payloads-dedupe.ts`): keep only trimmed exact equality against sends on the matching route. That branch was already the first check.
- Block streaming (`src/agents/embedded-agent-subscribe.stream-rendering.ts`): same trimmed exact equality against committed sent texts.
- Deleted `isMessagingToolDuplicate`, `isMessagingToolDuplicateNormalized`, `hasTextBeyondSentTexts`, `MIN_DUPLICATE_TEXT_LENGTH`, `MIN_SUBSTRING_DUPLICATE_RATIO`, the `messagingToolSentTextsNormalized` run state that only fed them, and their ratio tests.
- Unchanged: `resolveCurrentSourceMessagingToolPartial` (prefix equality), the `/btw` rendered-text equality, media dedupe.

## Impact (what the user sees)

- A final reply that adds anything to a tool send is now delivered.
- An exact repeat of a tool send on the same route is still suppressed.
- Accepted edge cases (visible and recoverable, not silent loss):
  - A model that paraphrases its own tool send (case, punctuation, emoji changes included) shows the user both messages.
  - A send recorded without a route (for example `sessions_send` to another session) no longer suppresses an identical final in this chat. The user in this chat did not see that send, so delivering the final is correct.

## Decisions recorded

- **`NO_REPLY` sentence in the `message` tool result: not added.** A same-chat send with `final` omitted or `true` already ends the turn structurally (`sourceReplyDeliveryState = "delivered"` suppresses later output, and the `final` parameter documents "A confirmed final source reply ends the turn"). A `final: false` send is progress, and the model is expected to answer after it, so telling it to end with `NO_REPLY` there would be wrong. No prompt, tool description or snapshot changes.
- **Red test shape.** The brief's literal case (tool text as prefix plus a short result) was already delivered on base since openclaw#151921 (`hasTextBeyondSentTexts`). The red tests use the tool text embedded in a reply (`Sent "Deploy started, checking logs now". Logs clean.`), which base drops by the 50% ratio.

## Evidence

Tests (red on base `98bb8cc00cc9`, green on head):
- `src/auto-reply/reply/agent-runner-payloads.test.ts`: embedded repeat on the matching route is delivered; unrouted exact repeat is delivered; routed exact repeat stays suppressed.
- `src/agents/embedded-agent-subscribe.subscribe-embedded-agent-session.source-reply-suppression.test.ts`: streamed final that embeds the tool send is delivered.
- Removed table rows in `followup-delivery.test.ts` and `agent-runner.misc.runreplyagent.test.ts` that asserted the unrouted ratio drop (they expected the "no answer" notice); the remaining unrouted rows cover the contract.

Telegram E2E (Test Server, real user via TDLib, `--source-gateway`, scripted mock model over `openai-completions`: turn 1 calls `message` `{action: "send", message: "Deploy started, checking logs now", final: false}`, turn 2 replies `Sent "Deploy started, checking logs now". Logs clean.`):

Base `98bb8cc00cc9`:
```
user  Deploy and report back. EXACTDEDUPE-BASE2
bot   Deploy started, checking logs now
bot   Working / ✉️ Message running
bot   No answer was returned. Ask again if you still need one.
```

Head:
```
user  Deploy and report back. EXACTDEDUPE-HEAD3
bot   Deploy started, checking logs now
bot   Working / ✉️ Message
bot   Sent "Deploy started, checking logs now". Logs clean.
```

Local: `ocx test` on touched tests plus every test importing a changed source (58 files, green after the last code change); `pnpm check:changed` green except `dead export scan`, which flags unrelated files (`src/agents/command/types.ts`, `src/plugins/native-module-require.ts`, `ui/src/...`, `update.test-harness.ts`) that this PR does not touch.

Co-authored-by: Ayaan Zaidi <[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 mantis: telegram-visible-proof Mantis should capture Telegram visible proof. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants