Skip to content

improve(msteams): avoid repeated activity preparation on retries - #128329

Merged
steipete merged 1 commit into
mainfrom
codex/perf-msteams-activity-retry-current
Aug 23, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-msteams-activity-retry-current

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Microsoft Teams replay-safe provider retries repeated already-successful activity preparation. For media messages, a transient provider 429 could reread and re-encode the attachment or repeat SharePoint upload and drive-item projection before retrying the same send.

Why This Change Was Made

Successful preparation is retained only for the current message and reused across provider retries. Preparation failures still leave the activity unset, so replay-safe preparation errors retry exactly as before; retry policy, payload projection, and pending-upload bookkeeping are unchanged.

User Impact

Teams sends recover from transient provider failures without repeating completed media or SharePoint work. Ordinary sends and failure behavior are unchanged.

Evidence

  • Mixed preparation/provider retry regression: transient upload 429 → successful upload → provider 429 → successful send now performs 2 uploads instead of the baseline 3, while both provider attempts serialize to the same payload.
  • Controlled 100 ms/upload reproduction: 358 ms before → 244 ms after (31.8% lower in this retry scenario).
  • Focused regression: 1 passed / 45 skipped.
  • Owner and sibling verification: 6 files / 148 tests passed.
  • node scripts/check-changed.mjs -- extensions/msteams/src/messenger.ts extensions/msteams/src/messenger.test.ts passed all selected format, boundary, dead-export, typecheck, lint, guard, and import-cycle checks.
  • git diff --check passed.
  • Fresh autoreview: TruffleHog clean; Codex gpt-5.6-sol with high reasoning reported no P0/P1 findings (correctness confidence 0.96).

@clawsweeper

clawsweeper Bot commented Aug 23, 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 channel: msteams Channel integration: msteams size: XS maintainer Maintainer-authored PR labels Aug 23, 2026
@steipete
steipete marked this pull request as ready for review August 23, 2026 18:40

Copy link
Copy Markdown
Contributor Author

Land-ready evidence for exact head 0bd50f22918361863c4256007cb87463768f4b3e:

  • Root cause: replay-safe provider retries rebuilt an already-successful Teams activity inside the retry closure, repeating media reads/encoding and SharePoint upload projection.
  • Repair: successful preparation is retained only for the current message. Preparation failures still retry with the activity unset; provider retries reuse the exact successfully prepared payload. Production LOC: +6/-6 (net 0); tests: +14/-5.
  • Red/green boundary: upload preparation 429 → successful upload → provider 429 → successful send performs 2 uploads after the fix versus 3 on the baseline. Both provider attempts serialize identically.
  • Focused regression: 1 passed / 45 skipped.
  • Owner+sibling suite: 6 files / 148 tests passed.
  • node scripts/check-changed.mjs -- extensions/msteams/src/messenger.ts extensions/msteams/src/messenger.test.ts passed all selected format, boundary, dead-export, extension/test typecheck, Oxlint, guard, and import-cycle checks.
  • git diff --check passed.
  • Fresh autoreview: TruffleHog clean; Codex gpt-5.6-sol/high reported no P0/P1 finding (correctness confidence 0.96).
  • Exact-head hosted CI: run 32658807117, green.
  • Native preparation: OPENCLAW_TESTBOX=1 scripts/pr prepare-run 128329 completed against the same head.

No live Teams provider mutation was performed: this changes only internal preparation reuse, not provider API behavior, and is covered at the owner/provider-call boundary. ClawSweeper currently has only an in-progress publisher placeholder and has not published a Rank-up moves: list; the latest full review will be re-read before merge.

@clawsweeper

clawsweeper Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 23, 2026, 2:37 PM ET / 18:37 UTC.

ClawSweeper review

What this changes

The PR reuses a successfully prepared Microsoft Teams activity during replay-safe provider retries, avoiding repeated media processing and SharePoint uploads.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for maintainer handling: the focused cache is source-sound, but this protected, maintainer-labeled draft still needs Teams provider-boundary confirmation before merge.

Priority: P2
Reviewed head: 0bd50f22918361863c4256007cb87463768f4b3e
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a focused owner-boundary repair with credible regression coverage, pending provider-boundary confidence for merge.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate, though a real Teams transport trace remains the key pre-merge risk reducer.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate, though a real Teams transport trace remains the key pre-merge risk reducer.
Evidence reviewed 6 items Changed owner boundary: The per-message send closure now retains only a fulfilled activity, while failed preparation leaves it unset and retryable; pending-upload metadata is captured and removed before dispatch.
Retry safety contract: Teams classifies only HTTP 429 as replay-safe for this unkeyed POST; ambiguous transport and server failures are not replayed.
Regression coverage: The changed test injects upload 429, successful preparation, provider 429, then send success; it asserts two uploads and identical provider payloads across both sends.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs extensions/msteams/src/messenger.test.ts -t "retries media preparation"

Result: PASS (completed)

node scripts/run-vitest.mjs extensions/msteams/src/messenger.test.ts -t "retries media preparation"
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128329-HaemYK/target$ node scripts/run-vitest.mjs extensions/msteams/src/messenger.test.ts -t "retries media pr
eparation"
node scripts/run-vitest.mjs extensions/msteams/src/messenger.test.ts -t "retries media preparation"
[test] starting test/vitest/vitest.extension-msteams.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-128329-HaemYK/target

 ✓  extension-msteams  extensions/msteams/src/messenger.test.ts (46 tests | 45 skipped) 40ms

 Test Files  1 passed (1)
      Tests  1 passed | 45 skipped (46)
   Start at  18:38:36
   Duration  9.80s (transform 7.80s, setup 754ms, import 8.73s, tests 40ms, environment 0ms)

