Repository navigation
fix(msteams): surface SharePoint/OneDrive download failures as MediaFailures (ENG-20968) - #260
Conversation
…ailures (ENG-20968) Dragging a file from Teams into the agent passed a link it couldn't access, with no explanation. The SharePoint/OneDrive resolution mechanism (Graph /shares/.../driveItem/content, used by default via alwaysFetchGraphMessage) already existed; every failure in that path was only logged at warn level and never reached the agent. Wires every download-failure path in extensions/msteams/src/attachments (direct contentUrl downloads, inline data: images, SharePoint reference attachments, Graph hostedContents, Bot Framework DM attachments) into core's MediaFailures contract, so the agent now reports an explicit failure instead of going silent. Also fixes several silent-duplicate-report and silent-drop bugs found across six rounds of review, reuses core's InboundMediaFailureReason directly instead of a msteams-local union (matching the Slack pattern), and documents that resolving a dragged SharePoint/OneDrive file needs its own Graph consent on the Teams bot's own Azure AD app, separate from the SharePoint skill's cert app. Verified: full extensions/msteams suite (1084/1085, one pre-existing unrelated failure), tsgo:extensions + tsgo:extensions:test clean, oxfmt clean. Live verification against a real Teams+SharePoint tenant is a fast-follow, not done here. Co-Authored-By: Claude Opus 5 <[email protected]>
There was a problem hiding this comment.
Review — one finding (reproduced locally)
Reviewed the full diff plus whole-file context of inbound-media.ts, graph.ts, download.ts, shared.ts, bot-framework.ts, payload.ts, all callers, and the core consumer contract (src/auto-reply/templating.ts InboundMediaFailure, media-note.ts, inbound-media-failure-notice.ts). Local runs at head 8c6ca07: 173/173 across the 7 touched attachment/inbound-media suites + 40/40 across the 4 message-handler suites. The wiring into core's MediaFailures contract is correct, failure entries carry no URLs/tokens (only name/contentType/reason), and the docs addition about the bot app's own Files.Read.All/Sites.Read.All consent is accurate.
Finding: the same dragged SharePoint file is double-reported across the direct path and the Graph fallback
For the ENG-20968 flagship scenario — one dragged SharePoint file in a channel message, bot app missing Graph consent — the failure is reported TWICE:
downloadMSTeamsAttachments(direct path): thereferenceattachment passesisDownloadableAttachment("any attachment with a contentUrl"),resolveDownloadCandidaterewrites it viatryBuildGraphSharesUrlForSharedLink, the shares fetch 403s,onFailurefires with{name: "dragged.pdf", reason: "fetch_failed"}.mediaListis empty, so the Graph fallback runs (hasHtmlFileAttachmentor Boon-forkalwaysFetchGraphMessage: true);downloadMSTeamsGraphMediare-attempts the same shares URL, fails, and pushes the identical failure again.
The existing dedup (seenGraphBatchKeys) only collapses repeats ACROSS Graph messageUrl retries — it never compares graph batches against the direct-path failures already in the accumulator. Reproduced with a probe test at this head (real resolveMSTeamsInboundMedia + real download/graph internals, only network mocked):
{ "media": [], "failures": [
{ "name": "dragged.pdf", "reason": "fetch_failed" },
{ "name": "dragged.pdf", "reason": "fetch_failed" }
] }User-facing result via buildInboundMediaFailureNotice: "I couldn't read 2 of the files you attached: "dragged.pdf" (it couldn't be downloaded), "dragged.pdf" (it couldn't be downloaded). Re-attach them and I'll try again." — for a user who attached exactly one file. The agent-facing media note likewise gets two identical lines, inviting "both files failed" phrasing.
This is the same bug class the PR already fixed twice inside the graph path (retry double-report, duplicate-URL double-report) — it just needs the cross-path case too.
Suggested fix shape: dedupe when merging into the accumulator in resolveMSTeamsInboundMedia (or just before return), keyed on name + contentType + reason, but ONLY for entries with a defined name — named failures identify a specific file, so identical named entries from two layers are the same file reported twice. Keep unnamed duplicates untouched so the existing "two genuinely distinct same-shaped failures from a single Graph call" case (two oversized pasted images, name: undefined) still survives. Probe test file left in the worktree if useful: extensions/msteams/src/monitor-handler/crosspath-probe.test.ts at ~/pr260-8c6ca075 on the review host.
Looks good
attemptedReferenceUrls/referenceAttemptCountsplit correctly fixes the retry double-report without undercounting diagnostics.extractInlineImageCandidatesbudget-exhausted rework (keep scanning, report each remaining image) closes the silent-vanish gap properly.- Dedup-before-allowlist ordering fix in the inline URL loop is correct.
- Barrel re-export of
InboundMediaFailure/InboundMediaFailureReason+ guardrail pin update follows the plugin-sdk boundary rules.
Happy to re-review quickly once the cross-path dedup lands — everything else is approve-ready.
A dragged SharePoint reference attachment has a contentUrl, so isDownloadableAttachment (no contentType check) lets the direct download path attempt and fail it first; since mediaList is still empty afterward, the Graph fallback then independently rediscovers and re-fails the same attachment. Neither path's own dedup caught this since they are genuinely separate attempts, not a retry of the same call. Dedupe named failures (keyed on name+contentType+reason) at the final merge point in resolveMSTeamsInboundMedia. Unnamed failures are left untouched since they have no identity to collide on, preserving the earlier fix for two genuinely distinct same-shaped unnamed failures. Found via PR review on #260 (verified independently before fixing: traced isDownloadableAttachment and the direct-path/Graph-fallback call sequence, reproduced with a new failing test before implementing the fix). Co-Authored-By: Claude Opus 5 <[email protected]>
|
RE review #5388028901 (cross-path double-report finding, addressed in 2918fb1): Verified the claim independently before fixing — traced Fix: dedupe named failures (keyed on Full |
There was a problem hiding this comment.
Code review — changes requested
The new merge-point dedupe addresses the prior cross-path duplicate, but its key treats (name, contentType, reason) as a unique attachment identity. Distinct Teams files can share all three fields (for example, two report.pdf SharePoint references that both fail with 403). The final Set then collapses the two real failures into one, undercounting the user-facing failure notice. A focused resolver probe at this SHA returned one failure for two distinct reference URLs with identical failure metadata. Please dedupe only when the same attachment identity is observed across paths (carry a stable ID/normalized URL internally), and preserve multiplicity for distinct attachments with the same display name.
…NG-20968) A second review on PR #260 found that the prior name+contentType+reason dedup key is not a unique file identity: two different SharePoint attachments can share a filename and collapse into one, under-reporting real failures. Thread an internal-only sourceUrl (never part of the public MediaFailures contract) through onFailure on both the direct download path and the Graph fallback, and dedupe only when that identity matches across paths. Co-Authored-By: Claude Sonnet 5 <[email protected]>
There was a problem hiding this comment.
Code review — changes requested
The source-URL identity change fixes the prior duplicate-failure case, but one same-file recovery path still returns a false failure. The direct download can record fetch_failed for a SharePoint source URL; if the Graph fallback then successfully retrieves that same item, mediaList is updated but the earlier failure is never cleared. The result therefore contains both the recovered media and a MediaFailure, and core tells the user it could not read a file that it actually received. A focused resolver probe at this head reproduced this state. Please carry the source identity through successful downloads too and retract only the matching recovered failure (preserving failures for other attachments), or otherwise report only terminal failures.
Validation: the seven focused suites passed 176/176 on a local merge with the current live base. The full Teams suite on that merged tree passed 1087/1088; the lone pinnedMessageId schema failure is the previously reproduced base failure. Exact-head Actions are green, but their run metadata still references the older base SHA 176e9c3; focused and full local tests were also run against live base b9e4432.
…ity-se-teams-drag-and-drop-file-links-not-usable-by-boon-agent
…lves (ENG-20968) A third review on PR #260 found that a direct-path failure for a SharePoint attachment stayed in the reported failures even when the Graph fallback subsequently succeeded on that exact attachment (e.g. a transient 403 followed by a successful retry), so the agent could tell the user both that a file downloaded AND that it couldn't be read. Thread an onSuccess callback (carrying the same internal sourceUrl identity as onFailure) through the direct download path and the Graph fallback, and drop any tracked failure whose sourceUrl a later path went on to resolve. Co-Authored-By: Claude Sonnet 5 <[email protected]>
There was a problem hiding this comment.
Approved — all review findings resolved at ec42ab876
Fourth review round. All three findings from the earlier rounds are fixed and independently re-verified with resolver-level probes (real resolveMSTeamsInboundMedia + real download/graph internals, only network mocked) at this exact head:
- Round 1 (cross-path double report): same dragged SharePoint file failing in both the direct path and the Graph fallback is now reported exactly once, deduped by shares-URL identity. Probe: 1 failure. PASS
- Round 2 (same-name over-collapse): two distinct files both named
dragged.pdfat different SharePoint URLs, both failing, are both reported. Probe: 2 failures. PASS - Round 3 (stale failure after recovery): direct path fails, Graph fallback recovers the same file — the earlier failure is now retracted via the
onSuccesssource-URL identity callback. Probe: media present,failures: []. PASS - Added surgical-retraction probe: direct fails X+Y, Graph recovers only X — result keeps media X and exactly the failure for Y. PASS
Validation at ec42ab876:
- 187/187 tests green across 9 suites (7 touched attachment/inbound-media suites incl. the new regression tests for all three findings, message-handler.dm-media, plus my 4 external probes)
- Hosted Actions: 117 pass / 24 skip / 0 fail
- Failure entries carry only name/contentType/reason (no URLs, no tokens) into the model/user-visible surface; filenames sanitized by core's notice builder
- Docs addition on the bot app's own
Files.Read.All/Sites.Read.Allconsent is accurate and matches the likely Affinity SE root cause
Non-blocking, already flagged in the PR body: live Teams+SharePoint tenant end-to-end verification, migration to core's native buildChannelInboundMediaPayload, richer failure-reason taxonomy. One residual edge not chased here (out of scope, no identity to match on): a transient direct-path failure in a Bot Framework DM followed by BF-by-ID recovery of the same file would leave a stale failure, since the BF path's identity space (attachment IDs) does not intersect the shares-URL space.
LGTM.
…263) Root version, 135 plugin manifests synced via scripts/sync-plugin-versions.ts (pnpm plugins:sync), root + 68 extension npm-shrinkwrap.json version fields and openclaw peerDependency ranges bumped, CHANGELOG section for boon.49. Shipping: #246 (tool-result aggregate budget scales with context window instead of a fixed 256k-char cap, so long tool-heavy sessions stop reading their own successful calls as failures and compaction actually fires on real pressure), #253/ENG-20866 (Chrome MCP handshake/navigate timeouts raised for real npx cold-start cost, unblocking browser-handoff live attach), #256/ ENG-20876 (session_id promoted to a real Sentry tag for the per-session reliability dashboard), #260/ENG-20968 (msteams SharePoint/OneDrive download failures surfaced through MediaFailures instead of silently dropped), #261/ ENG-21009 (Sentry node 8.49 -> 10.75.3, clearing ~12 medium Vanta/Inspector findings from its pinned otel/Prisma instrumentation chain), plus undici/ brace-expansion/axios security bumps and markdown-it/dompurify/golang.org/x/net dependency bumps. Base = 2026.6.11-boon.48. Gateway plus @openclaw/slack, @openclaw/msteams and @openclaw/diagnostics-prometheus bumped in lockstep; only @openclaw/msteams source changed in this train (#260), so a fleet-msteams.sh pass is needed on Teams hosts alongside the gateway roll. Co-authored-by: Claude Sonnet 5 <[email protected]>
What Problem This Solves
Dragging a file from a Microsoft Teams chat/channel into a message to the Boon agent passes a link the agent cannot access, even when the customer's SharePoint connection and Microsoft Graph permissions are confirmed set up (Affinity SE, ENG-20968). Users have to download and re-upload the file, or tell the agent which SharePoint folder/project to use.
Investigation found the resolution mechanism already exists in
extensions/msteams: SharePoint/OneDrive-referenced Teams attachments are already rewritten to Microsoft Graph'sGET /shares/{shareId}/driveItem/contentand fetched with the bot's own Graph token (alwaysFetchGraphMessagedefaults totruein this fork). The actual bug is that every failure in that download path was only logged atwarnlevel and never surfaced to the agent — so the agent was left with a bare SharePoint URL in text and zero signal that a download was attempted, let alone why it failed (most commonly: the bot's own Azure AD app lackingFiles.Read.All/Sites.Read.AllGraph consent, which is a separate consent from the SharePoint skill's certificate-basedSites.Selectedapp).Why This Change Was Made
Rather than building new SharePoint integration (none was needed), this wires every download-failure path across the msteams attachment pipeline into core's existing
MediaFailurescontract (InboundMediaFailure), so the agent can tell the user accurately what happened instead of silently ignoring the file or hallucinating about a dead link.Six rounds of adversarial code review (each re-run against the full diff) found and fixed real bugs along the way: a failure being erased when an unrelated attachment in the same message later succeeded via a fallback path, a SharePoint reference attachment being retried and double-reported, oversized inline
data:images being dropped one layer above the new failure plumbing, malformed GraphhostedContentsitems vanishing silently, and both an over-eager and (after narrowing it) a too-narrow failure-dedup key. Full history of what was found/fixed/declined is in the linked issue thread.User Impact
too_largenotice instead of vanishing.docs/channels/msteams.mdnow documents that resolving a dragged SharePoint/OneDrive file needs its own Graph consent (Files.Read.All/Sites.Read.All, Application) on the Teams bot's own Azure AD app — distinct from, and not satisfied by, the SharePoint skill's certificate-basedSites.Selectedapp. This is the most likely actual root cause for Affinity SE's report, and the same confusion that produced a prior (superseded) S3H RCA.Follow-ups flagged but intentionally out of scope here (noted in the issue, not blocking this PR):
buildChannelInboundMediaPayload/mediaFailuresplumbing (which Slack's equivalent path already uses) instead of this PR's localbuildMSTeamsMediaPayloadimplementation.classifySlackMediaFetchError) instead of the genericfetch_failedbucket most paths here use.Evidence
extensions/msteamssuite: 1084/1085 passing. The one failure (channel.actions.test.ts > exposes pinnedMessageId in the tool schema) is pre-existing onboonwith this branch's changes reverted — confirmed via a scratchgit stashcomparison — and unrelated to this change.tsgo:extensionsandtsgo:extensions:test: clean, no diagnostics.oxfmt --check: clean.src/plugins/contracts/plugin-sdk-runtime-api-guardrails.test.ts: passing (barrel-export pin updated for the newInboundMediaFailureReason/InboundMediaFailurere-exports).Linear: https://linear.app/getboon/issue/ENG-20968/affinity-se-teams-drag-and-drop-file-links-not-usable-by-boon-agent
🤖 Generated with Claude Code
Summary by cubic
Fixes dragging files from a Teams chat/channel into Boon so the agent no longer silently drops them. The SharePoint/OneDrive resolution already existed via Graph's
/shares/{shareId}/driveItem/content, but every download failure was only warn-logged and never surfaced, so the agent responded as if no file was attached.The full msteams attachment pipeline (direct contentUrl downloads, inline
data:images, SharePoint references, Graph hostedContents, Bot Framework DMs) now reports failures through core'sMediaFailurescontract, so the agent tells the user explicitly when a file couldn't be read.Bug fixes
too_largefailure instead of vanishing; failures are no longer erased when an unrelated attachment in the same message recovers.hostedContentsitems and allowlist-blocked URLs now surface failures instead of disappearing.Migration
docs/channels/msteams.mdnow documents that resolving a dragged SharePoint/OneDrive file needsFiles.Read.All/Sites.Read.All(Application) consent on the Teams bot's own Azure AD app — a separate grant from the SharePoint skill's certificate-basedSites.Selectedapp, and the likely root cause for the reported Affinity SE case.Written for commit ec42ab8. Summary will update on new commits.