Skip to content

fix(provider): note file/dir @-mentions as text instead of failing the turn#58

Merged
justin-carper merged 3 commits into
mainfrom
fix-opencode-references
Jul 6, 2026
Merged

fix(provider): note file/dir @-mentions as text instead of failing the turn#58
justin-carper merged 3 commits into
mainfrom
fix-opencode-references

Conversation

@justin-carper

Copy link
Copy Markdown
Collaborator

Problem

Including a non-text @-mention in an opencode prompt — an image, PDF, or directory — fails the whole turn with:

Cursor run ended with status "error"

Root cause

Non-text @-mentions reach the provider as AI-SDK file parts (data = a file:// URL or data: URI). The provider tried to forward them via SDKUserMessage.images, but the Cursor local SDK agent — the only backend the chat path uses — rejects attachments in every form:

  • { url } images → ConfigurationError: URL images are only supported for cloud SDK agents
  • { data, mimeType } inline base64 images → run ends status:"error" with an empty result → the exact user-facing error

Isolated at the raw @cursor/sdk level and reproduced across the default model and a vision model (claude-sonnet-5) — text-only turns succeed, any attachment fails. (text/plain and directory mentions that opencode inlines upstream were never affected.)

Fix

Stop attaching file parts. Route every non-text file part (images, PDFs, directories, other media) through a text note — [attached file: <name> (<mime>) — not forwarded to Cursor] — in both promptToCursorMessage and latestUserMessage (fresh + resumed pooled turns). The run always completes; the agent learns a file was referenced and can inspect it with its own workspace tools.

Note: attachments still aren't seen natively (the local agent has no attachment/vision channel), but the turn no longer errors.

Verification

  • Unit tests: 226 pass; tsc --noEmit clean; build succeeds
  • Live repro against the rebuilt provider — all status=finished err=none:
    • image via file:// URL (object + string)
    • PDF via file:// URL
    • directory via file:// URL (object + string)

All previously errored with status="error".

…e turn

The local Cursor SDK agent (the only backend the chat path uses) cannot
accept attachments in any form: `{url}` images throw "URL images are only
supported for cloud SDK agents", and inline `{data,mimeType}` base64 images
end the run with an empty `status:"error"` — surfacing to users as
"Cursor run ended with status error" on an `@image` or `@directory` mention.

Stop attaching file parts via SDKUserMessage.images. Route every non-text
file part (images, PDFs, directories, other media) through a text note so
the run always completes and the agent still learns a file was referenced.
Applies to both promptToCursorMessage and latestUserMessage (fresh + resumed
turns). Text/plain and directory mentions that opencode inlines upstream are
unaffected.
Add explicit unit tests for application/x-directory file parts (the case
that regressed) in both promptToCursorMessage and latestUserMessage, and a
test asserting the note falls back to the source file URL when a file part
has no filename (exercises describeSource).
describeSource returned any non-data: string verbatim, so a raw base64
file part with no filename inlined the whole blob into the note text.
Now only URL-shaped strings are used as names; everything else falls
back to "file". file:// sources are emitted as filesystem paths (via
fileURLToPath, href fallback on invalid URLs) since the local agent's
workspace tools act on paths.
@justin-carper justin-carper merged commit 0bca2ca into main Jul 6, 2026
6 checks passed
@justin-carper justin-carper deleted the fix-opencode-references branch July 6, 2026 20:32
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.

1 participant