Skip to content

fix(msteams): cancel unread Graph error response bodies - #117664

Merged
vincentkoc merged 2 commits into
openclaw:mainfrom
zenglingbiao:fix/msteams-graph-cancel-error-bodies
Aug 2, 2026
Merged

vincentkoc merged 2 commits into
openclaw:mainfrom
zenglingbiao:fix/msteams-graph-cancel-error-bodies

Conversation

@zenglingbiao

@zenglingbiao zenglingbiao commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Cancel unread Microsoft Teams Graph response bodies before releasing their guarded fetch resources.

The final branch is intentionally narrow:

  • message metadata responses
  • hosted-content collection responses
  • existing hosted-content $value responses

The unrelated shared Gateway test-helper changes were removed.

What Problem This Solves

fetchWithSsrFGuard() returns both a Response and a release() callback. The callback clears guard state and closes its dispatcher, but it does not consume or cancel an unread response body.

The message and $value non-ok paths released the guard with unread bodies. The collection path attempted to cancel first, but awaited that cancellation. Awaiting can deadlock when response capture has cloned and teed the stream because cancellation waits for the other tee branch.

Slow, large, or stalled Graph error bodies can therefore retain the pinned connection and dispatcher after the caller has finished handling the failure. Small finite JSON errors may already be buffered, so this PR does not claim every Graph error leaks a connection.

Microsoft Graph defines JSON error response bodies, and Undici requires callers to consume or cancel response bodies:

Fix

Add one local releaseGraphResponse() owner helper that:

  1. starts best-effort cancellation when the response body is unread;
  2. does not await cancellation, avoiding cloned-stream deadlock;
  3. awaits the guarded fetch release() callback.

All three guarded Graph response owners use this helper. The shared SSRF guard remains unchanged because streaming consumers have different response-lifecycle contracts.

Evidence

Exact reviewed head: c37c2c9206ee995a7cfce583f4c42424731bdd85

  • Sanitized AWS Crabbox, fresh PR checkout, public network, no Tailscale, no instance profile, no hydration:
    • pnpm test extensions/msteams/src/attachments/graph.test.ts
    • 1 file passed
    • 20/20 tests passed
    • run run_2c674c8df4cc
  • Added regressions for:
    • failed message response cancellation
    • failed hosted-content $value response cancellation
    • cloned failed collection response where cancellation starts before release without blocking the operation
  • Trusted-main pinned-dispatcher fixture:
    • stalled unread 500 + release() only: release completed after about 101 ms, while the server-side socket and response remained open after 1 second
    • stalled unread 500 + cancellation before release(): release completed in about 1 ms and the socket/response closed in about 5 ms
  • git diff --check clean
  • Autoreview clean, patch correctness 0.98

Scope

  • Production: extensions/msteams/src/attachments/graph.ts, +10/-4, net +6
  • Tests: extensions/msteams/src/attachments/graph.test.ts, +98
  • No config, persistence, SDK, protocol, or user-visible behavior changes

@openclaw-barnacle openclaw-barnacle Bot added channel: msteams Channel integration: msteams size: S labels Aug 1, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. labels Aug 1, 2026
@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 2, 2026, 4:19 AM ET / 08:19 UTC.

ClawSweeper review

What this changes

The PR makes Microsoft Teams attachment downloads cancel unread Microsoft Graph response bodies before releasing their guarded fetch dispatchers.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

This PR is still necessary because current main leaves the Microsoft Teams $value and message non-OK paths releasing guarded fetches with unread bodies. The final head centralizes cleanup at the attachment-layer owner, starts cancellation without awaiting the proxy-capture tee, and covers all three guarded Graph response owners; no actionable patch defect was found.

