Repository navigation
fix: agent turns end early on unoffered tool names and on long CUDA tool calls - #99
Closed
DevRico003 wants to merge 2 commits into
Closed
DevRico003 wants to merge 2 commits into
DevRico003 wants to merge 2 commits into
Conversation
…WN_TOOLS A well-formed call whose name the request did not offer stays text, so an agent harness sees prose and ends its turn. With the flag set, both the Mac lane parser and the CUDA parser return the call, the client answers "unknown tool", and the model corrects the name. Default behaviour is unchanged.
The CUDA server hides a tool call until it closes, so a reply that writes a large file in one call sends nothing for minutes. Clients with a read timeout drop the connection (Node's fetch does at 300 s), retry, regenerate the same tokens and fail again. An empty delta every 15 s while nothing visible is ready keeps the connection open; the reply is unchanged.
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two things end an agent's turn early when TensorFold serves a coding harness. Both showed up on one DGX Spark (GB10) running Qwen3.8-Flash-Next (MLX 4-bit + MTP, the MiaAI-Lab recipe) on TensorFold 0.3.6.3, driven by DeepSeek Harness (DSH Desktop 2.0.16) through the OpenAI chat API.
killwhere the request offersjob_kill). The parser keeps the whole block as content, so the harness sees prose, not a call, and ends the turn. A server that returns the call lets the harness answer "unknown tool" and the model corrects itself on the next step.writecall streams no bytes until the call closes. Node'sfetch(undici) drops a response body that is silent for 300 s, the harness retries, the same prompt regenerates the same tokens, and it fails again at the same place.This PR adds an opt-in flag for (1) and a keepalive for (2). References are at
main(1911880).1. Unoffered tool calls: opt-in pass-through
parse_tool_calls_from_content(src/tensorfold/server/tools.py:376-380) and the CUDA parser (src/tensorfold/cuda/reply_text.py:140) both keep a well-formed call to an unoffered name as text. That is deliberate since #51, and tests pin it (tests/test_deepseek_v4_prompts.py:65,tests/test_tool_draft.py:94), so the default does not change.With
TENSORFOLD_PASS_UNKNOWN_TOOLS=1(alsotrue,yes,on) both parsers return such a call as a tool call under the name the model wrote. Offered names keep their declared spelling. Malformed blocks stay text either way: no name, non-object arguments, unparsable JSON.max_callsstill takes the first call.The streaming
ToolCallStreameris unchanged: it still aborts on an unknown name and the end parser decides, which now returns the call when the flag is set.2. CUDA stream keepalive
App.runhides a tool call until it closes (src/tensorfold/cuda/server.py:302-304) and the handler emits calls only afterrunreturns (:532-535). In between,on_tokensemits only when there is visible text (:332).on_tokensnow emits an empty delta when nothing visible has been sent forKEEPALIVE_SECONDS(15 s). An emptydeltais a valid chat chunk that clients skip; for/v1/completionsit is an emptytext. The cancellation check runs as before, every round. Replies faster than 15 s between visible pieces stream exactly as before.Tests
tests/test_tool_call_unknown_name.py, parametrised over both parsers: an unoffered call stays text by default (including one with an unclosed<parameter>), reaches the client with the flag, offered names keep spelling and order next to an unknown one,max_calls=1takes the first, malformed blocks stay text with the flag.tests/test_cuda_stream_keepalive.py, on the fake CUDA engine fromtest_think_call.py: withKEEPALIVE_SECONDS = 0a hidden tool call streams empty deltas and still ends with the full call andfinish_reason: tool_calls; with the default a fast reply sends none.The new keepalive test fails on
mainand passes here. On macOS withoutmlx, the full suite gives the same 81 failures and collection errors onmainand on this branch (all from the missingmlx); nothing new fails. I could not run the MLX lane.On the GPU
One GB10, the MiaAI-Lab Qwen3.8-Flash-Next recipe with both changes applied to its image,
TENSORFOLD_PASS_UNKNOWN_TOOLS=1.Unknown names, API directly: a history where the assistant had already called
kill, the request offeringjob_killandbashor onlybash, 3 runs each, streamed and not:tool_callsmainReturning
Error: unknown tool 'kill'as the tool result, the next reply calledjob_kill.Keepalive, one
writecall of a 784-line file with thinking off: 108 s for the reply, longest gap between SSE lines 15.0 s, 7 empty deltas, the call arrived whole. Before, that was 108 s of silence.Keepalive in the harness: the same DSH session prompt (a self-playing voxel football match in one HTML file, effort max) on
mainfailed step 4 twice withterminatedat 423 s, each time 301 s after the last byte, while the model was writing a full-filewrite(29,774 output tokens). With this branch the same prompt ran 106 minutes to completion: 160 tool calls, six full-filewritecalls up to 62,810 characters, 0 transport retries.Not covered
ToolCallStreamerhas streamed a known call and the reply then calls an unknown one,server/http.py:354skips the end parser's calls because some were streamed, so the unknown call is dropped. That happens onmaintoo; this PR does not change it.