You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tui: attaching a PDF file to a prompt returns HTTP 500 (attachment normalization crash) #57726
Attaching a PDF file to a prompt in the TUI crashes prompt submission with an HTTP 500: the server fails schema validation inside SessionPrompt.normalizeImageAttachment (the attachment's base64 string does not match the Prompt.Base64 pattern), the client surfaces Failed to set up session: UnexpectedStatus: 500, and the message is not persisted — the targeted session is left completely empty.
Impact: any attempt to attach a PDF on this setup repeatedly returns 500; the user cannot attach PDFs at all, with no clear error explaining why.
Environment
opencode version: v2.1.2 (official install)
OS: Darwin 27.0.0, arm64 (macOS, Apple Silicon M1)
Terminal: Apple Terminal, TERM=xterm-256color, COLORTERM=truecolor
Shell: /bin/zsh
Install/channel: latest
Active plugins: none (no plugin key in ~/.config/opencode/opencode.json, nothing under .opencode/)
Reproduction
Run opencode (v2.1.2) in Apple Terminal.
Start a new session.
Attach a PDF file to the prompt (added via file selection in the TUI).
Send the prompt.
Result: the client shows "Failed to set up session — UnexpectedStatus: 500". The sessions targeted by the failing POST remain empty (GET /api/session/{id}/message returns {"data":[],"cursor":{...}}).
Expected Behavior
Either (a) submit the prompt and handle the non-image attachment gracefully, or (b) reject the unsupported attachment type with a clear, actionable validation error — not an unhandled HTTP 500 and a cryptic "Failed to set up session" message.
Actual Behavior
Server log (~/.local/share/opencode/log/opencode.log) shows two failing POSTs, both returning http.status=500:
level=INFO http.method=POST http.url=/api/session/ses_...1/prompt http.status=500
cause="Error: Schema validation failed
at jd (/$bunfs/root/chunk-ebxzfa7x.js:2:28720)
at <anonymous> (/$bunfs/root/chunk-zpbe9kf3.js:124:299)
at SessionPrompt.normalizeImageAttachment (/$bunfs/root/chunk-zpbe9kf3.js:124:23)
at SessionPrompt.materializeAttachment (/$bunfs/root/chunk-mdmwmx3f.js:18:25988)
at SessionPrompt.prepare (/$bunfs/root/chunk-zpbe9kf3.js:140:5532)
at Session.prompt (/$bunfs/root/chunk-bqqk6a8d.js:440:7488) {
[cause]: Error: { ... "_tag":"Filter", "annotations":{"expected":"a string matching the RegExp ^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$" ... "identifier":"Prompt.Base64" ... }, "issues":[{ ... "_tag":"InvalidValue"}] }
}"
The normalized "base64" content is apparently the raw PDF (or a non-base64-encoded representation), failing the Prompt.Base64 regex and throwing unhandled.
Session IDs redacted.
Additional Context
The background service itself was healthy at the time (opencode service status OK, opencode api get /api/info → version 2.1.2, PID alive), so this is not a service-down problem.
Related observation from the same period, filed here as context in case it helps: a session that contains a message with an unsupported attachment (audio/file content type, error snipped below) fails every subsequent message with Failed to drain Session: Upstream request failed: [unsupported_content_type] Messages may contain text, images and video; this model does not read audio or files. — i.e., the bad message persists in history and permanently poisons the session; there is no toast or recovery path to drop the offending message.
Frequency: reproduced on 2 consecutive attempts, once in each of 2 different new sessions.
Workaround: paste the content as text or attach a PNG/JPG screenshot instead of the PDF; do not re-use the poisoned session.
Thanks for the detailed report and the log. I think this is a duplicate of #45558.
The 500 doesn't mean your PDF was encoded wrong. OpenCode base64-encodes the file itself, so the data is always valid. The problem is the Prompt.Base64 check: its regex wrongly rejects valid base64 once the string is longer than a few MB, in the runtime the release binary ships with. So in practice any attachment over roughly 5–6 MB fails with exactly this Schema validation failed … Prompt.Base64 error from normalizeImageAttachment. The check is unchanged in 2.1.2, and a proposed fix (#51272) hasn't been merged yet.
Possible duplicates and related issues, ordered by likelihood:
If your PDF is small (well under 5 MB) and still fails, please reply with its size, because that would point to a different bug. Until the fix lands, converting the PDF to text first (for example with pdftotext), or letting the agent read the file from its local path, should work.
The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different.
Activity
opencode-agent commentedon Oct 21, 2026
Thanks for the detailed report and the log. I think this is a duplicate of #45558.
The 500 doesn't mean your PDF was encoded wrong. OpenCode base64-encodes the file itself, so the data is always valid. The problem is the
Prompt.Base64check: its regex wrongly rejects valid base64 once the string is longer than a few MB, in the runtime the release binary ships with. So in practice any attachment over roughly 5–6 MB fails with exactly thisSchema validation failed … Prompt.Base64error fromnormalizeImageAttachment. The check is unchanged in 2.1.2, and a proposed fix (#51272) hasn't been merged yet.Possible duplicates and related issues, ordered by likelihood:
Prompt.Base64HTTP 500 onPOST /api/session/<id>/prompt, with the root-cause analysis and reports of PDFs and other large files on 2.0.xIf your PDF is small (well under 5 MB) and still fails, please reply with its size, because that would point to a different bug. Until the fix lands, converting the PDF to text first (for example with
pdftotext), or letting the agent read the file from its local path, should work.The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different.