Repository navigation
fix(media): surface inbound attachment failures to the user and the model - #139
Conversation
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
…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.
fdcc0e2 to
7b08aa1
Compare
There was a problem hiding this comment.
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
resolveSlackMediareturns{ media, failures }and classifies every download failure (too_large,expired_link,fetch_failed,timed_out,over_file_limit) instead of collapsing tonull. - The
createSlackMediaRequest-inside-try/catch fix means one malformed/disallowed URL becomes a per-attachment failure instead of rejecting the whole batch — regression test inmedia.test.ts. - Dedicated
SlackMediaTimeoutErrorso the total-timeout race actually classifies astimed_out, not the genericfetch_failedbucket. - 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). stageSandboxMediarecords the 5MB post-download cliff via a WeakMap keyed onctx+ 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.reportNewMediaFailuresinget-reply.tsfires the notice before every early-return path (native slash, directive, inline action,before_agent_replyhook) and again after staging, tracked byreportedMediaFailureCountso no failure is double-reported. Regression test proves the hook-handled path.mediaReplyHintgated onhasInboundMedia(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.
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
InboundMediaFailureReasonunion carried onMsgContext(unaligned with the existingMediaPaths/MediaUrls/MediaTypesarrays, 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 tonull, 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(vianode scripts/run-vitest.mjs) on every touched file: Slack extension full suite 1372/1372 passing, coreauto-reply/media-understanding/channels/inbound-eventsuites for every touched area passing, newinbound-media-failure-notice.test.ts(16 cases) passing.tsgoclean fortsconfig.core.json,tsconfig.extensions.json, andtest/tsconfig/tsconfig.core.test.json.pnpm plugin-sdk:api:genregenerated cleanly for the newmediaFailuresSDK 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.
MsgContext(InboundMediaFailureReason) and unalignedMediaFailures;media-noterenders failure lines even when no media arrived, and the image‑reply hint only appears when actual media exists. Staging recordstoo_large/unavailable, de‑duplicates by exact source path, and reports failures so the agent isn’t left with an unstaged path.resolveSlackMedianow returns{ media, failures }(nevernull) 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 fortoo_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
mediaand any drops viamediaFailurestobuildChannelInboundEventContext/finalizeChannelInboundContext.resolveSlackMedia’s new outcome (outcome.media,outcome.failures) instead ofT[] | null. No config changes required.Written for commit 7b08aa1. Summary will update on new commits.