Skip to content

feat(server): remove the 50 MiB upload size cap and stream uploads to disk - #2312

Merged
sailist merged 1 commit into
MoonshotAI:mainfrom
sailist:feat/upload-no-size-cap
Jul 28, 2026
Merged

feat(server): remove the 50 MiB upload size cap and stream uploads to disk#2312
sailist merged 1 commit into
MoonshotAI:mainfrom
sailist:feat/upload-no-size-cap

Conversation

@sailist

@sailist sailist commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — the problem is explained below.

Problem

The built-in server's /files upload endpoint rejected anything over 50 MiB with an upload-too-large error, which blocked large attachments (for example videos or archives added through the web UI). The cap also acted as a memory guard: uploads were buffered fully in memory before being written to disk, so simply raising the limit would have made large uploads a memory hazard. The server targets local single-user deployments, so the concurrency/abuse rationale for a hard cap does not apply.

What changed

  • Removed the 50 MiB upload cap from the /files endpoint (both the multipart fileSize limit and the service-level check), and deleted the now-unreachable file.too_large error. The wire code 41301 stays in the protocol because session export still maps its own too-large error onto it.
  • Made the upload path streaming end to end: added writeStream to the filesystem storage service and putStream to the blob store, writing through tmp-file + fsync + rename so a failed upload leaves no partial file behind. FileService.save now pipes the request body straight to disk and only counts bytes for FileMeta.size, so upload memory usage no longer scales with file size.
  • Explicitly set the multipart fileSize to Number.MAX_SAFE_INTEGER: when left unset, @fastify/multipart silently falls back to Fastify's 1 MiB bodyLimit and truncates the file stream (caught by the e2e test).
  • Tests: the former "upload > 50MB → 41301" e2e now uploads 51 MiB and round-trips it; new unit tests cover multi-chunk streaming saves, byte counting, and cleanup when the source stream fails mid-upload.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

… disk

- add writeStream/putStream to the storage and blob store interfaces so
  large values are written incrementally (tmp + fsync + rename) instead of
  being buffered in memory
- FileService.save now streams the request body straight to the blob store
  and only counts bytes for FileMeta.size
- drop the multipart fileSize limit and the file.too_large error from the
  /files upload path (41301 stays in the wire protocol for session export)
@changeset-bot

changeset-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 418c6a6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 28, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@418c6a6
npx https://pkg.pr.new/@moonshot-ai/kimi-code@418c6a6

commit: 418c6a6

@sailist
sailist merged commit d03a488 into MoonshotAI:main Jul 28, 2026
15 checks passed

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 418c6a675d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +116 to +120
/**
* Streamed variant of `atomicWrite`: same tmp + fsync + rename discipline, but
* the content arrives as an `AsyncIterable` so arbitrarily large values never
* sit in memory at once.
*/

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Move the streamed-write note into the file header

In agent-core-v2 source, this new block comment is outside the top-of-file module header, but the scoped guide requires comments to live only in that header and not narrate implementation details. Please move or remove this note so the file follows the v2 comment convention.

AGENTS.md reference: packages/agent-core-v2/AGENTS.md:L13-L13

Useful? React with 👍 / 👎.

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