[test] passed 1 Vitest shard in 14.23s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128329-HaemYK/target$ node scripts/run-vitest.mjs extensions/msteams/src/messenger.test.ts -t "retries media pr
eparation"

































Assertions:

  • PASS expect_output: 1 passed

How this fits together

The Microsoft Teams plugin prepares outbound activities, including media uploads or consent cards, then sends them through the live turn context or proactive sender. A rate-limit retry returns to the same per-message send closure before delivery completes.

flowchart LR
A[Rendered Teams message] --> B[Prepare activity]
B --> C[Media or SharePoint work]
C --> D[Teams provider send]
D --> E{HTTP 429?}
E -->|Yes| D
E -->|No| F[Delivered activity]
Loading

Decision needed

Question Recommendation
Should this maintainer-owned draft require a real Microsoft Teams 429 recovery trace before it is made ready for merge? Require provider-boundary proof: Run a controlled Teams rate-limit recovery with the real reply/send client and retain a redacted request/result trace showing preparation occurs once after it succeeds.

Why: The remaining uncertainty is at the authenticated Teams transport boundary and cannot be resolved from the mocked regression alone.

Before merge

  • Resolve merge risk (P1) - The cache changes the payload object reused by the live Teams reply/send boundary; the attached regression is mocked and no real Teams 429 recovery trace is available for merge confidence.
  • Complete next step (P2) - The remaining pre-merge action is authenticated Teams transport proof and maintainer judgment, not a safe automated repair.
Agent review details

Security

None.

PR surface

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

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

Review metrics

Metric Value Why it matters
Production versus test delta production +6/-6 (net 0); tests +14/-5 (net +9) The retry repair adds no net production code and concentrates its extra coverage in the changed owner-boundary scenario.

Stored data model

Persistent data-model change detected: serialized state: extensions/msteams/src/messenger.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Prove the real retry boundary before merge (recommended)
    Record a redacted real Teams provider retry showing the prepared media activity is accepted unchanged after a 429.
  2. Accept mocked-boundary coverage
    Land based on the focused regression while accepting that the installed Teams SDK behavior was not exercised against a live provider.

Technical review

Best possible solution:

Keep the per-message cache, then capture a redacted Teams provider-boundary 429 recovery trace proving one prepared payload is accepted on retry before marking the draft ready.

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

Yes—source defines a deterministic upload-429, provider-429, then success scenario in the changed regression test, though it was not rerun in this dependency-free checkout.

Is this the best way to solve the issue?

Yes—the cache belongs in the per-message retry owner, so successful preparation is reused without widening retry policy or changing ambiguous-failure handling.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded reliability and duplicate-work fix in Microsoft Teams message delivery.
  • add merge-risk: 🚨 message-delivery: Reusing an activity across a Teams provider retry changes the outbound delivery path and lacks real-provider confirmation.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.

Label justifications:

  • P2: This is a bounded reliability and duplicate-work fix in Microsoft Teams message delivery.
  • merge-risk: 🚨 message-delivery: Reusing an activity across a Teams provider retry changes the outbound delivery path and lacks real-provider confirmation.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.

Evidence

What I checked:

Likely related people:

  • steipete: Recent history includes the retry-safety repair and the dominant share of changes to the messenger and its tests. (role: recent Microsoft Teams retry owner; confidence: high; commits: 1027837d966a, 3eecab1beed9; files: extensions/msteams/src/messenger.ts, extensions/msteams/src/messenger.test.ts)
  • sudie-codes: History ties this contributor to the pending-upload/file-consent flow whose internal metadata is preserved by the change. (role: file-consent path contributor; confidence: medium; commits: 784318799bf0; files: extensions/msteams/src/file-consent-helpers.ts, extensions/msteams/src/pending-uploads.ts)

Rank-up moves

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

  • Add a redacted real Teams 429 recovery trace showing prepared media work is not repeated and the retry succeeds.

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.

Copy link
Copy Markdown
Contributor Author

ClawSweeper review disposition for exact head 0bd50f22918361863c4256007cb87463768f4b3e:

  • Rank-up move — real Teams 429 trace: skipped. A provider 429 is not reliably inducible in a controlled live tenant, and forcing one would add external mutation without stronger determinism. This PR does not change the Teams request contract or retry policy. The regression runs the real sendMSTeamsMessages preparation owner, including SharePoint preparation, and stubs only provider dispatch; it proves preparation-failure retry, successful-fact reuse, byte-identical provider payloads, and final success in the original execution order.
  • Maintainer decision: accept the owner/provider-boundary proof. Direct SDK source inspection confirms proactive delivery projects a copied activity and thread/provider delivery constructs deterministic targeting/wire projections; no provider path consumes the internal pending-upload tag.
  • Stored-data note: not applicable. The review's serialized state match is a test-local array of JSON.stringify(activity) captures used to compare provider payloads; no persistence or migration surface changed.

The review reports no actionable code or security findings and identifies the per-message retry owner as the best fix. Exact-head CI and native prepare remain green.

@steipete
steipete merged commit 7c7e10a into main Aug 23, 2026
168 checks passed
@steipete
steipete deleted the codex/perf-msteams-activity-retry-current branch August 23, 2026 18:50

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: msteams Channel integration: msteams maintainer Maintainer-authored PR size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants