Skip to content

fix(msteams): prevent duplicate final replies - #116398

Merged
vincentkoc merged 7 commits into
openclaw:mainfrom
a-tokyo:bug/msteams-thread-dedupe-resolve-auto-thread
Aug 1, 2026
Merged

vincentkoc merged 7 commits into
openclaw:mainfrom
a-tokyo:bug/msteams-thread-dedupe-resolve-auto-thread

Conversation

@a-tokyo

@a-tokyo a-tokyo commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #116397

What Problem This Solves

Fixes an issue where Microsoft Teams users could receive the same final answer twice when the agent used message(action=send) and then returned identical text under automatic visible replies.

Why This Change Was Made

Teams now records authoritative conversation and thread identity for message-tool sends, including direct messages, channel roots, explicit thread targets, and cross-conversation targets. Core also holds an automatic source preview while it can still be the same current-route message-tool delivery, then either suppresses the duplicate or releases a diverging response.

This keeps transport identity in the Teams plugin and source-preview ownership in the core agent subscriber. It does not weaken route isolation with content-only global dedupe.

The current-main repair also records confirmed current-source reply and poll deliveries outside send-only telemetry, so those sibling actions participate in the same preview-suppression contract.

User Impact

Teams users get one visible answer when the message tool and automatic final represent the same delivery. Different threads, different conversations, explicit targets, and genuinely different automatic text remain visible.

Evidence Map

  • Entry points: Teams inbound dispatch and threading.buildToolContext; core partial-reply and message-tool result handlers.
  • Owner boundary: Teams owns Teams route/thread identity; core owns whether a current-source automatic preview duplicates a proven tool delivery.
  • Caller: message-tool evidence extraction invokes the active channel plugin's action and threading adapters.
  • Callee: Teams target matching and send-result extraction produce authoritative route evidence consumed by core dedupe.
  • Sibling controls: direct message, group chat, same-thread, different-thread, different-conversation, explicit-target, cumulative-preview, delta-preview, diverging-preview, reply, and poll paths are covered.
  • Best-fix judgment: plugin-only routing was necessary but insufficient because the observed duplicate was the Teams native partial preview posted before terminal-final dedupe. The paired plugin/core repair fixes each fact at its owning boundary.

Evidence

  • Exact PR head: 457966c141b7591ec6ea78a60f30d10de9e985d6
  • Exact tree: e679fba32d5a716141940d0baf21f5ac891e49ba
  • Maintainer repair: signed commit ea46dbb83c66d399eba7c1438171389925958592 extends the dedupe invariant to current-source reply and poll actions.
  • Autoreview: the repair delta and full branch review found no P0/P1 defects; full-branch correctness confidence 0.99.
  • Focused tests: 248/248 core agent assertions passed after the current-main merge. The broader Teams/core/QA set passed 606/606 assertions.
  • Changed gate: the repair delta passed all delegated changed-check lanes, including formatting, policy guards, production/test typechecks, lint, and import-cycle checks: https://github.com/openclaw/openclaw/actions/runs/30687430770
  • Exact-head build and real behavior: Blacksmith Testbox tbx_01kyy0z92pjgyqnry2dysct2es first materialized tree e679fba32d5a716141940d0baf21f5ac891e49ba, then passed OPENCLAW_BUILD_PRIVATE_QA=1 pnpm build and the dedicated msteams-thread-message-tool-final-dedupe Gateway scenario 1/1 with zero failures or skips: https://github.com/openclaw/openclaw/actions/runs/30688267540
  • Observed controls: the scenario asserts one delivery for same-thread, direct-message, and group-chat cases, and two deliveries for different-thread and different-conversation controls.
  • Static proof: git diff --check, targeted oxfmt, and targeted oxlint passed.

The behavior run exercises real Gateway startup, the real Teams plugin, Bot Framework-shaped inbound/outbound traffic, a mock OpenAI tool call, source preview handling, and final delivery. It is deterministic and credential-free; it is not a live Microsoft tenant soak.

Current Main Compatibility

Compared against origin/main 78486e27511c945a01c7e719b7e271e437ffb7a2.

  • Main is two commits ahead of the PR's merged base; both are unrelated iMessage/infra changes.
  • There is zero touched-file overlap between those commits and this PR.
  • git merge-tree --write-tree completed without conflicts and produced tree d0669b6f5cb4ee71ee494ffe20583107dc40ff17.

AI Assistance

