Skip to content

fix: return images read on a held Run as ReadSuccess.data - #42

Merged
oakimov merged 4 commits into
oakimov:mainfrom
nkoynov:fix/read-image-results
Oct 8, 2026
Merged

oakimov merged 4 commits into
oakimov:mainfrom
nkoynov:fix/read-image-results

Conversation

@nkoynov

@nkoynov nkoynov commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

When the model reads an image with OpenCode's read tool, OpenCode answers with "Image read successfully" and moves the image into a trailing Attached media from tool result: user message (third-party providers are not on its media-in-tool-result allowlist). The provider skipped that message for liveTail and encoded the read as text, so the model saw only the placeholder on that turn.

Cursor's own read executor answers an image file with bytes in ReadSuccess.data (#5) and no text (LocalReadExecutor in the Cursor CLI local unpack). This PR does the same on held-Run continuations.

Changes

  • Attribute trailing caption media (and in-result media parts) in result order; keep <system-update> append and <system-reminder> skip
  • Decode with existing image-input helpers (url as well as data for OpenCode 1); gate on session.supportsImages
  • Encode successful read_result with data, total_lines: 0, file_size from bytes when path stat fails
  • Record delivered image hashes only after a successful held-Run write
  • Docs: GenerateImage reference_image_paths use the same ReadSuccess.data path; no CLI resize (20 MiB decode budget); PDF not delivered; cursor_image_save / write path unchanged

Dependency note

GenerateImage output write / cursor_image_save is independent. This PR only unlocks reference reads via ReadSuccess.data. No image-save code changes.

Stacked: #46 builds on this.

Tests

  • tools.test.ts, image-input.test.ts (OC1 data-URL + OC2 base64), continuation-session.test.ts (attribution, plan-reminder+caption, delivery, hash-after-success)
  • bun test / typecheck / build / architecture gate green

Live A/B + cache (quality bar)

Host Result
OpenCode 1.18.35 Pass — continuation: 1 tool-result image(s) on read_result; prompt "open shot.png…"
OpenCode 2.0.24 Pass — same debug line; model reported seeing pixels
Warm cache Pass — second turn continuity=warm, ~99% rawReadVsPriorContext on both hosts
GenerateImage + one reference_image_paths Pass on OC1 (muse-spark-1.3) — ref read via read_result image path, then existing cursor_image_save landed output

Method: automated opencode run against local dist/ (not interactive TTY). Image-save untouched.

CONTRIBUTING checklist

  • OpenCode 1.x verified (not OC2-only)
  • OpenCode 2.0 verified
  • Prompt-cache warm confirmation (docs/cache-log-runbook.md)
  • CHANGELOG [Unreleased] Fixed + credit @nkoynov

@oakimov

oakimov commented Oct 7, 2026

Copy link
Copy Markdown
Owner

CONTRIBUTING checklist

Per CONTRIBUTING.md, please add:

  • OpenCode 1.x — verify on classic/1.x as well, or state explicitly that this bug is OpenCode 2.0-only.
  • Prompt-cache confirmation — confirm RequestContext / checkpoint continuity stays warm (cache diagnosis: / docs/cache-log-runbook.md).

Live before/after and CHANGELOG look good.

@nkoynov

nkoynov commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Closing per the new contribution policy. This fix and the others we had open are maintained in our fork: https://github.com/nkoynov/cursor-opencode-provider

@nkoynov nkoynov closed this Oct 7, 2026
@oakimov oakimov reopened this Oct 7, 2026
@oakimov

oakimov commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

Reopening to land a quality-standard rebase onto current main (OpenCode 1.x + 2.0 live A/B, prompt-cache confirmation, host-note merge).

When the model reads an image with OpenCode's `read` tool, OpenCode
answers with "Image read successfully" and moves the image into a
trailing `Attached media from tool result:` user message (third-party
providers are not on its media-in-tool-result allowlist). The provider
skipped that message when locating the live tool results and encoded the
read as text, so the model got only the placeholder and saw the image,
if at all, as a history image on the next user turn. Models then guessed
or fell back to decoding the file in the shell.

Cursor's own read executor answers an image file with its bytes in
`ReadSuccess.data` (oakimov#5, already declared in messages.ts) and no text.
Do the same on held-Run continuations: keep the media parts of the
trailing message (and a result's own `file-data` parts) and attribute
them in result order. One result takes all of them; with several, each
media read ("Image read successfully") takes one part, results OpenCode
replaced with "Media attached in the following user message." take the
rest, and media no placeholder settles rides on the last result, as host
notes already do. Decode them with the existing image-input helpers and
encode a successful `read_result` with `data` instead of `content`.
Delivered images are added to the session's sent history-image hashes so
the next fresh Run does not attach them again. Results without an image
field keep the existing history path; models without image support are
unchanged.
@oakimov
oakimov force-pushed the fix/read-image-results branch from 69ba35e to 37a7810 Compare October 7, 2026 23:28
@oakimov

oakimov commented Oct 8, 2026

Copy link
Copy Markdown
Owner

CONTRIBUTING checklist (tip 37a7810):

  • OpenCode 1.x verified (not OC2-only)
  • OpenCode 2.0 verified
  • Prompt-cache warm confirmation (docs/cache-log-runbook.md)
  • CHANGELOG [Unreleased] Fixed + credit @nkoynov

Live A/B: OC1.18.35 + OC2.0.24 pass (read_result image path); warm cache ~99% rawReadVsPriorContext; GenerateImage + one reference_image_paths pass on OC1 (muse-spark-1.3). Image-save path unchanged.

@oakimov
oakimov merged commit 909a0bf into oakimov:main Oct 8, 2026
1 check passed
nkoynov added a commit to nkoynov/cursor-opencode-provider that referenced this pull request Oct 8, 2026
Fork main moved past b88509f while the upstream sync was prepared: CP-39's
early tool rows (46b51e7, 200f132, 04ab323, 9ed6eff).

The tool-call id of an early row now resolves in correlateToolResults,
where the merged oakimov#42 code correlates results after attributing detached
media. Its CHANGELOG entry goes under [Unreleased].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants