Repository navigation
Description
Summary
On Cursor models whose id matches OpenCode's gpt-5* substitution rule, OpenCode advertises apply_patch and hides write/edit. When the model then emits a native write_args (or edit_tool_call) exec — which it does regardless of the advertised MCP set — this provider maps it to write, the catalog check rejects it as "unavailable for the current agent", and the model falls back to bash printf > file.txt. File creation/editing still works, but loses the write/edit permission flow, LSP diagnostics, and file-history tracking.
Repro
opencode run -m cursor/gpt-5.5-1m "Create a file named hello.txt with: hi from cursor"
With CURSOR_PROVIDER_DEBUG=1, the advertised tools for the turn are:
extractTools: 12 incoming → 12 advertised [apply_patch,bash,custom_websearch,glob,grep,jbcontext_code_search,jbcontext_find_repositories,read,skill,task,todowrite,webfetch]
No write, no edit. The model reads hello.txt (missing), then emits write_args. The exec is rejected and the model retries with bash (printf > hello.txt).
Root cause (provider side)
OpenCode's tool registry substitutes apply_patch for edit/write on gpt-5* model ids (excluding oss and gpt-4*) — this is host-side behavior in OpenCode core, not something the provider can override. The provider then has two mappings that both target the now-unadvertised write:
-
Exec path —
write_args/pi_write_args→toolName: "write"(src/protocol/tools.ts:289,293, parse at:845). The catalog check atsrc/language-model.ts:1605rejects it:OpenCode tool 'write' is unavailable for the current agent. ...(
src/language-model.ts:1610) -
Display bridge —
edit_tool_call→preferredToolName: "write"(src/protocol/tool-call-bridge.ts:202). The edit handshake first reads the target file;recoverMissingEditRead(src/language-model.ts:1121) is supposed to treat a missing-target read as an empty file so the model proceeds to the write step, but it bails early atsrc/language-model.ts:1129because!advertisedToolNameSet.has("write"). The read goes to OpenCode, fails, and the model abandons the edit path.
Net: both native file-write paths the model can emit are dead-ended when only apply_patch is advertised, and the model degrades to bash.
What I expected
Either (a) the provider recognizes apply_patch is the advertised file-edit tool and translates write_args/pi_edit_args into an apply_patch call (synthesizing the V4 patchText), or (b) the edit-handshake recovery accepts apply_patch as a valid write target so the model isn't forced to bash.
Open question — write_args.file_text on large files
While investigating the above, I noticed something I couldn't fully explain and would value your take on. When the model uses write_args on a large existing file, the file_text field arrives at ~50 KB regardless of original size:
| Original file | write_args frame (decoded) |
file_text length |
Result |
|---|---|---|---|
| 35.6 KB (1,200 lines) | 35,867 B | 35,605 B | intact (under cap) |
| 75.2 KB (2,520 lines) | 51,417 B | 51,144 B | truncated to 1,716 lines |
| ~540 KB (18,027 lines) | 51,429 B | 51,167 B | truncated to 1,486 lines |
Raw protobuf field walk of the 75 KB-case write_args frame showed exactly 3 fields (path, file_text, tool_call_id) — no blob_id or unknown field. The same Run stream carried KV set_blob_args frames with 125 KB / 108 KB / 103 KB of decoded data (full file content, 32-byte hash blob ids) around the same time.
I don't want to assert a cause — I couldn't determine whether the ~50 KB file_text is a Cursor server-side cap, an intended reference-only message the provider should resolve via the KV channel, a hand-written proto schema gap, or a frame-reassembly issue on this provider's side. Cursor's native client edits large files without corruption, so a hard cap on write_args seems unlikely by design. Flagging it in case you have visibility I don't.
Environment
- Provider:
cursor-opencode-provider@main(36a5952, v0.2.9) - Model:
cursor/gpt-5.5-1m
Activity
oakimov commentedon Jul 31, 2026
Both faults are fixed in #19 (draft) on branch
fix/18-apply-patch-and-read-cap. Summary of the diagnosis, since the second one turned out not to be what it looked like.Fault A — you were right, and the root cause is upstream
OpenCode 1.x doesn't merely add
apply_patchfor GPT models — it removeseditandwritefrom the catalog in exchange. FromToolRegistry.tools:It's a filter, not a rename, so the provider's fixed
write_args → writemapping resolved to a name that wasn't in the catalog and every write was refused. Confirmed live:cursor/gpt-5.4-miniadvertisesapply_patchand noedit/write, whilecursor/grok-4.5advertisesedit+writeand noapply_patch.The exclusivity is deliberate — a maintainer on opencode#34491 describes the gate as a "band-aid" whose purpose is that "GPT no longer receives edit + write + apply_patch simultaneously", and notes a plugin-side opt-out "isn't feasible today". opencode#19942 reported the same plugin-hostile behavior and was closed
not_planned. opencode#35408 (open) would move the policy into a hook with a mutable tool roster, at which point this shim can retire. OpenCode 2.0 has no such gate, so this is 1.x-only in practice.On your two proposed fixes: (b) alone is insufficient —
recoverMissingEditReadonly covers the read-before-write handshake, so the actualwrite_argsexecs would still be refused. (a) is the substantive one, and that's what's implemented. One correction: the rejection is atlanguage-model.ts:1620, not:1605.Fault B — the truncation is on the read, not the write
This is not a Cursor server-side cap. OpenCode's own read tool caps at
MAX_BYTES = 50 * 1024, cuts on a whole-line boundary, and appends(Output capped at 50 KB. Showing lines X-Y. Use offset=N to continue.). The provider strips that footer along with the read envelope — deliberately, so the model can't echo wrappers into a later write — which left the model believing a capped read was the complete file. It then rewrote the file from a partial view and everything past the cap was lost.That accounts for all three of your data points: 51,144 and 51,167 both sit just under 51,200 and differ because the line boundary lands differently per file, and the 35.6 KB file was under the cap so it survived. Cursor's own CLI uses the identical 50 KiB budget (
const io = 51200), which is why a server cap looked plausible — coincidence of constants, not causation. Its write executor applies no cap at all, exactly like ours; it just never truncates a read without saying so.Your field walk was also correct that only fields 1/2/3 were on the wire — but
agent.v1.WriteArgsactually has six, includingfile_bytes(#5). Cursor's executor prefers bytes when non-empty, so a byte-encoded write would have decoded as empty content here. Fixed too, though it's latent rather than something you hit.What changed
Native writes/edits are translated into
apply_patchenvelopes when — and only when — the host advertisesapply_patchand withholdsedit/write. And capped reads now say so: a[Partial read: …]marker on nativeread_result, a separate notice item onmcp_result, structuredtruncationon Pi reads. Deliberately paged reads are left alone.Worth flagging: the structured
truncatedflag was already being sent and made no difference. In a controlled A/B on a fixture where the marker is the only possible signal, gpt-5.4-mini said "highly confident" the partial content was the whole file with the marker off, and "confidence is low because the file output was truncated" with it on. grok-4.5 behaved the same way.One thing this does not fix
grok-4.5 writing a ~76 KB file in one call stalled and tripped the provider's own
Cursor semantic-progress timeout after 120000ms. No data loss — the file was left intact — but the write never landed. That looks like a separate fault and wants its own issue; please don't read #19 as proving large-file writes work end to end. Happy to open one if you've seen it too.oakimov commentedon Jul 31, 2026
@renaudcerrato — would you be willing to test this against your setup before I take #19 out of draft? You hit both faults on real usage and I'd rather not land it on my repro alone.
The branch is
fix/18-apply-patch-and-read-cap, cut from currentmain(v0.3.0 — you reported on36a5952/v0.2.9, so there are unrelated changes in between).Installing it
There's no
preparescript, so installing straight from the git URL won't builddist/. It needs a clone:Then point your host config at the built entry — for OpenCode, in
~/.config/opencode/opencode.json:{ "plugin": ["/abs/path/to/cursor-opencode-provider/dist/index.js"] }Fault A — your original repro
opencode run -m cursor/gpt-5.5-1m "Create a file named hello.txt with: hi from cursor"Expected: the file is created through
apply_patch, with nobash printffallback and no "unavailable for the current agent" rejection. If you setCURSOR_PROVIDER_DEBUG=1you should seetoolName=apply_patch resultField=write_result— thewrite_resultpart is what tells you it came from a nativewrite_argsand was translated, rather than the model callingopencode-apply_patchdirectly.Worth also trying an edit of an existing file, which takes the other path (substring →
*** Update File:widened to whole lines). That one refuses rather than guessing if the target text isn't unique, so if you see a refusal I'd like the message.Fault B — the ~50 KB truncation
bun -e 'await Bun.write("big.txt", Array.from({length:1200},(_,i)=>{const id=String(i+1).padStart(4,"0");return `LINE ${id} ${".".repeat(44)} KEEP${id}`}).join("\n")+"\n")'That's 1200 lines × 63 bytes = 76,800 bytes. Ask the model to read it in a single call with no offset/limit and report the last line it received, then whether it got the whole file.
Expected: it receives 800 lines (
LINE 0800 … KEEP0800— the cap lands there exactly for 63-byte lines) and says so, rather than claiming that's the end of the file. Then try a whole-file rewrite and checkwc -l big.txtis still 1200 andgrep -c KEEP1200is still 1.What I'd most value
gpt-5.5-1misn't a model I tested — I usedgpt-5.4-miniandgrok-4.5. The structuredtruncatedflag was already being sent before this change and both of those ignored it completely; only a marker in the content text moved them. If yours ignores the marker too, I want to know, because the fix is then incomplete rather than done.grok-4.5writing ~76 KB in one call tripped the provider's ownCursor semantic-progress timeout after 120000msfor me. No data loss, but the write never landed. That looks like a third, separate fault and I've deliberately not claimed it's fixed. If you've hit it I'll open a dedicated issue.file_byteson the wire?WriteArgsfield 5 is now decoded, but I've never observed Cursor populating it — your field walk showed only 1/2/3, same as mine. It's a schema-correctness fix, not a confirmed bug, and I'd be glad to hear if it ever fires for you.Full diagnosis and the A/B evidence are in #19. Thanks for the writeup on the original report — the field-number walk on
WriteArgsis what made the second fault tractable.fix: support apply_patch hosts and report opencode's 50 KB read cap (#18