AI-assisted maintainer repair and review were used. The implementation was manually traced through the full Teams delivery path, reviewed with the repository autoreview skill, and validated with exact-tree tests and runtime proof.

@openclaw-barnacle openclaw-barnacle Bot added channel: msteams Channel integration: msteams size: M labels Jul 30, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 30, 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 30, 2026
@clawsweeper

clawsweeper Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 3:04 AM ET / 07:04 UTC.

ClawSweeper review

What this changes

This PR records authoritative Microsoft Teams conversation and thread identity for message-tool deliveries, then suppresses an automatic final reply only when it repeats a confirmed same-route delivery.

Merge readiness

⚠️ Needs maintainer review before merge - 3 items remain

Keep this PR open for maintainer review. The supplied exact-head Gateway proof is strong and current main visibly lacks the Teams thread-aware route evidence required for safe deduplication, but this read-only partial checkout could not materialize the PR’s changed blobs because its promisor remote could not resolve GitHub; that prevents a high-confidence exact-head source verdict.

Priority: P1
Reviewed head: 457966c141b7591ec6ea78a60f30d10de9e985d6

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The runtime proof is strong, but a local promisor-fetch failure prevented direct exact-head source inspection for a higher-confidence patch rating.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR provides exact-head real-behavior proof through a private QA build, real Gateway startup, bundled Teams plugin, loopback Bot Framework transport, and controls showing one same-route delivery versus two distinct-route deliveries.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR provides exact-head real-behavior proof through a private QA build, real Gateway startup, bundled Teams plugin, loopback Bot Framework transport, and controls showing one same-route delivery versus two distinct-route deliveries.
Evidence reviewed 6 items Current-main route invariant: Current dedupe only falls back to a channel-level match when neither side has a structured thread id; it explicitly rejects that fallback when thread evidence is present, so missing Teams thread identity prevents safe same-thread matching.
Current Teams gap: Current main’s Teams tool context exposes the incoming ReplyToId as currentThreadTs and does not provide the route-matching or send-result extraction hooks used by the proposed repair, matching the reported missing owner facts.
Existing SDK seam: The channel-plugin contract already supports plugin-owned target matching and recovery of an actual resolved send route, so the proposed approach extends an existing seam rather than adding a parallel plugin API.
Findings None None.
Security None None.

How this fits together

The Microsoft Teams plugin turns inbound Bot Framework activity into a current conversation and thread context, then records outbound message-tool delivery facts. The core embedded-agent subscriber uses those facts while streaming and delivering automatic replies so it can avoid a duplicate without hiding text meant for another conversation or thread.

flowchart LR
  A[Teams inbound activity] --> B[Conversation and thread context]
  B --> C[Message tool send]
  C --> D[Confirmed delivery route]
  D --> E[Core preview and final decision]
  E --> F[Suppress duplicate or send distinct reply]
Loading

Before merge

  • Resolve merge risk (P1) - This PR changes the shared rule for suppressing visible automatic replies; an incorrect conversation or thread match could hide a legitimate reply, which is why the distinct-thread and distinct-conversation controls are merge-critical.
  • Resolve merge risk (P1) - The local checkout could not materialize the exact PR tree because its promisor remote failed DNS resolution, so a maintainer or refreshed review worker should complete direct current-head source inspection before merge.
  • Complete next step (P2) - The remaining blocker is direct exact-head source inspection in a healthy checkout, not a concrete repair defect that should be sent to an automated fix lane.
Agent review details

Security

None.

PR surface

Source +365, Tests +1022, Docs +1, Other +243. Total +1631 across 31 files.

View PR surface stats
Area Files Added Removed Net
Source 15 399 34 +365
Tests 14 1022 0 +1022
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 1 243 0 +243
Total 31 1665 34 +1631

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: extensions/qa-lab/src/providers/mock-openai/server.test.ts, serialized state: extensions/qa-lab/src/scenario-catalog-channels.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #116397
Summary: This PR is the explicit candidate repair for the reported Microsoft Teams same-thread duplicate-final-reply bug.

Members:

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

Merge-risk options

Maintainer options:

  1. Refresh exact-head review (recommended)
    Materialize and inspect the changed PR source at the current head, then retain the existing Gateway scenario as the merge proof for same-route suppression and distinct-route delivery.
  2. Pause for a narrower replacement
    Close or replace the branch only if direct review shows the shared core preview hold cannot be kept route-scoped through the existing plugin seams.

Technical review

Best possible solution:

