opencode: images above ~200k px are dropped in the nixpkgs build ("could not be decoded")
Nixpkgs version
- Unstable (26.11)
Describe the bug
pkgs.opencode cannot decode tool-result images: the read tool returns
[1 image omitted: could not be decoded.] for any image above roughly 200k
pixels, while the official v2.2.5 linux-x64 release binary reads the same
files correctly. Images below that threshold pass through untouched, and
attachments (opencode run -f) work, so the package looks fine at first.
This is not an upstream bug: same version, same model, same file, only the build differs.
Steps to reproduce
- Create two PNGs from any screenshot: 480x400 (192k px, ~16 KB) and 480x600 (288k px, ~15.6 KB — fewer bytes than the first).
- Run the nixpkgs
opencodeand ask an agent toreadeach of them. - The 480x400 image is visible; the 480x600 image is replaced with
[1 image omitted: could not be decoded.].
The boundary tracks pixels, not bytes. Measured on this machine: 384x480 and
480x400 work; 480x500, 448x560 and 480x600 fail. -f attachments work at any
size (tested 1440x1800, 90 KB).
Minimal reproducer
# Any 480x600 PNG works as the fixture, e.g. a screenshot crop.
nix shell nixpkgs#imagemagick -c magick input.png -crop 480x600+0+0 +repage /tmp/t500.png
nix run github:NixOS/nixpkgs/f9a75f41be3a74eab55d3a7679d34ad6cc0da977#opencode -- \
run --standalone -m <any-vision-model> \
"read /tmp/t500.png; reply SEE if visible, DECODE-FAILED if not"
# -> DECODE-FAILED
# Same file, official release binary:
curl -LO https://github.com/anomalyco/opencode/releases/download/v2.2.5/opencode-linux-x64.tar.gz
tar xzf opencode-linux-x64.tar.gz
./opencode run --standalone -m <any-vision-model> \
"read /tmp/t500.png; reply SEE if visible, DECODE-FAILED if not"
# -> SEE
Expected behaviour
Both builds deliver the image to the model.
Screenshots
Not applicable.
Relevant log output
[1 image omitted: could not be decoded.]
Additional context
The failing code path is Image.normalize: it loads the Photon worker with
import("/$bunfs/root/chunk-*.js", { with: { type: "file" } }) and hands it to
Photon. When that import throws, normalize yields PhotonUnavailableError
and the tool-result handler substitutes the omission string, which blames the
file rather than the build. Small images never reach normalize (core
short-circuits images within the inline limits), which is why only larger ones
fail. Upstream issue anomalyco/opencode#27109 has the same signature for
packaged builds and was closed as fixed; it does reproduce here.
Upstream packages/cli/script/build.ts at v2.2.5 builds
entrypoints: ["./src/index.ts", "./src/photon-worker.ts"] with
splitting: true; the derivation in
pkgs/by-name/op/opencode/package.nix invokes
bun --bun ./script/build.ts --single --skip-install (Bun 1.4.4, the same
version upstream pins). --single only filters build targets in that script, so
it is a suspect rather than a proven cause — the remaining difference between
the two builds is what needs bisecting.
Suggested check for the fix: a >240k px PNG must survive read.
Workaround for users meanwhile: attach instead of reading, or keep tool-result
images at or below 480x400.
Disclosure: this report was drafted with AI assistance and reviewed by the submitting account owner before posting.
System metadata
- system: `"x86_64-linux"`
- host os: `Linux 6.18.60, NixOS (nixos-unstable, pinned nixpkgs f9a75f41be3a74eab55d3a7679d34ad6cc0da977)`
- multi-user?: `yes`
- sandbox: `yes`
- version: `nix-env (Nix) 2.34.9`
- nixpkgs: `/nix/store/qyccs9pc22b3fvl2lxia3jagcg97dn48-source`
Notify maintainers
@delafthi @DuskyElf @graham33 @xiaoxiangmoe
Note for maintainers: Please tag this issue in your pull request description. (i.e. Resolves #ISSUE.)
I assert that this issue is relevant for Nixpkgs
- [X] I assert that this is a bug and not a support request.
- [X] I assert that this is not a duplicate of an existing issue.
- [X] I assert that I have read the NixOS Code of Conduct and agree to abide by it.
- [X] I assert that I have read the automation/AI policy and that this issue report complies with it.
I couldn't reproduce this on the exact pinned build (f9a75f41, opencode 2.2.5).
With a mock OpenAI-compatible provider that makes the model call read, the 480x400, 480x500, 448x560, and 480x600 PNGs all reached the provider with the image attached and no omission. 1440x1800 also works. A 3000x2000 image was resized by Photon: the base64 went from about 323k characters to about 123k, so the worker and wasm are loading and resizing. No photon worker unavailable warnings.
The import("/$bunfs/root/chunk-*.js", { with: { type: "file" } }) code in the report is from 1.14.48 (#27109), not 2.2.5. In 2.2.5, Photon runs in a worker (packages/cli/src/photon-worker.ts) and falls back to in-process. If the worker or wasm is missing, ResizerUnavailableError passes the image through unchanged; it does not produce an omission. [1 image omitted: could not be decoded.] is Image.DecodeError, which means Photon loaded and rejected the image bytes. --single only filters build targets in packages/cli/script/build.ts; it doesn't change the entrypoints or splitting: true.
Can you attach the failing PNG, opencode --version, and the --print-logs --log-level debug output? Please retest on 2.2.6 from master too, though the image code is unchanged between 2.2.5 and 2.2.6.
Thanks — you're right, and I have to retract the root cause in the report.
The --single / 1.14.48 code path was a bad inference. I ran the same
nixpkgs 2.2.5 binary with a minimal config and it reads the exact file that
fails otherwise:
nixpkgs 2.2.5, minimal config -> SEE
nixpkgs 2.2.5, my config -> DECODE-FAILED
official 2.2.5, minimal config -> SEE
official 2.2.5, my config -> DECODE-FAILED
official 2.2.6, minimal config -> SEE
official 2.2.6, my config -> DECODE-FAILED
Same for the failing 480x500 PNG, and 2.2.6 behaves exactly as you predicted.
So the package build is fine, Photon does load, and this is not a Nixpkgs
bug — it is specific to my configuration. Sorry for the noise.
Artefacts you asked for, in a gist (GitHub gists refuse binary uploads, so the PNGs are base64):
https://gist.github.com/chgardener/577ce57e5ee238a7776d503826997f9b
t500.png.b64— the 480x500 PNG (17,799 bytes)t400.png.b64— the 480x400 crop of the same source (16,946 bytes), worksfail-run.json—opencode run --format jsontranscript of the failure: the tool part'soutputis"Image read successfully\n[1 image omitted: could not be decoded.]",metadata.truncatedisfalse, and no image part reaches the provider- versions: nixpkgs
opencode2.2.5, official v2.2.5 and v2.2.6, all x86_64-linux; a--print-logs --log-level debugrun produced no photon/worker/resize lines, only the omission in the tool output
What my config has that a minimal one does not: two local plugins
(Rehydra 0.16.0 — a redaction plugin
that hooks tool.execute.after and rewrites every string in a tool result —
and Hindsight 0.2.8) and five MCP servers. That is presumably why a
mock-provider reproduction without them passes.
Working hypothesis, consistent with your DecodeError explanation: the
redaction hook mutates the image payload before normalisation, Photon then
rejects the bytes, and the omission lands in the tool output. I have not
isolated it yet — my attempt to run with only one plugin at a time was
inconclusive because plugins appear to load from the default config directory
regardless of XDG_CONFIG_HOME.
Unless you want to keep it open for that finding, please close this as not a Nixpkgs bug. If I can produce a plugin-free reproduction I'll open a fresh issue with it.
Closing the loop: the local cause is isolated, and it is not nixpkgs. Retraction complete — please close this.
What it is. All plugin entries removed from my opencode.json (same nixpkgs 2.2.5 binary, same PNGs, only plugins changed, each run confirmed via the msg="loading plugin" log line):
| config | 480x400 PNG | 480x600 PNG |
|---|---|---|
plugins = [] |
renders | renders |
| Hindsight only | renders | renders |
| Rehydra 0.16.0 only | dropped | dropped |
| both (real config) | dropped | dropped |
Mechanism. read returns the image as an OpenCode V2 file part, {type:"file", uri:"data:image/png;base64,…", mime:"image/png"}. Rehydra's plugin hooks (tool.execute.after, and the request scrub of a tool-result part) pass every string of a tool result through its anonymizer. Its POSTAL_CODE recognizer matches digit runs inside the base64 and substitutes <PII type="POSTAL_CODE" id="…"/>, changing the bytes. Image.normalize runs after tool.execute.after, so Photon then fails to decode — hence [1 image omitted: could not be decoded.]. It looks pixel/size-dependent only because a longer base64 contains more digit runs (480x600 → 2 tags, 480x400 → 1 tag, a 176-char image → 0 tags and it renders). No secret values are involved: the repro below runs with envFiles: [].
Minimal repro (no opencode needed), fixture PNGs as base64 plus the script: https://gist.github.com/chgardener/e38b3b96c14859ce8193c64a123dd511
bun upstream-repro.mjs t600.png
{"uriRewritten":true,"tagsInserted":2,"bytesIdentical":false}
So the packaging theory was wrong on both counts: not the build (same binary passes with plugins = []) and not --single. The nixpkgs package is fine; I have reported the false-positive-in-base64 rewrite upstream.
Fix found, applied locally — closing this as not-a-nixpkgs-bug.
Cause was the Rehydra plugin in my OpenCode config, not the package. read hands the image to plugin hooks as {type:"file", uri:"data:image/png;base64,…", mime:"image/png"}; Rehydra's POSTAL_CODE recognizer matched digit runs inside the base64, substituted <PII/> tags and the payload stopped decoding. With plugins = [] the same nixpkgs binary renders every one of the test PNGs.
Local fix (the plugin wrapper now treats V2 file parts as opaque bytes and restores them by marker): commit 1cc1d6c1 in my flake, docs in docs/aspects/ops.md. Upstream report with a secret-free repro: rehydra-ai/rehydra-sdk#137.
Thanks for the pushback that led to the retraction — the package was never at fault.