fix: prevent duplicate Teams broker retry turns#107171
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed July 14, 2026, 7:37 AM ET / 11:37 UTC. Summary PR surface: Source +197, Tests +481. Total +678 across 2 files. Reproducibility: yes. from source at medium confidence: current main has two direct Teams agent-dispatch paths without delivery dedupe, but no live broker replay establishes the exact production retry identity. citeturn533451view0. Review metrics: 1 noteworthy metric.
Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Keep one Teams-owned wrapper around both dispatch boundaries using the shared claimable dedupe, key only on proven stable delivery identity, and land after a redacted broker replay confirms duplicate suppression and retry-after-failure behavior. Do we have a high-confidence way to reproduce the issue? Yes from source at medium confidence: current main has two direct Teams agent-dispatch paths without delivery dedupe, but no live broker replay establishes the exact production retry identity. citeturn533451view0. Is this the best way to solve the issue? Yes in shape: a Teams-owned wrapper using the shared claim/commit/release helper is narrower and more maintainable than new dedupe infrastructure, provided the real broker identity and failure path are proven. citeturn429913view0. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 9c03b2310e6c. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +197, Tests +481. Total +678 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
Review history (1 earlier review cycle)
|
Closes #107170
What Problem This Solves
Fixes an issue where Microsoft Teams users could see duplicate agent replies or repeated side effects when a brokered Teams webhook delivery is retried while the first delivery is in flight or within the retry window after success.
Why This Change Was Made
The Teams monitor now projects the broker delivery header into the activity before SDK dispatch and uses the shared persistent claimable dedupe helper around both Teams agent-dispatch paths. The guard commits only after successful dispatch, releases failed claims so retries remain eligible, scopes fallback activity keys by source and Teams context, and skips fallback suppression when no stable event identity exists.
User Impact
Teams broker retries with the same stable delivery id no longer start duplicate agent turns. Normal Teams events without a stable delivery id continue to dispatch rather than being guessed into a dedupe key.
Evidence
Before evidence:
After-fix focused test output:
Patch hygiene:
git diff --check -- extensions/msteams/src/monitor.ts extensions/msteams/src/monitor.lifecycle.test.ts # passed with no outputStructured review:
Real behavior proof
Behavior addressed: Microsoft Teams brokered webhook retries with the same stable delivery id can no longer start duplicate agent turns through the monitor dispatch path.
Real environment tested: Local repo checkout with focused Microsoft Teams monitor lifecycle tests. The tests exercise the real monitor registration and dispatch wrapper with mocked Teams SDK routes and mocked persistent dedupe factory to avoid writing test state to the user database.
Exact steps or command run after this patch:
node scripts/run-vitest.mjs extensions/msteams/src/monitor.lifecycle.test.tsandgit diff --check -- extensions/msteams/src/monitor.ts extensions/msteams/src/monitor.lifecycle.test.ts.Evidence after fix: Terminal capture above shows the focused Teams lifecycle suite passed with 24 tests and patch whitespace check passed with no output.
Observed result after fix: The new tests prove duplicate non-poll card actions are suppressed while in flight and after success, activity-id fallback dedupes only stable scoped events, in-flight retries process after owner failure, message updates are not suppressed by bare message id, and events without a stable id are not suppressed.
What was not tested: No live Microsoft Teams broker replay was run; the local bug evidence did not include credentials or a raw duplicate live Teams turn log. Remote Testbox was unavailable in the initial environment because the installed Crabbox wrapper was too old.