opencode icon indicating copy to clipboard operation
opencode copied to clipboard

provider: treat tool_calls finish without calls as stop

Open ry2009 opened this issue 1 month ago • 6 comments

  • Treats finish_reason: "tool_calls" as stop when no tool-call deltas were seen (prevents hangs when providers return an empty tool_calls list).
  • Keeps tool-calls when actual tool-call chunks were emitted.
  • Added a regression test for the mapping.

ry2009 avatar Dec 05 '25 22:12 ry2009

I don't think this does what you think it does

rekram1-node avatar Dec 06 '25 20:12 rekram1-node

Are you solely doing this for codex models specifically through the github copilot subscription? It seems unlikely that is your intention given lack of description saying this much. But this change would ONLY affect those models.

rekram1-node avatar Dec 06 '25 20:12 rekram1-node

Yes, sorry I was more interested in making sure this fix works at the base level as this is a bigger abstraction:

I was curious how to continue if we want to add the same tool_calls into stop when no deltas mapping to the upstream @ai-sdk/openai-compatible path we use elsewhere (or wrap the finishReason after any OpenAI-compatible response).

Or we can PR change upstream to ai-sdk and remove the divergence in our fork so every OpenAI-compatible flow gets the fix.

ry2009 avatar Dec 06 '25 20:12 ry2009

what providerr were u seeing this issue w/?

rekram1-node avatar Dec 06 '25 20:12 rekram1-node

I saw it with LM Studio’s OpenAI‑compatible local server (model: qwen2.5‑coder‑7b‑instruct). It returned finish_reason:"tool_calls" but never streamed any tool_call deltas (tool_calls: []), so the mapper yielded unknown and the session waited forever. It isn’t a Copilot‑only problem; that’s just wherethe fork is.

ry2009 avatar Dec 08 '25 01:12 ry2009

Yeah this code wouldn't have done anything in that case then. we should fix this in processor.ts

rekram1-node avatar Dec 08 '25 01:12 rekram1-node

@ry2009 can you send me the session for this? opencode export > session.json

Because I think this may be a bug on LMStudio and they should fix it on their end

rekram1-node avatar Dec 08 '25 04:12 rekram1-node

session.json

Let me know if this loads or use the gist:

https://gist.github.com/ry2009/4559c3f9b4350a1bf4853cc20acd1993

ry2009 avatar Dec 08 '25 04:12 ry2009