Materialize the exact PR head in a healthy checkout, confirm the plugin’s normalized Teams route facts feed the existing channel-plugin seams without widening cross-route suppression, then merge if the supplied same-route and distinct-route Gateway scenario remains green.

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

Yes, source-reproducible: current main requires exact route and thread evidence for safe source-reply dedupe, while the current Teams tool context records only ReplyToId as its thread fact. The supplied exact-head Gateway scenario then exercises same-thread, direct-message, group-chat, other-thread, and other-conversation cases.

Is this the best way to solve the issue?

Unclear pending direct PR-tree inspection: the proposed plugin-owned Teams identity plus core-owned preview decision matches the existing plugin seam and avoids content-only global dedupe, but the local infrastructure failure prevents confirming every changed implementation detail at the exact head.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The change addresses a user-visible Microsoft Teams delivery regression that can post the same final answer twice.
  • merge-risk: 🚨 message-delivery: A mistaken route or thread match would suppress a valid automatic reply or fail to suppress the duplicate the PR targets.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR provides exact-head real-behavior proof through a private QA build, real Gateway startup, bundled Teams plugin, loopback Bot Framework transport, and controls showing one same-route delivery versus two distinct-route deliveries.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR provides exact-head real-behavior proof through a private QA build, real Gateway startup, bundled Teams plugin, loopback Bot Framework transport, and controls showing one same-route delivery versus two distinct-route deliveries.

Evidence

What I checked:

  • Current-main route invariant: Current dedupe only falls back to a channel-level match when neither side has a structured thread id; it explicitly rejects that fallback when thread evidence is present, so missing Teams thread identity prevents safe same-thread matching. (src/auto-reply/reply/reply-payloads-dedupe.ts:316, d8ba00f8a262)
  • Current Teams gap: Current main’s Teams tool context exposes the incoming ReplyToId as currentThreadTs and does not provide the route-matching or send-result extraction hooks used by the proposed repair, matching the reported missing owner facts. (extensions/msteams/src/channel.ts:1289, d8ba00f8a262)
  • Existing SDK seam: The channel-plugin contract already supports plugin-owned target matching and recovery of an actual resolved send route, so the proposed approach extends an existing seam rather than adding a parallel plugin API. (src/channels/plugins/types.core.ts:378, 78486e27511c)
  • Proven runtime coverage: The PR body and latest maintainer re-review comment report exact-head private-QA build success and a real Gateway plus bundled Teams-plugin scenario that asserts one delivery on same-thread, DM, and group paths, while retaining two deliveries for different-thread and different-conversation controls. (qa/scenarios/channels/msteams-thread-message-tool-final-dedupe.yaml:1, 457966c141b7)
  • Current release provenance: The latest supplied release tag is v2026.7.1; current main is not contained in a local release tag, so this remains an unshipped fix proposal rather than work already solved on main. (CHANGELOG.md:1, 78486e27511c)
  • Exact-head inspection blocked: The commit object exists locally, but reading the PR’s changed tree objects attempted a promisor fetch and failed because github.com could not resolve. This review therefore does not claim direct inspection of the expanded PR source beyond the supplied diff context. (457966c141b7)

Likely related people:

  • Peter Steinberger: Blame attributes the current Teams threading context and route-deduplication implementation to the same current-main commit, which is the code path this PR extends. (role: current-main feature provenance; confidence: high; commits: d8ba00f8a262; files: extensions/msteams/src/channel.ts, src/auto-reply/reply/reply-payloads-dedupe.ts)
  • Vincent Koc: Authored the PR’s core repair commits and previously merged the private Teams Gateway QA adapter used by the claimed regression scenario. (role: recent adjacent contributor; confidence: medium; commits: 463b05123e65, ea46dbb83c66, a3220af4aa04; files: extensions/msteams/src/qa/adapter.runtime.ts, qa/scenarios/channels/msteams-thread-message-tool-final-dedupe.yaml, src/agents/embedded-agent-subscribe.handlers.messages.ts)

Rank-up moves

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

  • Refresh the review in a checkout that can materialize commit 457966c.
  • Confirm the exact head retains route-scoped suppression for different threads and conversations before merge.

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 (13 earlier review cycles; latest 8 shown)
  • reviewed 2026-07-31T17:49:36.391Z sha bed670482a0d0dc6165deb60d1924d6fa38c587c :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-31T18:50:03.068Z sha fa5f78036e59fa26b341a7d3d66cc8fbf11c2aef :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-31T19:05:17.070Z sha fa5f78036e59fa26b341a7d3d66cc8fbf11c2aef :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-31T19:14:28.178Z sha fa5f78036e59fa26b341a7d3d66cc8fbf11c2aef :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-01T04:14:10.568Z sha 463b051 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T04:19:26.592Z sha 463b051 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T06:39:40.193Z sha 457966c :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-01T06:58:33.385Z sha 457966c :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 30, 2026
