Unclosed </think> before tool call stalls agent session (finish=stop, no tool call delivered)
This project is amazing work, first of all- and has been my daily driver. Using the Q2 on a Mac Studio M4 Max 128 GB. But I have noticed this recurring issue:
#167 was closed (same issue) but the fix leaves sessions in a worse state than the original bug. When the model produces a DSML tool call without closing first, the server now logs "thinking not closed, ignoring DSML in reasoning" and returns finish=stop with no tool calls and no useful text. Opencode and pi both just stop and sit there until I nudge it. Typically I explain the tool call failed and to try again- or run the command myself. Not ideal.
Here's a log snip from a session:
ds4-server: thinking not closed, ignoring DSML in reasoning 0531 21:29:28 ds4-server: chat ctx=104990..105039:49 gen=80 TOOLS THINKING finish=stop 4.779s
Opencode shows that the model intended the tool call. (I have not seen a model "thinking about tool calling" and generating the tool token sequence. That seems very unlikely.) Most probable is that it just dropped the closing tag. The fix seems like: when is absent but DSML is present, treat the DSML start as an implicit whoopsie thinking boundary instead of discarding the call. Pre-DSML text becomes reasoning, DSML parses normally.
I checked open PRs and PR #273 does fix this but bundles a lot of other stuff (ASCII DSML variants, tool result reordering, argument unwrapping... none of which I have issues with personally). I made a fork with a targeted change and it's about 20 lines in parse_generated_message_ex. I'm can send the PR if that sounds good.
Thanks
i can confirm, same issue:
0601 13:52:59 ds4-server: chat ctx=67493..67541:48 gen=98 TOOLS THINKING decoding chunk=19.95 t/s avg=19.69 t/s 4.978s
ds4-server: thinking not closed, ignoring DSML in reasoning
0601 13:52:59 ds4-server: chat ctx=67383..67443:60 gen=98 TOOLS THINKING finish=stop 5.834s
0601 13:53:05 ds4-server: live kv cache miss live=67541 prompt=67445 common=67441 reason=token-mismatch
When I use the pi agent with the ds4-server, it often occurs
0602 11:10:40 ds4-server: chat ctx=11874..11897:23 TOOLS prefill chunk 0/23 (0.0%) chunk=0.00 t/s avg=0.00 t/s 0.000s
0602 11:10:41 ds4-server: chat ctx=11874..11897:23 TOOLS prefill chunk 23/23 (100.0%) chunk=64.63 t/s avg=64.62 t/s 0.356s
0602 11:10:41 ds4-server: chat ctx=11874..11897:23 TOOLS prompt done 0.356s
0602 11:10:43 ds4-server: chat ctx=11897..11947:50 gen=50 TOOLS THINKING decoding chunk=25.46 t/s avg=25.46 t/s 1.964s
0602 11:10:44 ds4-server: chat ctx=11947..11974:27 gen=77 TOOLS THINKING decoding chunk=25.47 t/s avg=25.46 t/s 3.024s
ds4-server: thinking not closed, ignoring DSML in reasoning
0602 11:10:44 ds4-server: chat ctx=11874..11897:23 gen=77 TOOLS THINKING finish=stop 3.380s
0602 11:11:11 ds4-server: live kv cache miss live=11974 prompt=11917 common=11895 reason=token-mismatch```
I ran into this problem using OpenCode several times today.
Currently I am testing your fix -> https://github.com/TipKnuckle/ds4/tree/fix/implicit-think-close-on-dsml and it seems to work fine so far. I'd recommend others to test it too and see if this fixes this problem/bug.
Update: After >2h using this fix this Unclosed /think problem has not reappeared, I consider this a much needed bugfix that should get merged ASAP.
I'm trying to handle it with 91bafb5a since I believe it is better if we have a minimal fix that let the model recover. This is handled in a different way in ds4-agent, that is, often the harness emits an error, sometimes it tolerates not finding the opening DSML stanza, but there we don't have prefix reconciliation issues in the next turns, and the ways the model can fail emitting the proper DSML are varying. So the idea here is to let the model recover as it wishes, and apparently it works well. This should also avoid any prefix matching issue later when the tool call is converted back into the prefix.
Another "Q2 on a Mac Studio M4 Max 128 GB" user here. Have been using it with VS Code and found this issue after I had VS Code stop mid-session with:
...and finding the "ds4-server: thinking not closed, ignoring DSML in reasoning" message on the DS4 console.
I installed the latest main version including the new commit, and now the reaction of VS Code is to show this:
And this is what the DS4 log shows:
I think this is what you were hoping to achieve, right? At least VS Code doesn't stop there anymore and continues on its own. Can't tell yet whether it will eventually succeed, because it's incredibly slow overall, has been working on this medium task for 10+ hours now and still continues. I hope it's only a misconfiguration on my side, this project looks really promising, thanks for your work (and the latest fix!)
Indeed @YorVeX we now display whatever the model sampled, and then the model can recover. However I see from the logs that your computer is not actually so slow executing the model itself, maybe the request goes often outside the cache, I would try ds4-agent that is the built-in agent that does not have prefix-matching issues and will never stop pre-processing the history to see the actual maximum performance available. Thanks for the feedback.
0611 07:36:42 ds4-server: chat ctx=65996..66017:21 TOOLS tool call inside unclosed
thanks @antirez , you fixed it :-)
Indeed @YorVeX we now display whatever the model sampled, and then the model can recover. However I see from the logs that your computer is not actually so slow executing the model itself, maybe the request goes often outside the cache, I would try
ds4-agentthat is the built-in agent that does not have prefix-matching issues and will never stop pre-processing the history to see the actual maximum performance available. Thanks for the feedback.
Thanks, will check ds4-agent! I was really surprised, especially when Qwen 3.7 35B A3B Q4 on my Windows PC GPU would show 10-15 t/s (as opposed to the ~20 I get in ds4, though prefill there is 3000 vs. 500), but was much faster in VS Code (compared by giving it the same task).
Anyway, in the meantime it finished and looks good. I can see that it noticed previous errors, retried and succeeded, so at least with VS Code I can report that it goes to plan, instead of breaking the autonomous flow it can continue on its own, sweet! Will also play with it a bit in Agent Zero, at first glance it seems to work with the model more effectively.
Bit of a shame that this otherwise neat model seems to mess up closing tags (or JSON syntax in general?) quite frequently, it also happens with the cloud hosted versions of both Flash and Pro, so I know it's not DS4 or the quant we're using here.