Repository navigation
feat(attachments): Stream large Slack files instead of storing them - #3339
Merged
thomasjiangcy merged 6 commits intoNov 13, 2026
Merged
Conversation
Non-image Slack files over 25 MiB are recorded without their bytes when the message arrives. The first loadAttachment reads the file from Slack (files.info, then a streamed download into storage), and later loads reuse the stored copy. A deleted or unshared Slack file becomes a tool error. junior_attachments.storage_key and sha256 become nullable. A null key marks a file that has not been downloaded yet. Also match Slack file ids in URLs case-sensitively, so the /files-pri/ segment is no longer read as the file id. Co-Authored-By: Thomas Jiang <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
A pending Slack file row now says "Too large to preview" and has a Download button. The button posts to a new route that runs the same first load as loadAttachment (ensureAttachmentStored) inside the conversation's Slack installation, then the browser downloads the stored copy from the byte route. A deleted or unshared file shows the loadAttachment error inline. The route is a POST so a link prefetch cannot start a 250 MB download. It needs a signed-in viewer who can see the conversation. Move the attachment e2e journeys to conversation-attachments.spec.ts so conversations.spec.ts stays under the file length limit. Co-Authored-By: Thomas Jiang <[email protected]>
The save runs after the prepare request, without user activation, so a target=_blank click can be blocked as a popup. Use a same-window download link instead. An installed home screen app skips the automatic save and uses the refreshed row's Download link.
The byte route sends videos and images inline. Firefox and Safari can ignore the download attribute then, so the same-window save replaced the conversation with the video. The byte route now takes ?download=true to send Content-Disposition: attachment, and the prepared save uses it.
thomasjiangcy
approved these changes
Nov 13, 2026
Non-image Slack files over MAX_EAGER_SLACK_FILE_BYTES stay metadata-only rows. Storing them cost storage for files that are rarely opened. - loadAttachment streams them Slack -> host -> sandbox on every load, in the same 8 MiB parts with scratch-then-move and cleanup. The 250 MiB cap is checked against files.info before the download. Nothing is written to storage and the row does not change. The sandbox gets bytes only. - The dashboard byte route streams them Slack -> browser with the conversation's Slack installation. HEAD checks the file without a download, so the row can show a deleted file inline. The POST prepare route and the Preparing download step are gone. - Every Slack download starts from a row that the conversation-scoped lookup returns. A row from another conversation, a raw Slack file id, or an unknown id gets the normal not-found error and no Slack call. - Remove storeDeferredAttachment, its race handling, and the pending version fingerprint. Co-Authored-By: Thomas Jiang <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c701163. Configure here.
Bugbot review on #3339: - The dashboard loads a large Slack file in a hidden frame instead of a same-window link. A saved file loads no document. An error response loads in the frame, not over the conversation, and the row then asks the server for the reason. This also drops the HEAD before each download, so a file that fails only on the Slack download still shows an error. - Streaming a Slack file now needs a signed-in viewer, also in a public conversation, because each read downloads up to the cap with the bot token. Anonymous HEAD and GET get 401 and make no Slack call.
thomasjiangcy
approved these changes
Nov 13, 2026
23 tasks done
thomasjiangcy
added a commit
that referenced
this pull request
Nov 16, 2026
Large Slack files (non-image, over 25 MiB) are recorded with `storage_key = NULL` and were never stored (#3339). Now the first call that needs the bytes streams the file from Slack into attachment storage once and fills in `storage_key`, `sha256` and `bytes`. Later reads use storage. So `transcribeAudio` (#3489) can sign a storage URL with `createDownloadUrl` (#3488) for every file. **Behavior** - `storeDeferredAttachment` (`store.ts`) streams the source through the existing `writeAttachmentObject` path (fresh write key, retries, size check, sha256). Then it updates the row only where `storage_key IS NULL`, the row is not delete-requested, and the conversation is not purged. When the update misses, it deletes our object and returns the winner's row, or null when the row is no longer live. - `storeAttachmentOnFirstUse` (`download.ts`) does the Slack lookup and the size check, maps errors to `AttachmentDownloadError`, and wraps the store in an `attachment.store` span. - `loadAttachment` and `transcribeAudio` call it first. `transcribeAudio` no longer refuses unstored files. - `writeAttachmentObject` no longer retries `AttachmentSourceUnavailableError`. A file that Slack deleted is not transient. - The dashboard byte route does **not** store. It keeps streaming files from Slack until a tool stores them. **Notes** - No migration: `0107_attachment_deferred_download.sql` already made `storage_key` and `sha256` nullable. - `model-input.ts` is unchanged except for a comment. Only web uploads reach it, and they are always stored. It reads bytes only for images up to 5 MB, and deferred rows are non-images over 25 MiB. **Open risk** - Nobody has checked yet that ElevenLabs can fetch a Vercel Blob signed URL in production. <!-- junior-request-attribution:start --> via @thomasjiangcy. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A71078a65e4a20ded28d6e80cfc50ba2d --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A71078a65e4a20ded28d6e80cfc50ba2d) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A71078a65e4a20ded28d6e80cfc50ba2d/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Thomas Jiang <[email protected]>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Stack: 3rd of 3 (#3333 → #3336 → this PR). This PR stacks on #3336 because it reuses #3336's Slack-file-id attachment ids, its streaming Slack download, the 8 MiB part writes in
loadAttachment, and the 250 MiB cap. The three PRs should merge together.Before this PR, every Slack file streamed into storage when the message arrived, even when Junior never opened it. A 200 MB recording cost download time before the turn started, plus storage and function time.
What changes
MAX_EAGER_SLACK_FILE_BYTES(25 MiB, inchat/slack/vision-context.ts) gets a metadata-only row: Slack file id (source), filename, media type, and declared size. It is never downloaded at ingest and never stored. The model gets the sameloadAttachmentpointer as before. Images and smaller files are stored at ingest, as before.loadAttachment: every load streams the file Slack → host → sandbox.files.inforeturns the current URL and size, and the 250 MiB cap is checked against that size before the download. The bytes go to the sandbox in the same 8 MiB parts as feat(attachments): Stream Slack files and loadAttachment, and raise the file cap to 250 MB #3336, joined in a scratch directory, size-checked, then moved into place; a failure removes the parts. Nothing is written to storage, no sha256 is recorded, and the row does not change. The bot token stays on the host: the sandbox gets bytes only, never a Slack URL or token.GET …/attachments/:id?download=truein a hidden frame, and the route streams the file Slack → host → browser withContent-Disposition: attachment. A saved file loads no document in the frame. An error response loads in the frame, not over the conversation, and the row then sends HEAD (Slackfiles.infoonly, no download) and shows the server's error inline. There is no POST route and no "Preparing download…" step.files.infofile_not_found/file_deleted, a tombstone with no URL, or a 403/404/410 on the download all become " is no longer available: The Slack file was deleted, or Junior can no longer access it."loadAttachmentreturns it asToolInputError; the byte route returns it as 409. The turn keeps going.readAttachmentContent(chat/attachments/download.ts) finds the bytes of one row: storage for a stored file, the source for a large Slack file. It checks the cap beforeopendownloads anything.loadAttachmentand the byte route both use it.chat/slack/client.tsreadPrivateSlackFile,chat/slack/attachments.tsreadSlackAttachmentSource). The attachment core sees only a provider-neutralReadAttachmentSource(chat/attachments/source.ts).createToolspasses the Slack reader toloadAttachmentonly in Slack conversations. The byte route binds the conversation's Slack installation (runWithSlackInstallation, team fromjuniorDestinations.providerTenantId).Security rule
Every Slack download starts from an attachment row that ingest created in that conversation.
loadAttachmentand the byte route look the row up by attachment id and conversation id, and the Slack file id comes only from that row. Neither accepts a raw Slack file id or URL. A row from another conversation, a raw Slack file id, and an unknown id all get the normal not-found error and cause no Slack call (tested on both paths).Schema change
Migration
0107_attachment_deferred_download.sqlmakesjunior_attachments.storage_keyandsha256nullable (DROP NOT NULL×2; no table rewrite). A nullstorage_keymeans "never stored". There is no new status column and no team or installation column:loadAttachmentruns inside the conversation's Slack turn, and the byte route resolves the team from the conversation's root Location.junior_attachment_uploadsdoes not change.Consumers of rows without an object
readLiveAttachmentreturnssourceand a nullablestorageKey;AttachmentRecord.storageKeyisstring | null.matchSlackAttachmentssetspending: true(optional field onmessageAttachmentSchema), andTranscriptAttachment.tsxrenders the Download row.readStoredBytes) treats such a row as unavailable. Only images reach this path, and images are never deferred.collectAttachmentGarbagedeletes only keys that are not null. Purge marking does not change.sendFilesand artifacts always write bytes, so they never create these rows.Idempotency
The id comes from the Slack file id (#3336). A Slack file seen twice maps to one row, and later messages reuse it.
Also fixed
getSlackFileIdused a case-insensitive regex. On real Slack URLs (/files-pri/T…-F…/name), it returnedfilesas the file id. The Chat SDK adapter does not setfetchMetadata.fileId, so this fallback is the path production uses. With #3336's source-based ids, two different Slack files with the same name and type in one conversation would get the same attachment id. The regex is now case-sensitive. The ingest test uses a real-shaped URL and asserts the storedprovider_id.Trade-offs
files.info.storage.get(null)and fail on that one attachment. Rows with objects are not affected.Tests
Extended existing scenarios through real wiring (MSW Slack, Postgres, versitygw):
slack/attachment-media-behavior: a 25 MiB + 1 B video is not fetched at ingest (nofetchData, no download, no object). A repeat gets the same id. The row hasstorage_keynull and the real Slack file id.tools/load-attachment: two loads make twofiles.infocalls and two downloads, the bytes match, storage stays empty, and the row keepsstorage_key/sha256null. Sandbox commands contain no Slack URL or token. A file that grew past the cap is refused before download.file_not_foundand a 404 download each give the tool error and write nothing. A row from another conversation, a raw Slack file id, and an unknown id give "Attachment not found" with no Slack call.attachment-s3-storage: a large Slack file gets a row with no object, and the 30-day GC deletes its row next to a stored file's object and row.api/conversations/attachments: the transcript showspending: true. HEAD callsfiles.infoonly. Two GETs stream the bytes withattachmentdisposition and make two downloads; nothing is stored. A deleted file gives 409 with the message on HEAD and GET. A viewer without access gets 404, and an anonymous viewer of a public conversation gets 401. A row from another conversation, a raw Slack file id, and an unknown id get 404 with no Slack call.conversation-attachments.spec.ts: both large rows show "Too large to preview". Download savesstandup-recording.mp4from?download=true, the page stays on the conversation, and the saved bytes match the streamed response. The deleted file shows its error inline, and the page stays on the conversation.pnpm typecheckandpnpm lintpass. The affected suites pass (42 tests), plus dashboard unit tests (453) and the attachment e2e (2). In the full@sentry/juniorsuite, 3567 passed; 2 unrelated tests (agent-invocation-limits,any-resource-event-automations) timed out under load and pass on rerun.via @thomasjiangcy.
--
View Session [Sentry]