@a-tokyo a-tokyo changed the title fix(msteams): duplicate final answers in Teams channel threads 🐛 fix(msteams): duplicate final answers in Teams channel threads Jul 30, 2026
@a-tokyo

a-tokyo commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper please re-review

@github-actions

github-actions Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Security-sensitive guard cleared

This PR no longer has blocked security-sensitive file changes. A future security-sensitive change requires a fresh /allow-security-sensitive-change comment after the guard blocks that new head SHA.

  • Current SHA: 457966c141b7591ec6ea78a60f30d10de9e985d6

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord channel: googlechat Channel integration: googlechat channel: imessage Channel integration: imessage channel: line Channel integration: line channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: signal Channel integration: signal channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: voice-call Channel integration: voice-call channel: whatsapp-web Channel integration: whatsapp-web app: android App: android labels Jul 31, 2026
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

Exact-head causal integration proof is now in the PR body for 5a093f9beeb7b1dc31c539cd0bd880521def175f, including the honest boundary that this is not a live Teams tenant/Bot Framework transport run.

@clawsweeper

clawsweeper Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@github-actions

github-actions Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Dependency graph guard cleared

This PR no longer has blocked dependency graph changes. A future dependency graph change requires a fresh /allow-dependencies-change comment after the guard blocks that new head SHA.

  • Current SHA: 457966c141b7591ec6ea78a60f30d10de9e985d6

@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

Exact-head runtime proof is now in the PR body for 463b05123e65d248d7af107879ffd01a7c77c764: real Gateway + bundled Teams plugin + private loopback Bot Framework adapter, with same=1, otherThread=2, otherConversation=2, dm=1, and group=1.

@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

…98-main-4caff51-20260801

* origin/pr-116398:
  fix(agents): suppress duplicate source previews
  test(msteams): prove thread-aware final dedupe
  fix(msteams): preserve message-tool thread routing
…in-4caff51-20260801

* origin/main:
  fix(agents): surface /new guidance for thinking-signature replay errors (openclaw#116967) (openclaw#116987)
  fix(doctor): keep repaired session rows readable (openclaw#117207)
  fix(feishu): unify outbound delivery lifecycle (openclaw#117223)
  docs(gateway): document llamacpp toolSchemaProfile for custom llama.cpp endpoints (openclaw#117120)
  fix(clickclack): thread replies stop being answered past the 100-reply thread window (openclaw#117225)
  fix(talk): retain bounded relay close owners
  fix(talk): bound relay transcript persistence
…in-4caff51-20260801

* origin/main:
  fix(minimax): validate complete generated audio at producer owners (openclaw#117195)
  fix(line): centralize Flex alternative-text bounds (openclaw#117217)
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

Exact-head proof is now attached to the PR body for 457966c141b7591ec6ea78a60f30d10de9e985d6 / tree e679fba32d5a716141940d0baf21f5ac891e49ba: private QA build green, dedicated Teams Gateway scenario 1/1 green, and required exact-head CI 83/83 successful.

@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member

Final maintainer landing gate for exact head 457966c141b7591ec6ea78a60f30d10de9e985d6:

  • exact-head CI: 83 successful, 0 failed/pending; openclaw/ci-gate green
  • focused proof: repaired 248/248; full related set 606/606
  • exact private Teams adapter scenario: green on the merged tree
  • autoreview: full branch clean, confidence 0.99
  • ClawSweeper: exact-head no findings/security, proof sufficient
  • rank-up moves satisfied: exact head was materialized and reviewed; same-route suppression plus different-thread/conversation controls are covered by the repaired tests and private-adapter scenario
  • review threads: 0 unresolved
  • live main: 2358566c299de9c731caa26add6ae9f9f97ce481
  • touched-path drift: 0
  • clean synthetic merge tree: d53f89c2800d0947fc367a6def856a25f16c4f97

Landing via squash with contributor authorship preserved.

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: msteams Channel integration: msteams extensions: qa-lab 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL 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.

[Bug]: MS Teams channel thread posts identical answer twice after message-tool delivery

2 participants