Skip to content

attachments: large files (~6MB+) crash the prompt with HTTP 500 instead of a size-limit error #54323

Closed as duplicate

Description

@qiufengdiewu

Description

Summary

Sending a prompt with a file attachment larger than ~5–6 MB fails with
UnexpectedStatus: 500. The server log shows Schema validation failed inside
SessionPrompt.normalizeImageAttachment (a Prompt.Base64 validity check)
instead of a clear "attachment too large" error. A ~5 MB attachment succeeds;
≥6 MB attachments fail consistently. Every retry of the same message keeps
failing, and there is no user-facing hint about any size limit.

Environment

  • opencode version: 2.0.26
  • OS: Windows_NT 10.0.19045 (win32 x64)
  • Terminal: standard Windows console; CLI usage via opencode run
  • Shell: C:\WINDOWS\system32\cmd.exe
  • Install/channel: npm global install (latest)
  • Active plugins: oh-my-opencode-slim@3.0.2

Reproduction

  1. Prepare a file larger than 6 MB (reproduced with a 6.3 MB synthetic binary
    and a 6.6 MB PDF).
  2. Run: opencode run --session --file "big.pdf" "test"
    3.Observe the request fail with: Error: UnexpectedStatus: 500

Relevant server log lines (~/.local/share/opencode/log/opencode.log, role=server):
cause="Error: Schema validation failed
at (chunk-5gdygp26.js:4:44934)
at SessionPrompt.normalizeImageAttachment (chunk-b7pgr6s2.js:115:23)
at SessionPrompt.materializeAttachment (chunk-z2s2g3dy.js:24:23833)
at SessionPrompt.prepare ...
at Session.prompt ... {
[cause]: Error: {"~effect/SchemaIssue/Issue":..., "identifier":"Prompt.Base64",
"issues":[{..."expected":"a string matching the RegExp
^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$",
..."_tag":"InvalidValue"}]}
}"
http.method=POST http.url=/api/session//prompt http.status=500
Size boundary (same command, different files):

attachment size result
5.0 MB OK
6.0 MB 500
6.3 MB 500
6.6 MB 500

Expected Behavior

Either the attachment is accepted, or the user gets a clear, actionable error
such as "attachment exceeds the maximum size". Retrying should not repeatedly
produce an opaque 500 with no explanation.

Actual Behavior

HTTP 500 (Schema validation failed, Prompt.Base64 InvalidValue in
normalizeImageAttachment). The client only shows
Failed to send prompt: UnexpectedStatus: 500. The affected session becomes
unusable while that message keeps being retried. Nothing anywhere mentions a
size limit.

Additional Context

  • Related UX suggestion: when an attachment cannot be used (oversized, or a
    type the active model cannot read — e.g. PDF inputs on a text-only model),
    opencode should surface a clear message and suggest a fallback (e.g. convert
    to text first, or read the file via a tool) instead of failing opaquely.
    Currently a PDF attachment enters the pipeline with no warning even when the
    model cannot read it, and an oversized file crashes the whole prompt.
  • Workarounds that work: drop the attachment and send plain text; or convert
    the PDF to text (e.g. with pdftotext) and let the assistant read the
    resulting text file.
  • Reproducibility: 100% (same file every time; survives client restart and
    machine reboot, across multiple sessions).

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Activity

  1. opencode-agent commented on Oct 10, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed report and the size table, they make the cause easy to pin down. I think this is a duplicate of #45558.

    The 500 doesn't come from a size limit. The Prompt.Base64 check uses a regex that stops working on base64 strings longer than a few MB: it rejects valid data, so any attachment over roughly 5–6 MB fails with Schema validation failed before it reaches the provider.

    Possible duplicates and related issues, ordered by likelihood:

    Your broader idea of warning when the active model can't read an attachment type (such as a PDF on a text-only model) is separate from this bug. Feel free to open a feature request for it.

    The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different.

  2. qiufengdiewu commented on Oct 10, 2026

    @qiufengdiewu
    Author
  3. opencode-agent commented on Oct 10, 2026

    @opencode-agent
    Contributor

    这不是 OpenCode 的设计特性,而是一个已知 bug。问题出在附件的 base64 校验上:所用的正则在字符串超过几 MB 后就会失效,把正常文件误判为无效,于是返回 500。它与文件大小限制无关。

    这个 bug 已在 #45558 中跟踪(#50336 是同一问题),另有一个待合并的修复 PR #51272。关闭本 issue 只是为了把讨论集中到 #45558,并不代表不会修复。具体何时合并由维护者决定,我这边无法承诺时间。你可以订阅 #45558 关注进展。

    在修复之前,可以先用你已经找到的办法绕过:不附加大文件,或者先把 PDF 转成文本(例如用 pdftotext),再让助手读取这个文本文件。


    This isn't intended behaviour, it's a known bug. The base64 check on attachments uses a regex that breaks on strings over a few MB, so it rejects valid files and returns a 500. There is no actual size limit involved. The bug is tracked in #45558 (#50336 is the same problem), and an open PR, #51272, fixes it. This issue is being closed only to keep the discussion in one place, not because it won't be fixed. When the fix is merged is up to the maintainers, so I can't promise a timeline; you can subscribe to #45558 to follow it. Until then, your workarounds (skip the large attachment, or convert the PDF to text first) still work.

  4. qiufengdiewu commented on Oct 10, 2026

    @qiufengdiewu
    Author
  5. opencode-agent commented on Oct 10, 2026

    @opencode-agent
    Contributor

    什么时候修复: 修复 PR #51272 目前还没有合并,具体时间由维护者决定,我这边无法给出时间。可以订阅 #45558 或 #51272,合并后会有通知。

    修复后能传多大的文件: OpenCode 代码中已有的单个附件上限是 20 MB(MAX_ATTACHMENT_BYTES = 20 * 1024 * 1024)。超过 20 MB 的文件会收到明确的报错(Attachment exceeds the … byte limit),不会再是 500。现在大约 5–6 MB 到 20 MB 之间的文件失败,是校验正则的 bug 造成的,修复后这个区间应该就能正常上传。

    不过,你使用的模型提供商可能还有自己的限制(请求体大小、PDF 页数,或者模型本身是否支持 PDF 输入),所以实际能用的上限可能更低,例如 #35112 中提到的 6 MB 请求体限制。

    在修复发布之前,先用 pdftotext 把 PDF 转成文本再让助手读取,仍然是最稳妥的办法。


    When will it be fixed: the fix (#51272) hasn't been merged yet, and I can't give a timeline because that's up to the maintainers. You can subscribe to #45558 or #51272 to get notified.

    How large after the fix: OpenCode already caps each attachment at 20 MB, and larger files get a clear "Attachment exceeds the … byte limit" error instead of a 500. The current failures between about 5 and 20 MB come from the regex bug, so files in that range should work once it's fixed. Your provider or model may still set lower limits of its own (request size, PDF pages, whether it accepts PDFs at all; see #35112).

  6. opencode-agent commented on Oct 11, 2026

    @opencode-agent
    Contributor

    本 issue 作为 #45558 的重复问题关闭:同样是 Prompt.Base64 校验在 5–6 MB 以上的附件上失效,导致 HTTP 500。关闭只是为了把讨论集中到 #45558,不代表不会修复。修复 PR #51272 仍在等待合并,可以订阅 #45558 或 #51272 关注进展。在修复之前,先把 PDF 转成文本(例如用 pdftotext)仍然可用。如果你的情况和 #45558 其实不同,欢迎在这里回复说明。


    Closing as a duplicate of #45558: it's the same Prompt.Base64 validation failure that causes the HTTP 500 on attachments over about 5–6 MB. This keeps the discussion in one place and doesn't mean it won't be fixed. The fix, PR #51272, is still waiting to be merged; subscribe to #45558 or #51272 to follow it. Until then, converting the PDF to text first still works. If your problem turns out to be different, reply here and say how.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions