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
Attaching a text file that starts with "BM" fails with "Image could not be decoded" #59245
A text file whose content starts with the letters "BM" is detected as a BMP image when it is attached to a prompt. A CSV with a "BMI" column or notes that start with "BMW" are enough. The server then tries to decode it as an image and rejects the whole prompt with HTTP 400 Image could not be decoded. Text that starts with "GIF8" fails the same way, and the read tool returns such a file to the model as a base64 GIF image instead of text.
Mime.detect in packages/core/src/mime.ts only checks the first two bytes for BMP ("BM") and the first four for GIF ("GIF8"). Attachments get their type from it, including the file:// URIs that TUI and app file mentions send.
Thanks for the clear report, I can confirm this on 2.1.4.
I started opencode serve, created a session and sent a prompt with one file attached by file:// URI each time:
plain,age\n22.5,31 is accepted and attached as text/plain.
BMI,age\n22.5,31 gets HTTP 400 Image could not be decoded: file:///…/bmi.csv.
GIF8 notes\nhello gets the same 400.
It still happens on the latest dev (ed74ec8) run from source. I didn't separately check the read tool returning a GIF8 file as a GIF image. It goes through the same Mime.detect, though, which only looks at the first 2 bytes (BM) or 4 bytes (GIF8), as you pointed out.
The script below reproduces it against the API.
Reproduction script (repro.sh)
#!/usr/bin/env bash# Reproduces #59245: text files starting with "BM" / "GIF8" are sniffed as images# and the prompt is rejected with "Image could not be decoded".# Usage: repro.sh [opencode command...] (defaults to `opencode` on PATH)set -u
OC=("${@:-opencode}")
PORT=4211
PROJ=$(mktemp -d)cd"$PROJ"printf'BMI,age\n22.5,31\n'> bmi.csv
printf'GIF8 notes\nhello\n'> gif.txt
printf'plain,age\n22.5,31\n'> ok.csv
export OPENCODE_SERVER_PASSWORD=repro-pass
"${OC[@]}" serve --port $PORT>"$PROJ/serve.log"2>&1&
PID=$!trap'kill $PID 2>/dev/null' EXIT
foriin$(seq 1 60);do curl -s -o /dev/null localhost:$PORT/api/session -u opencode:x &&break; sleep 1;done
PASS=$(grep -o 'server password .*' serve.log | awk '{print $3}'); PASS=${PASS:-$OPENCODE_SERVER_PASSWORD}api() { curl -s -u "opencode:$PASS" -H 'content-type: application/json'"$@";echo; }
SID=$(api -X POST localhost:$PORT/api/session -d "{\"location\":{\"directory\":\"$PROJ\"}}"| sed -E 's/.*"id":"([^"]+)".*/\1/')echo"session: $SID"forfin ok.csv bmi.csv gif.txt;doecho"--- prompt with $f attached"
api -w 'HTTP %{http_code}' -X POST localhost:$PORT/api/session/$SID/prompt \
-d "{\"text\":\"Inspect this\",\"files\":[{\"uri\":\"file://$PROJ/$f\"}]}"done
Activity
opencode-agent commentedon Oct 26, 2026
Thanks for the clear report, I can confirm this on 2.1.4.
I started
opencode serve, created a session and sent a prompt with one file attached byfile://URI each time:plain,age\n22.5,31is accepted and attached astext/plain.BMI,age\n22.5,31gets HTTP 400Image could not be decoded: file:///…/bmi.csv.GIF8 notes\nhellogets the same 400.It still happens on the latest
dev(ed74ec8) run from source. I didn't separately check the read tool returning aGIF8file as a GIF image. It goes through the sameMime.detect, though, which only looks at the first 2 bytes (BM) or 4 bytes (GIF8), as you pointed out.The script below reproduces it against the API.
Reproduction script (repro.sh)
Run it:
bash repro.sh