Repository navigation
feat(opencode): attach prompt images in agent sessions - #4922
Merged
Merged
Conversation
This was referenced Oct 22, 2026
ananthsub
force-pushed
the
ananthsub/opencode-session-images
branch
from
October 22, 2026 14:33
ee4fdd0 to
bc4afe4
Compare
ananthsub
changed the base branch from
main
to
ananthsub/sandbox-spec-file-bytes
October 22, 2026 14:33
This was referenced Oct 27, 2026
7 tasks done
yfw
pushed a commit
that referenced
this pull request
Nov 6, 2026
The opencode_agent session path rejected any input_image part with a 422, and its model entry declared no image input. OpenCode omits every image from model requests for a model without image input, including images its read tool returns, while still reporting the read as successful. A session now accepts base64 data-URI input_image parts in the user task. The adapter decodes them with nemo_gym.media_utils, uploads them into the session directory, and passes each one to `opencode run --file`. The session model entry declares image input, so images the read tool returns reach the model. Media outside the user task and image URLs are still rejected with a 422. Ported onto main 792fa14 for the Agentic-MME stack (#5720): main's session input now also takes request sampling, and test_unset_extensions_keep_setup_activation_and_capture_unchanged now expects the image options in the model entry. The #4922 test reads the staged activation through params(). Signed-off-by: Ananth Subramaniam <[email protected]> Signed-off-by: Yi-Fu Wu <[email protected]>
yfw
reviewed
Nov 6, 2026
7 tasks done
ananthsub
force-pushed
the
ananthsub/sandbox-spec-file-bytes
branch
from
November 9, 2026 20:50
4c78c92 to
b8fa950
Compare
ananthsub
force-pushed
the
ananthsub/opencode-session-images
branch
from
November 9, 2026 20:52
6664177 to
aa7838b
Compare
yaoyu-33
reviewed
Nov 9, 2026
ananthsub
force-pushed
the
ananthsub/opencode-session-images
branch
from
November 9, 2026 23:13
20d45f3 to
5a274aa
Compare
The opencode_agent session path rejected any input_image part with a 422, and its model entry declared no image input. OpenCode omits every image from model requests for a model without image input, including images its read tool returns, while still reporting the read as successful. A session now accepts base64 data-URI input_image parts in the user task. The adapter decodes them with nemo_gym.core.split_text_and_media, uploads them into the session directory with nemo_gym.sandbox.upload_media within the activation's budget, and passes each one to `opencode run --file`. The session model entry declares image input, so images the read tool returns reach the model. Media outside the user task and image URLs are still rejected with a 422. Signed-off-by: Ananth Subramaniam <[email protected]>
Each request's images are now base64-decoded once. A continuation activation reuses the input that validation already parsed, and a retried single activation is compared with the stored request without parsing it again. Prompt images are uploaded to <session_dir>/input-media. The extra activation segment was "None" outside continuation sessions, and the path reaches the model through OpenCode's read-tool text. The model entry now declares only modalities. OpenCode 1.17.11 never reads the model attachment key on the request path; modalities.input alone lets images through, and without it OpenCode replaces each image with an error text. The rejection test now sends valid image parts, so the adapter's own checks reject them instead of request validation, and it asserts the adapter's message. New tests cover image order and exact paths, an image without text, the continuation path, decoding once, and the upload spending a continuation activation's budget. Signed-off-by: Ananth Subramaniam <[email protected]>
OpenCode tells the model each attached file's path, and the path held the session's random directory, so the prompt differed on every rollout of the same task. Images now go to /tmp/nemo-gym-media/<sha256>.<ext> through nemo_gym.sandbox.stage_media, which uploads each distinct image once and renames it into place atomically, so sessions sharing a sandbox never read a partly written file. Staging now runs in stage_activation, inside the session's execute, so session close cancels an image upload before it releases the sandbox. stage_activation appends the --file arguments from the paths stage_media returns, so each image is hashed once. Tests cover the content-named paths and close cancelling a stalled image upload before the sandbox is released. Signed-off-by: Ananth Subramaniam <[email protected]>
Follow #4917's staging changes: the fake sandbox now renames files with the separate mv -fT command. A new test checks that a provider timeout or a refused rename while staging images fails the activation as a server error rather than ending it incomplete. The README now limits the claim that a timeout before launch leaves the session usable to the activation's own budget. Signed-off-by: Ananth Subramaniam <[email protected]>
A first activation passed no deadline, so staging its files, prompt images included, could hold a concurrency slot until the session closed. Its budget now starts once it holds a slot, as Pi's does: staging spends it, OpenCode runs for the rest, and a budget that runs out before launch fails the activation. Signed-off-by: Ananth Subramaniam <[email protected]>
#4917 now checks for a directory at each target path and renames with plain mv -f, since BSD mv has no -T. The fake sandbox and the refused-rename test match that command. Signed-off-by: Ananth Subramaniam <[email protected]>
…figured Sessions declared image input on every model call. OpenCode then sends the model any image its tools return, so on a text-only deployment a task whose sandbox holds an image failed where the model used to get OpenCode's error text. A session now declares image input when the prompt has images or when the new image_input setting is on, matching the Pi agent's setting. Once an activation declares it, later activations of the session keep it, because OpenCode resends earlier images with the history. Set image_input for a vision model whose tasks keep their images in the sandbox, where the prompt has none. Signed-off-by: Ananth Subramaniam <[email protected]>
OpenCode 1.17.11 shrinks or re-encodes any image over 2000 px on a side or 5 MiB of base64, so the model could get different bytes than the row holds. A session that declares image input now lifts these limits, as opencode_sandboxed_agent does, so the model gets each image's own bytes. Session opencode_config now accepts attachment, so a run on an endpoint with image limits can restore them. Signed-off-by: Ananth Subramaniam <[email protected]>
yfw
approved these changes
Nov 10, 2026
This was referenced Nov 11, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Where this sits
Arrows point from each PR to its base. #4917 has merged into
main, so #4922 and #4923 are based onmainand can merge in either order. yfw's #5719 is stacked on #4922.What changed
opencode_agentsandbox sessions now pass prompt images to OpenCode. When a session declares image input, OpenCode also passes images it reads in the sandbox to the model.input_imageparts in the user task, alongside nonempty text. Insidestage_activation, the adapter writes each image to/tmp/nemo-gym-media/<sha256>.<ext>withnemo_gym.sandbox.stage_mediaand adds--file <path>toopencode run, which attaches it to the first message, before the task text.modalities.input: ["text", "image"]) when the prompt has images or when the newimage_inputsetting is true, the same setting the Pi agent has (feat(pi): attach prompt images in agent sessions #4923). Once an activation declares it, later activations of the session keep it, because OpenCode resends earlier images with the session history. Without that declaration OpenCode 1.17.11 replaces every image in its model requests, including images itsreadtool returns, with an error text telling the model it cannot read images. OpenCode 1.17.11 never reads the modelattachmentkey, so the entry does not set it.attachment.image), asopencode_sandboxed_agentdoes. Otherwise OpenCode shrinks or re-encodes any image over 2000 px on a side or 5 MiB of base64, so the model would get different bytes than the row holds. Sessionopencode_confignow acceptsattachment, so a run on an endpoint with image limits can restore them.stage_mediauploads each distinct image once and renames it into place atomically, so sessions sharing a sandbox never read a partly written file.main,stage_activationstages, in order: the session instructions, the task-environment plugin for a continuation, the MCP plugin and grant files when the session grants MCP tools, the prompt, the images, and then the runner parameters.nemo_gym.core.split_text_and_mediaand staging usesnemo_gym.sandbox.stage_media, both from feat: binary sandbox files and shared media helpers #4917, now onmain.The legacy
opencode_sandboxed_agentand the local/runpath are unchanged.Why
Multimodal tasks put images in the prompt as
input_imageparts, and the session path rejected them outright. A text-only declaration also hid images from the model whenever OpenCode opened an image file during a task, with nothing in the trajectory showing the image was dropped.No issue: this is one harness's part of multimodal support, and the change is self-contained. The Pi session change (#4923) is a sibling PR on the same base.
Compatibility
image_inputdefaults to false, so a session without prompt images behaves as before on a text-only deployment: OpenCode replaces an image it reads with its error text. A session with prompt images, or withimage_input: true, also sends images its tools return, which a text-only deployment rejects. Setimage_input: truefor a vision model whose tasks keep their images in the sandbox, where the prompt has none. A session that declares image input sends images over 2000 px on a side or 5 MiB of base64 unchanged, so an endpoint with image limits may reject one; setattachmentinopencode_configto restore OpenCode's resizing.In a borrowed sandbox, prompt images remain under
/tmp/nemo-gym-mediaafter the session closes, because another session may be reading the same file. They are bounded by the number of distinct images. A sandbox that isolates its/tmpdrops them when it is destroyed; the local provider, and Apptainer without--contain, share the host's/tmp, where they stay until the host clears it.A first activation's OpenCode run now gets its budget minus the time spent staging, rather than the whole budget, and a budget that runs out before launch fails the activation.
Validation
49324d1a20):pytest -n 16 responses_api_agents/opencode_agent/tests tests/unit_tests/sandbox/test_sandbox_media.py tests/unit_tests/core/test_media.pypassed.--filein order, decoded once even when the request is retried, and declared on the model entry;image_inputis true, and in a continuation session a prompt image keeps the declaration for the next activation;attachmentsetting replaces them;stage_activationfails the close test. Treating a provider error while staging like the activation's own deadline fails the staging-error test. Without the first-activation budget, the stalled-upload test waits for the whole upload and fails. Dropping the declaration in a later activation fails the continuation declaration test. Lifting the image limits for every session, or rejectingattachmentinopencode_config, fails the image-limit tests.pre-commit run --files <changed files>passed.Rollout evidence
The latest run used
6664177f9f. Since then, the base moved tomainwith #4917 merged, and this branch added three changes: a first activation's budget now bounds its staging, image input is declared only for prompt images orimage_input, and declaring it lifts OpenCode's image limits. The prompt-image tasks still declare it, and their images are 768 by 768 px, under OpenCode's limits, so the run covers them; the image staging and attachment code is otherwise the same. #4917 has since replacedmv -fTwith a directory check and plainmv -f, because BSDmvhas no-T, so the run exercised the earlier rename. #4917 was rebased ontomain, which brought in #4934's transfer telemetry and #5862's MCP staging instage_activation. The smoke tasks grant no MCP tools, so the run does not exercise #5862's staging.The run used Qwen3-VL-30B-A3B-Instruct on vLLM 0.29.0 (default sampling) and OpenCode 1.17.11 in Docker sandboxes.
single_agent_turn_legacydrove it so each row runs as an agent session, andmcqagraded it (ten options, so a model that cannot see the image scores about 10% by guessing). The dataset has five image questions (color, shape, number, dot count and word) plus a text-only control.opencode run --fileat/tmp/nemo-gym-media/<sha256>.png. The five paths match the run on7255d05066, so the prompt does not change between rollouts, and feat: binary sandbox files and shared media helpers #4917's staging at that time (directory creation, readable partial files,mv -fT) worked in Docker sandboxes.Earlier runs:
7255d05066scored 5 of 6 on the same prompt images, missing only the dot count.bc4afe4b15, from before the package reorganization, scored 5 of 6 on prompt images. On images OpenCode opened with itsreadtool, it answered 8 of the 10 rows where the model calledread, over three runs; those sessions always declared image input, which now takesimage_input: true. In the same tasks throughopencode_sandboxed_agent, which does not declare image input, only the text control was correct.