Chat: the two-command limit counts loops and chains, and incomplete tools get error results when a reply stops #5

Merged
kubus merged 3 commits from t3/stop-task-incomplete-tools into main 2026-10-13 00:31:25 +00:00
Owner

Summary

  • Renamed MAX_CHAT_CHANGES to MAX_CHAT_COMMANDS and updated the limit logic to count individual commands within chained calls
  • Added commands property to PluginTool to allow plugins to declare how many commands a single tool invocation runs (chains count per part, loops count as infinity)
  • Implemented commandCount() in ssh policy to analyze shell commands: splits on ;, &&, ||; returns infinity for loops (for/while/until), xargs, parallel, or find -exec
  • Added answered() function to fill missing tool results when a reply stops mid-execution: unanswered tool calls get error results with message "Stopped before this finished; it may or may not have run."
  • Updated prompt documentation: command counting includes chained parts and loops; chart blocks no longer repeat their values in text
  • Updated error message to reference commands rather than changes, and clarify the limit behavior

Testing

  • New test: "a reply runs at most two commands itself; a third is sent to run_task" — verifies two single commands run, third is rejected
  • New test: "commands chained into one call count one by one" — verifies three commands in one tool call are rejected as exceeding limit
  • New test: "a shell line counts each chained part, and a loop as many" — unit tests for commandCount() covering pipes, chains, and loops
  • New test: "tool calls a stop cut off get a result, so the next message still goes through" — verifies missing tool results are filled with error results before the next message is sent to the model
  • Updated test message assertion to match new error text ("Start run_task for the work")
## Summary - Renamed `MAX_CHAT_CHANGES` to `MAX_CHAT_COMMANDS` and updated the limit logic to count individual commands within chained calls - Added `commands` property to `PluginTool` to allow plugins to declare how many commands a single tool invocation runs (chains count per part, loops count as infinity) - Implemented `commandCount()` in ssh policy to analyze shell commands: splits on `;`, `&&`, `||`; returns infinity for loops (`for`/`while`/`until`), `xargs`, `parallel`, or `find -exec` - Added `answered()` function to fill missing tool results when a reply stops mid-execution: unanswered tool calls get error results with message "Stopped before this finished; it may or may not have run." - Updated prompt documentation: command counting includes chained parts and loops; chart blocks no longer repeat their values in text - Updated error message to reference commands rather than changes, and clarify the limit behavior ## Testing - New test: "a reply runs at most two commands itself; a third is sent to run_task" — verifies two single commands run, third is rejected - New test: "commands chained into one call count one by one" — verifies three commands in one tool call are rejected as exceeding limit - New test: "a shell line counts each chained part, and a loop as many" — unit tests for `commandCount()` covering pipes, chains, and loops - New test: "tool calls a stop cut off get a result, so the next message still goes through" — verifies missing tool results are filled with error results before the next message is sent to the model - Updated test message assertion to match new error text ("Start run_task for the work")
Stopping a reply while its tools ran left their tool_use blocks without
tool_results, and the API rejected every later message in the episode.
Loading the turns now fills in an error result for each unanswered call,
which also mends episodes already stuck this way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One ssh_exec or ssh_pct_exec call counted as one change however much it ran,
so a for loop over every container fit in a single reply. Plugin tools can now
say how many commands a call runs; the SSH tools count each part between ;,
&& and ||, and a loop, xargs or find -exec as any number. The prompt says a
check across several hosts or containers is a task from the start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kubus merged commit 70dbb3fca9 into main 2026-10-13 00:31:25 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
kubus/hatbot!5
No description provided.