Skip to content

fix(terminal): guard invalid command values - #6417

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-1fa6ad8f
Apr 9, 2026
Merged

fix(terminal): guard invalid command values#6417
teknium1 merged 1 commit into
mainfrom
hermes/hermes-1fa6ad8f

Conversation

@teknium1

@teknium1 teknium1 commented Apr 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

Salvage of #6371 by @helix4u — cherry-picked onto current main.

Prevents the terminal tool from double-faulting when an invalid command value reaches execution. When the model sends command: null (or omits the key), the agent crashed in two cascading places:

  1. _transform_sudo_command() called re.search(..., command) on None → TypeError
  2. The retry/error logging tried command[:200] on None → second TypeError, killing the error handler

This caused the agent to stop working suddenly with no recovery.

Changes

  • Guard non-string command values at the start of terminal_tool() — returns clean error JSON
  • Add _safe_command_preview() helper so retry/error logging never assumes a sliceable string
  • Make _transform_sudo_command() return cleanly for None
  • Regression tests in tests/tools/test_terminal_none_command_guard.py

Test results

  • All 47 terminal tool tests pass (45 existing + 2 new)
  • E2E verified: terminal_tool(None) returns clean error, normal commands unaffected

Credit to @helix4u for the fix.

@teknium1
teknium1 merged commit e94008c into main Apr 9, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants