Skip to content

fix(media): surface inbound attachment failures to the user and the model - #139

Merged
convyusboy merged 4 commits into
boonfrom
worktree-frolicking-tinkering-lighthouse
Aug 20, 2026
Merged

convyusboy merged 4 commits into
boonfrom
worktree-frolicking-tinkering-lighthouse

Conversation

@convyusboy

@convyusboy convyusboy commented Aug 20, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Resolves a problem where a user who attaches a file to an agent chat thread on Slack (and, via a paired plugin-repo change, Boon Web) would sometimes get no reply reflecting the file at all — the attachment silently failed to download or stage, the turn proceeded as if nothing was ever sent, and the agent would confidently claim no file was attached. There was no error, no retry, and no way for the user to know what went wrong.

Why This Change Was Made

Every layer of the inbound-attachment pipeline (channel download, sandbox staging) was fail-soft with no error channel: a failed download or staging attempt just vanished. This adds a closed InboundMediaFailureReason union carried on MsgContext (unaligned with the existing MediaPaths/MediaUrls/MediaTypes arrays, since a failure has no path of its own), renders it into the model-facing prompt note so the agent is never left claiming a file wasn't sent, and delivers a best-effort user-visible chat notice before the agent turn starts naming the file and a plain-language reason (expired link, too large, timed out, etc.) with a Retry suggestion. Slack's inbound media resolver is rewritten to classify and report every download failure instead of swallowing it to null, adds bounded retry for transient failures, and fixes a partial-failure hole where one successful attachment used to hide every other file's failure. A related staging cliff (files that download fine under a channel's cap but silently fail a smaller internal size limit) and a logging gap for binary attachments are also fixed. Out of scope: raising any size caps, and a positive "unpack this file with a tool" prompt marker for binary attachments (follow-up).

User Impact

A file that fails to reach the agent is now always visible: the agent's own reply references the failure instead of denying the file was sent, and — on Slack — the user gets an explicit chat message naming the file and why it failed, with guidance to retry. A file that transiently fails to download is now retried automatically before being reported as failed.

Evidence

  • pnpm test (via node scripts/run-vitest.mjs) on every touched file: Slack extension full suite 1372/1372 passing, core auto-reply/media-understanding/channels/inbound-event suites for every touched area passing, new inbound-media-failure-notice.test.ts (16 cases) passing.
  • tsgo clean for tsconfig.core.json, tsconfig.extensions.json, and test/tsconfig/tsconfig.core.test.json.
  • pnpm plugin-sdk:api:gen regenerated cleanly for the new mediaFailures SDK export.

Summary by cubic

Surfaces inbound attachment failures to both the user and the model instead of silently dropping them. Previously failed downloads/staging were ignored; now each failure is classified (including timeouts), included in the prompt, and a best‑effort notice is sent before the agent turn (and again after staging for new failures), even when directives or plugins early‑return.

  • Adds a closed failure vocabulary on MsgContext (InboundMediaFailureReason) and unaligned MediaFailures; media-note renders failure lines even when no media arrived, and the image‑reply hint only appears when actual media exists. Staging records too_large/unavailable, de‑duplicates by exact source path, and reports failures so the agent isn’t left with an unstaged path.
  • Sends a best‑effort inbound failure notice naming files (sanitized), skips unmentioned room events and non‑deliverable channels, and correctly handles partial/suppressed sends. The notice fires before hooks and early returns and again after staging without double‑reporting.
  • Slack: resolveSlackMedia now returns { media, failures } (never null) and classifies per‑file failures (too_large, expired_link, fetch_failed, timed_out, over_file_limit). Adds bounded retry for transient fetches and skips fresh‑URL retry for too_large. Treats Slack auth HTML as expired for direct files and forwarded images, handles malformed/disallowed URLs per‑file, surfaces partial failures alongside successes, preserves filename/content type on forwarded/shared attachments, and logs (but drops) thread‑starter hydration failures.

Migration

  • Channel integrations: when building inbound context, pass successful attachments via media and any drops via mediaFailures to buildChannelInboundEventContext/finalizeChannelInboundContext.
  • Slack plugin callers: update to handle resolveSlackMedia’s new outcome (outcome.media, outcome.failures) instead of T[] | null. No config changes required.

Written for commit 7b08aa1. Summary will update on new commits.

Review in cubic

@claude

claude Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 29 files

Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.

Re-trigger cubic

Comment thread extensions/slack/src/monitor/media.ts Resolved
Comment thread src/auto-reply/reply/get-reply.ts Resolved
Comment thread extensions/slack/src/monitor/media.ts Resolved
Comment thread docs/channels/slack.md Resolved
Comment thread extensions/slack/src/monitor/media.ts Resolved

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 18 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread extensions/slack/src/monitor/media.ts Resolved
Comment thread src/auto-reply/reply/get-reply.ts Resolved
convyusboy and others added 4 commits August 20, 2026 20:14
…odel

Every channel and staging step that could drop an inbound attachment used
to fail silently, leaving the agent to answer as if no file was ever sent.
Adds a closed InboundMediaFailureReason seam on MsgContext, renders it in
the model-facing media note, and delivers a best-effort user-visible
notice before the agent turn starts. Slack now classifies and reports
every download failure (with bounded retry) instead of swallowing it to
null, fixes the 1-of-N partial-failure hole, and the 5MB post-download
staging cliff is now recorded instead of silently discarded.
…facing

- Fix a P1 regression: createSlackMediaRequest ran before the try/catch in
  downloadSlackMediaFile, so one malformed/disallowed attachment URL threw
  out of mapLimit's Promise.all and rejected the whole batch instead of
  becoming a per-attachment failure.
- Fix duplicate MediaFailures entries when stageSandboxMedia runs twice on
  the same ctx for remote-host attachments.
- Fix the before_agent_reply hook path skipping the attachment-failure
  notice entirely for plugin-handled turns; the notice now fires before
  the hook check (for channel-level failures) and again after staging
  (for anything staging adds), without double-reporting.
- Add a timed_out reason so Slack's own download timeout no longer
  collapses into the generic fetch_failed bucket.
- Apply the same HTML-auth-page guard to forwarded-image downloads that
  direct file downloads already had, so an expired forwarded-image link
  isn't reported as a successful image.
- Sanitize the attachment name in the user-facing notice the same way the
  model-facing note already does.
- Skip the fresh-URL retry for too_large failures (a fresh URL can't make
  a file smaller).
- Correctly classify partial/suppressed durable-send outcomes instead of
  logging them as a successful notice send.
- Qualify a doc claim that overstated when the user-facing notice fires.
- Bump the plugin SDK surface budget for the two new public type exports.
- Remove leftover internal ticket references from source comments.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
The previous commit added a timed_out reason to the shared vocabulary but
never wired Slack's own SLACK_MEDIA_TOTAL_TIMEOUT_MS race to use it — the
timeout still threw a plain Error, so classifySlackMediaFetchError kept
falling through to the generic fetch_failed bucket. Introduces a
dedicated SlackMediaTimeoutError so the classifier can tell a real timeout
apart from every other download failure, and adds a regression test for
the P1 fix (a malformed/disallowed attachment URL must fail as a
per-attachment result, not reject the whole resolveSlackMedia batch).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
- Dedup sandbox staging failures by exact source path (WeakMap), not
  name+reason, so two different files sharing a basename are never
  conflated.
- Preserve filename/content-type on forwarded-image download failures
  in the Slack extension instead of dropping them.
- Report existing MediaFailures before every early-return path in
  get-reply (native slash, directives, inline actions, before_agent_reply
  hook), not only after sandbox staging.
@convyusboy
convyusboy force-pushed the worktree-frolicking-tinkering-lighthouse branch from fdcc0e2 to 7b08aa1 Compare August 20, 2026 13:27

@gandalfboon gandalfboon 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.

Approving.

The core seam is right: one closed InboundMediaFailureReason union carried on MsgContext.MediaFailures — deliberately unaligned with MediaPaths/MediaUrls/MediaTypes (a failure has no path/url/index of its own, and folding it in would have corrupted every consumer that assumes parallel-array alignment). The two copy tables (model-facing in media-note.ts, user-facing in inbound-media-failure-notice.ts) are keyed as Record<InboundMediaFailureReason, string> so adding a reason is a compile error at both renderers — that's the discipline that stops the two vocabularies from drifting.

Coverage of the failure surface is thorough:

  • Slack resolveSlackMedia returns { media, failures } and classifies every download failure (too_large, expired_link, fetch_failed, timed_out, over_file_limit) instead of collapsing to null.
  • The createSlackMediaRequest-inside-try/catch fix means one malformed/disallowed URL becomes a per-attachment failure instead of rejecting the whole batch — regression test in media.test.ts.
  • Dedicated SlackMediaTimeoutError so the total-timeout race actually classifies as timed_out, not the generic fetch_failed bucket.
  • The HTML-auth-page guard (isHtmlAuthPageDownload) applied to both direct and forwarded-image downloads — customer's real failure shape (Slack returns 200 with an HTML login page on an expired URL).
  • Fresh-URL retry correctly skipped for too_large (a fresh URL can't make a file smaller).
  • stageSandboxMedia records the 5MB post-download cliff via a WeakMap keyed on ctx + Set of source paths — dedup by exact absolute path (not name+reason), so two distinct files sharing a basename aren't conflated. Regression test covers that case.
  • reportNewMediaFailures in get-reply.ts fires the notice before every early-return path (native slash, directive, inline action, before_agent_reply hook) and again after staging, tracked by reportedMediaFailureCount so no failure is double-reported. Regression test proves the hook-handled path.
  • mediaReplyHint gated on hasInboundMedia(ctx) not just a rendered note — a failures-only turn no longer promises a media reply. Nice catch.
  • Thread-starter hydration deliberately drops failures (with a log) — the user didn't attach a file in this turn, so a notice about a root message's dead file would be a false alarm. Correct call.

Tests: 16-case inbound-media-failure-notice.test.ts covers destination resolution, event-kind gating, empty-input skipping, copy rendering, delivery failure swallowing, and independence from NO_REPLY. Slack media tests cover every classified reason. Prepare-content test verifies partial-failure reporting and the generic-name fallback. Media-note tests cover total-failure, per-file-failure, and partial-failure line composition.

Security: no secrets (scanned the full commit history). Untrusted filename text sanitized via the shared sanitizeInlineMediaNoteValue before rendering into either prompt or chat. Retry declines on max_bytes and abort. SSRF policy retained.

Migration is documented (channel integrations pass mediaFailures alongside media; Slack plugin callers handle the new outcome shape) and the SDK public-export budget bumped +2 for the two new type exports — the exact delta.

CI green on the shards that matter (types, lint, security, boundaries, docs, plugin SDK contract). All 25 review threads resolved; cubic-bot's latest re-review confirms "all reported issues were addressed." Signed commits throughout.

@convyusboy
convyusboy merged commit cf220d4 into boon Aug 20, 2026
145 checks passed
@convyusboy
convyusboy deleted the worktree-frolicking-tinkering-lighthouse branch August 20, 2026 13:51
convyusboy added a commit that referenced this pull request Aug 21, 2026
Cut a fork release containing the inbound-attachment-failure-visibility
fix from #139, the Slack reply-session-init-conflict retry from #132, and
the browser login handoff tool from #137.

Bump the gateway and published fork plugins in lockstep.
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.

1 participant