Priority: P2
Reviewed head: c37c2c9206ee995a7cfce583f4c42424731bdd85

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused response-lifecycle repair with direct runtime proof, targeted regressions, and no identified correctness or security finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body provides final-head after-fix pinned-dispatcher timing evidence plus a sanitized focused Crabbox run, and the added cloned-response regression directly exercises the changed lifecycle.
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 provides final-head after-fix pinned-dispatcher timing evidence plus a sanitized focused Crabbox run, and the added cloned-response regression directly exercises the changed lifecycle.
Evidence reviewed 7 items Current-main gap: Current main cancels only the failed collection response before release; the hosted-content $value and message response owners call release() directly, leaving their non-OK bodies unread.
Attachment-layer repair: The PR adds one local helper that starts best-effort cancellation only for unread bodies and then awaits the existing guard release; all collection, $value, and message response owners use it.
Guard release contract: The shared SSRF guard marks release once, clears the timeout, and closes the per-request dispatcher. The PR preserves this shared contract rather than changing response lifecycle behavior for unrelated consumers.
Findings None None.
Security None None.

How this fits together

Microsoft Teams attachment downloads fetch message metadata, hosted-content collections, and hosted-content bytes through an SSRF-guarded Graph client. The attachment layer owns each returned response and its dispatcher-release callback after parsing or an error path completes.

flowchart LR
  A[Teams message] --> B[Graph attachment downloader]
  B --> C[Guarded Graph fetch]
  C --> D[Response and release callback]
  D --> E[Parse metadata or media]
  E --> F[Cancel unread response body]
  F --> G[Close pinned dispatcher]
Loading

Before merge

  • Complete next step (P2) - No discrete automated repair is needed; the final patch has no actionable review finding and is ready for ordinary maintainer merge review.
Agent review details

Security

None.

PR surface

Source +6, Tests +98. Total +104 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 10 4 +6
Tests 1 98 0 +98
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 108 4 +104

Review metrics

None.

Stored data model

Persistent data-model change detected: vector/embedding metadata: extensions/msteams/src/attachments/graph.test.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Merge this focused attachment-layer repair after the normal current-head merge gate; keep the shared SSRF guard unchanged because other callers may own streaming response lifecycles differently.

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

Yes, from current source and the added regression shape: failed message and $value responses reach the guard release callback with unread bodies, and the capture runtime can clone a response so awaiting cancellation may not settle.

Is this the best way to solve the issue?

Yes. A local helper at the Microsoft Teams response-owner boundary fixes all affected guarded Graph responses while preserving the shared guard contract for streaming and non-attachment consumers.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: The PR repairs a bounded Microsoft Teams attachment-download resource-lifecycle defect without changing configuration, persisted data, public APIs, or defaults.
  • 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 provides final-head after-fix pinned-dispatcher timing evidence plus a sanitized focused Crabbox run, and the added cloned-response regression directly exercises the changed lifecycle.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides final-head after-fix pinned-dispatcher timing evidence plus a sanitized focused Crabbox run, and the added cloned-response regression directly exercises the changed lifecycle.

Evidence

What I checked:

  • Current-main gap: Current main cancels only the failed collection response before release; the hosted-content $value and message response owners call release() directly, leaving their non-OK bodies unread. (extensions/msteams/src/attachments/graph.ts:232, 26cf4e6130a8)
  • Attachment-layer repair: The PR adds one local helper that starts best-effort cancellation only for unread bodies and then awaits the existing guard release; all collection, $value, and message response owners use it. (extensions/msteams/src/attachments/graph.ts:102, c37c2c9206ee)
  • Guard release contract: The shared SSRF guard marks release once, clears the timeout, and closes the per-request dispatcher. The PR preserves this shared contract rather than changing response lifecycle behavior for unrelated consumers. (src/infra/net/fetch-guard.ts:507, 26cf4e6130a8)
  • Capture tee contract: The proxy-capture runtime explicitly documents that cancelling a cloned response branch can remain unsettled until both tee branches cancel, and it uses fire-and-forget cancellation for that reason. This directly supports the helper's non-awaited cancellation. (src/proxy-capture/runtime.ts:43, 26cf4e6130a8)
  • Focused regressions: The PR adds coverage for failed $value and message responses plus a cloned collection response where cancellation starts before release without blocking the operation. (extensions/msteams/src/attachments/graph.test.ts:252, c37c2c9206ee)
  • Final-head provenance: The final commit refines the original contributor change into the current attachment-layer cleanup shape; it is not present in the current release or current main. (extensions/msteams/src/attachments/graph.ts:102, c37c2c9206ee)

Likely related people:

  • Peter Steinberger: Authored the final-head lifecycle refinement and earlier Microsoft Teams Graph hardening in the same attachment path. (role: recent area contributor; confidence: high; commits: c37c2c9206ee, c56b56e514f8; files: extensions/msteams/src/attachments/graph.ts)
  • colton-octaria: Authored the recent merged inbound Microsoft Teams file-recovery repair in this attachment subsystem. (role: recent feature contributor; confidence: medium; commits: dc8c0aaaf273; files: extensions/msteams/src/attachments/graph.ts)
  • cxbAsDev: Authored the merged Graph attachment JSON-response bounds change, which shares the response-reading and cleanup boundary. (role: adjacent contributor; confidence: medium; commits: 090c3a26d051; files: extensions/msteams/src/attachments/graph.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 (6 earlier review cycles)
  • reviewed 2026-08-01T22:30:25.716Z sha 07a868efa3e098f82c63c12e66c9eadb8d50caae :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T23:06:14.220Z sha 07a868efa3e098f82c63c12e66c9eadb8d50caae :: needs maintainer review before merge. :: none
  • reviewed 2026-08-02T01:52:54.997Z sha 2f047cf05752251f6cc6bb7594a4db3f6aeb16f2 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-02T03:09:42.061Z sha fd382e5d171d0d58c68c428459ba910ae954f314 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-02T03:44:32.637Z sha a219482bdf280b78f2203831d7f199e6f1e199dd :: needs maintainer review before merge. :: none
  • reviewed 2026-08-02T08:07:50.894Z sha c37c2c9 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 2, 2026
@vincentkoc
vincentkoc force-pushed the fix/msteams-graph-cancel-error-bodies branch from a219482 to c37c2c9 Compare August 2, 2026 07:58
@vincentkoc vincentkoc self-assigned this Aug 2, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed size: M labels Aug 2, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. labels Aug 2, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 2, 2026
@vincentkoc
vincentkoc merged commit 83c6a51 into openclaw:main Aug 2, 2026
107 of 118 checks passed
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

abdulrahman305 pushed a commit to qenex-ai/openclaw that referenced this pull request Aug 2, 2026
* origin/main:
  fix: stop lost cancellations, false success, and stuck Codex compaction (openclaw#117902)
  fix(cli): reject incomplete hosted video downloads (openclaw#117893)
  refactor(board): remove duplicate in-memory store (openclaw#117353)
  refactor: consolidate Teams and error helpers (openclaw#117907)
  fix(msteams): cancel unread Graph error response bodies (openclaw#117664)
  fix(imessage): rewind the recovery cursor when chat.db is replaced at the same path (openclaw#117788)
  feat(browser): relay CDP compat for Puppeteer clients (chrome-devtools-mcp) (openclaw#117915)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 3, 2026
)

* fix(msteams): cancel unread Graph error response bodies

* fix(msteams): release every guarded Graph response safely

---------

Co-authored-by: Peter Steinberger <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 3, 2026
* origin/main:
  fix: stop lost cancellations, false success, and stuck Codex compaction (openclaw#117902)
  fix(cli): reject incomplete hosted video downloads (openclaw#117893)
  refactor(board): remove duplicate in-memory store (openclaw#117353)
  refactor: consolidate Teams and error helpers (openclaw#117907)
  fix(msteams): cancel unread Graph error response bodies (openclaw#117664)
  fix(imessage): rewind the recovery cursor when chat.db is replaced at the same path (openclaw#117788)
  feat(browser): relay CDP compat for Puppeteer clients (chrome-devtools-mcp) (openclaw#117915)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: msteams Channel integration: msteams P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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.

3 participants