Fail turns whose model text looks like an unparsed tool call - #119
Merged
Merged
Conversation
A model with unreliable tool-calling (observed with a small local Ollama model) can emit a JSON-ish blob naming a real tool as plain assistant text instead of a real structured tool call. Since `last.tool_calls` is empty, the turn fell through to `TaskExpectation::ReadOnly`, which completes on any non-empty final text — reporting "Completed" while no file was actually touched. Detect this case in `apply_model_response` before it reaches the evaluator: if the turn issued zero real tool calls and the final text contains a registered tool name in call-shaped syntax (a quoted name immediately followed by `:` or `,`), fail the turn explicitly instead. The detection lives in lib.rs rather than completion.rs, since that module is documented to have no dependency on the model's own text. Adds `CompletionReason::DanglingToolCallText` and two regression tests: the false-completion repro, and a false-positive guard for prose that merely mentions a tool name in a sentence.
3 tasks
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
qwen2.5-coder:3b) can emit a JSON-ish blob naming a real tool as plain assistant text instead of a real structured tool call. Sincelast.tool_callswas empty, the turn fell through toTaskExpectation::ReadOnly, which completes on any non-empty final text — the header reported✓ Completedwhile the target file was never touched.apply_model_responsenow detects this case before evaluation: if the turn issued zero real tool calls and the final text contains a registered tool name in call-shaped syntax (a quoted tool name immediately followed by:or,), the turn fails explicitly withCompletionReason::DanglingToolCallTextinstead of silently completing. The detection is deliberately conservative (ordinary prose that just mentions a tool name does not match) and lives inlib.rsrather thancompletion.rs, since that module documents itself as having no dependency on the model's own text.CompletionReasonmatch arms were needed elsewhere — the TUI already humanizes unknown failure categories generically (dangling_tool_call_text→ "Dangling tool call text"), confirmed live.Test plan
cargo test --package forge-core— 128/128, including two new regression tests:dangling_tool_call_text_does_not_complete(the repro) andprose_mentioning_a_tool_name_still_completes(false-positive guard).cargo fmt --all -- --check,cargo clippy --workspace --all-targets --locked -- -D warnings,cargo test --workspace --all-targets --locked— all clean.qwen2.5-coder:3b: header changed from✓ Completedto✗ Failed · Dangling tool call text, target file confirmed byte-for-byte unchanged on disk both before and after.