feat(terminal): hint at structured tools when bash fails to parse a command - #25862
Open
sparkeros wants to merge 1 commit into
Open
feat(terminal): hint at structured tools when bash fails to parse a command#25862sparkeros wants to merge 1 commit into
sparkeros wants to merge 1 commit into
Conversation
When bash fails to parse a command — almost always an unclosed quote
in a curl payload, e.g. an apostrophe inside a single-quoted JSON body
like `-d '{"body":"It's done"}'` — it exits 2 with a recognizable
message in stdout. Today the model just sees:
/usr/bin/bash: eval: line 3: unexpected EOF while looking for matching ''
and frequently retries the same broken quoting. Add a detector that
catches the parser-error markers (with returncode==2) and attaches an
actionable `_hint` to the tool result pointing at:
1. The new `http` tool — eliminates the shell entirely for any
HTTP-shaped call. Single best fix.
2. End-quote-concat or double-quoted alternatives for raw shell.
The detector is conservative: requires BOTH exit code 2 AND a known
parser-error marker. A real command that prints the marker text in
stdout but exits 0 (e.g. `echo unexpected EOF ...`) does not trigger.
Tests in tests/tools/test_terminal_quoting_hint.py cover the four
documented markers, the exit-code gate, and that the hint advertises
the http tool explicitly.
9 tasks
teknium1
reviewed
Jul 13, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for targeting a real recovery gap: current foreground execution still reaches bash -c through tools/environments/base.py:933-936 and tools/environments/local.py:1003, while tools/terminal_tool.py:2740-2785 returns no quoting-specific guidance.
Problems
tools/terminal_tool.py:1575tells the model to callhttp, but current main has notools/http_tool.pyand nohttpentry intoolsets.py:31-80; linked PR #25861 is still open. This would direct the model to an unavailable tool.- The change only packages a foreground result. Background commands also run through a shell (
tools/process_registry.py:764-776) and expose their output viaprocesspoll/log/wait (tools/process_registry.py:2233-2239), without the detector. The added tests only call the helper directly.
Suggested changes
- Keep the generic quoting guidance, but remove or availability-gate the
httprecommendation. - Add a foreground result-packaging test; if background shell failures are in scope, cover the process-result path too.
Automated hermes-sweeper review.
| "mismatched quote. Common cause: a single-quoted string with a " | ||
| "literal apostrophe inside (e.g. `-d '{\"body\":\"It's done\"}'`). " | ||
| "Fastest fixes: " | ||
| "(1) If this was an HTTP request, call the `http` tool instead — " |
Contributor
There was a problem hiding this comment.
http is not available on current main: tools/http_tool.py is absent, _HERMES_CORE_TOOLS has no http entry, and linked PR #25861 is still open. Remove this unconditional recommendation or gate it on actual tool availability so the recovery hint cannot direct the model to a nonexistent tool.
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.
What does this PR do?
When the `terminal` tool's `bash -c ` invocation fails to parse the command (almost always an unclosed quote, e.g. an apostrophe inside a single-quoted JSON body), bash exits 2 with a recognizable message in stdout. Today the model just sees:
```
/usr/bin/bash: eval: line 3: unexpected EOF while looking for matching ''
```
…and frequently retries the same broken quoting because the error doesn't say what to do.
This PR adds a detector that catches the parser-error markers (with `returncode == 2`) and attaches an actionable `_hint` to the tool result, pointing the model at:
Standalone — works without #25861, but recommends it.
Type of Change
Changes Made
How to Test
`pytest tests/tools/test_terminal_quoting_hint.py -q` — 9 passed.
Checklist