Skip to content

fix(msteams): surface SharePoint/OneDrive download failures as MediaFailures (ENG-20968) - #260

Merged
convyusboy merged 5 commits into
boonfrom
ridho/eng-20968-affinity-se-teams-drag-and-drop-file-links-not-usable-by-boon-agent
Oct 2, 2026
Merged

convyusboy merged 5 commits into
boonfrom
ridho/eng-20968-affinity-se-teams-drag-and-drop-file-links-not-usable-by-boon-agent

Conversation

@convyusboy

@convyusboy convyusboy commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

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's GET /shares/{shareId}/driveItem/content and fetched with the bot's own Graph token (alwaysFetchGraphMessage defaults to true in this fork). The actual bug is that every failure in that download path was only logged at warn level 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 lacking Files.Read.All/Sites.Read.All Graph consent, which is a separate consent from the SharePoint skill's certificate-based Sites.Selected app).

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 MediaFailures contract (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 Graph hostedContents items 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

  • When a dragged SharePoint/OneDrive file fails to download (most commonly a missing Graph consent on the Teams bot's own app), the agent now tells the user explicitly — e.g. "I couldn't read "report.pdf" — it couldn't be downloaded. Re-attach it and I'll take another look." — instead of silently dropping the file or responding as if it saw nothing.
  • Oversized inline images now get a too_large notice instead of vanishing.
  • No change for the success path — files that already downloaded correctly continue to work exactly as before.
  • docs/channels/msteams.md now 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-based Sites.Selected app. 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):

  • Migrating msteams to core's native buildChannelInboundMediaPayload/mediaFailures plumbing (which Slack's equivalent path already uses) instead of this PR's local buildMSTeamsMediaPayload implementation.
  • A richer per-cause failure-reason taxonomy (e.g. Slack's classifySlackMediaFetchError) instead of the generic fetch_failed bucket most paths here use.
  • Live end-to-end verification against a real Teams + SharePoint tenant (no tenant access in this session) — dragging a file into a chat with the bot and confirming the agent reports a failure or success instead of silently ignoring it.

Evidence

  • Full extensions/msteams suite: 1084/1085 passing. The one failure (channel.actions.test.ts > exposes pinnedMessageId in the tool schema) is pre-existing on boon with this branch's changes reverted — confirmed via a scratch git stash comparison — and unrelated to this change.
  • tsgo:extensions and tsgo: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 new InboundMediaFailureReason/InboundMediaFailure re-exports).
  • Every behavior change was test-first (confirmed RED before the corresponding fix went GREEN) across ~45 new/modified tests, including an end-to-end test that builds a real threaded-reply Graph URL (not mocked) to confirm the fix also covers a dragged file inside an existing thread reply, not just a fresh top-level message.

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's MediaFailures contract, so the agent tells the user explicitly when a file couldn't be read.

Bug fixes

  • Failed SharePoint reference downloads are reported once, not retried and double-reported (including duplicate URLs in a single message and failures in threaded replies).
  • A failure named by both the direct download path and the Graph fallback (the same dragged reference failing twice) is reported once, while genuinely distinct same-shaped unnamed failures stay separate.
  • A failure is cleared when a later Graph retry succeeds on that exact attachment, instead of reporting both a success and a failure for the same file.
  • Oversized inline images get a too_large failure instead of vanishing; failures are no longer erased when an unrelated attachment in the same message recovers.
  • Malformed Graph hostedContents items and allowlist-blocked URLs now surface failures instead of disappearing.
  • Cross-path and Graph messageUrl-retry dedup keys on the internal source URL identity, never name/contentType, so genuinely distinct failures (e.g. two oversized images) stay separate.

Migration

  • docs/channels/msteams.md now documents that resolving a dragged SharePoint/OneDrive file needs Files.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-based Sites.Selected app, and the likely root cause for the reported Affinity SE case.
  • Success paths are unchanged.

Written for commit ec42ab8. Summary will update on new commits.

Review in cubic

…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]>
@convyusboy
convyusboy requested a review from a team October 1, 2026 14:53

@boon-hermes-bot boon-hermes-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. downloadMSTeamsAttachments (direct path): the reference attachment passes isDownloadableAttachment ("any attachment with a contentUrl"), resolveDownloadCandidate rewrites it via tryBuildGraphSharesUrlForSharedLink, the shares fetch 403s, onFailure fires with {name: "dragged.pdf", reason: "fetch_failed"}.
  2. mediaList is empty, so the Graph fallback runs (hasHtmlFileAttachment or Boon-fork alwaysFetchGraphMessage: true); downloadMSTeamsGraphMedia re-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 / referenceAttemptCount split correctly fixes the retry double-report without undercounting diagnostics.
  • extractInlineImageCandidates budget-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]>
@convyusboy

Copy link
Copy Markdown
Collaborator Author

RE review #5388028901 (cross-path double-report finding, addressed in 2918fb1):

Verified the claim independently before fixing — traced isDownloadableAttachment (shared.ts, no contentType check) and the direct-path → Graph-fallback call sequence in resolveMSTeamsInboundMedia, and reproduced it with a new failing test before implementing anything. Confirmed real: a dragged SharePoint reference attachment with a contentUrl gets attempted (and fails) via the direct download path first, then the Graph fallback independently rediscovers and re-fails the same attachment, producing a duplicate MediaFailures entry for one file.

Fix: dedupe named failures (keyed on name+contentType+reason) at the final merge point in resolveMSTeamsInboundMedia. Left unnamed failures untouched, per the suggested fix shape, so the existing "two genuinely distinct same-shaped unnamed failures" case still survives — added a dedicated test for that too.

Full extensions/msteams suite: 1086/1087 passing (same one pre-existing, unrelated failure as before). tsgo:extensions/tsgo:extensions:test clean, oxfmt clean. CI green at 2918fb1.

@boon-hermes-bot boon-hermes-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>

@boon-hermes-bot boon-hermes-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

convyusboy and others added 2 commits October 2, 2026 15:09
…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]>

@boon-hermes-bot boon-hermes-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.pdf at 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 onSuccess source-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.All consent 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.

@convyusboy
convyusboy merged commit 554c0e0 into boon Oct 2, 2026
147 checks passed
@convyusboy
convyusboy deleted the ridho/eng-20968-affinity-se-teams-drag-and-drop-file-links-not-usable-by-boon-agent branch October 2, 2026 09:06
convyusboy added a commit that referenced this pull request Oct 2, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants