Repository navigation
fix(hermes): close the rewrite's stdin and make its timeout configurable - #3833
Conversation
There was a problem hiding this comment.
Tested and approved on a live Hermes deployment.
Independently reviewed and validated this PR end-to-end.
Independently validated this PR end-to-end against a live Hermes deployment. The proposed fix works for me.
Environment
- RTK v0.48.0
- Hermes Agent v0.21.0 (2026.8.31)
- Oracle Linux 9.8 / aarch64
- Rust/Cargo 1.98.1
- PR commit tested:
f8f4c2d
Validation
- Checked out the PR commit directly and reviewed the diff against develop.
- Ran the Hermes test suite with Cargo available:
Ran 16 tests in 48.538s OK
This included test_cargo_init_installs_importable_plugin_that_rewrites_with_fake_rtk.
3. Copied the PR's hooks/hermes/rtk-rewrite/__init__.py into the live Hermes plugin directory and verified it was byte-for-byte identical to the PR version before restarting the gateway.
4. Restarted the Hermes gateway successfully.
5. From a live WhatsApp Hermes session, asked Hermes to run git status. The terminal invocation was rewritten to:
rtk git status
rtk gainindependently recorded the invocation. The trackedrtk git statuscount increased from 1 to 2 after the PR version was loaded.
Live Hermes terminal call was successfully rewritten through RTK. I had previously reproduced the underlying issue locally with the {"action": "modify", "args": {"command": rewritten}} workaround.
Also verified this PR's more complete {**args, "command": rewritten} implementation works in a live Hermes gateway while preserving other terminal arguments covered by the regression test. This provides live Linux/aarch64 validation in addition to the existing unit/contract testing.
Thanks for the fix!
|
Two small additions to the same
A |
|
@KuSh I've addressed these in commit 6f91b82: added stdin=subprocess.DEVNULL, made RTK_HERMES_TIMEOUT configurable with a 5-second default and fallback for invalid values, and added the requested assertions and tests. The README is updated too. The changes are already pushed to this PR and ready for another look. |
KuSh
left a comment
There was a problem hiding this comment.
Round 1 — CHANGES REQUESTED
Claim: the Hermes plugin returns a pre_tool_call modify directive for terminal rewrites instead of only mutating the payload, closes the rewrite subprocess's stdin, and reads its timeout from RTK_HERMES_TIMEOUT (5 s default).
Scope: accept. #4093 carries the same Hermes change (opened later, alongside its OpenClaw work) and #4527 edits the same subprocess.run call; this one lands first.
Ran: real Hermes v2026.7.30, v2026.8.13, v2026.8.16, v2026.8.31 and v0.22.2 (run from source in Docker) × rtk develop f16becacd vs this PR merged onto it. Each run did rtk init --agent hermes, then a terminal git status through model_tools.handle_function_call and through the AIAgent loop against a stub model (quiet, verbose, two parallel calls). Also: a second plugin returning modify × 2 releases; RTK_HERMES_TIMEOUT × 6 values through Hermes; Hermes hook_callback_timeout below the rewrite time. Invariants: every decision, under the real host dispatch, non-default config. Savings n/a (no filter change).
Pins: 6 decision areas, 14 mutations, 0 survived the suite.
Matrix: executed this round; pin check: executed this round.
CI @6f91b82: all green (11/11).
Blocks merge (1, frozen at round 1)
-
hooks/hermes/rtk-rewrite/__init__.py:85: the directive's shape does not match how Hermes applies apre_tool_callresult. It has two consequences, both regressions against develop (develop mutatesargs["command"]in place):- Hermes before v2026.8.16 ignores
modify. Those releases only readblock/approvefrom the return value and run the payload they passed in. On v2026.7.30 and v2026.8.13, develop's plugin rewrites: the tracking DB recordsgit status → rtk git statusand the model sees* master / ?? f1.txt …. This PR's plugin runs rawgit status(On branch master / Untracked files: …) with no warning, on every path and mode above. From v2026.8.16 on, both rewrite. {**args, "command": rewritten}resends the original value of every other key. Hermes mergesmodifydirectives in hook order, so this undoes an earlier plugin's change. With a plugin that returns{"action": "modify", "args": {"workdir": "/work/repo2"}}and sorts beforertk-rewrite, on a call{"command": "git status", "workdir": "/work/repo"}: develop runs inrepo2, as that plugin asked. This PR runs back inrepo(v2026.8.16 and v0.22.2).
A correct fix passes these rows: the rewrite applies (
rtk git statustracked) on all five releases above, inhandle_function_calland the agent loop; and the other plugin'sworkdirsurvives on v2026.8.16 and v0.22.2. Tests:test_rewrite_returns_modify_directive_without_mutating_terminal_argsand the installed-flow test currently pin the payload as untouched and the directive as carrying every key. They need to fail when the payload is not updated and when the directive carries keys other thancommand. The README sentence "The original payload stays unchanged" changes with it. - Hermes before v2026.8.16 ignores
Optional — will not hold merge
-
The installed-flow test reads
RTK_HERMES_TIMEOUTfrom the contributor's environment.RTK_HERMES_TIMEOUT=1e-9 python3 -m unittest discover -s hooks/hermesfailstest_cargo_init_installs_importable_plugin_that_rewrites_with_fake_rtkwith{'action': 'modify', …} != None. The samesetUpasRtkRewritePluginTestfixes it. -
The README accepts "any positive, finite"
RTK_HERMES_TIMEOUT, but two ranges do not behave that way:- At or above Hermes'
plugins.hook_callback_timeout(30 s by default), Hermes fails closed. With its cap below the rewrite time, the terminal call returns{'error': 'pre_tool_call plugin callback timed out or is still running'}, on develop and on this PR alike. - Very large values:
RTK_HERMES_TIMEOUT=31536000makessubprocess.runraisetimeout is too largeon every call (warning, no rewrite).
Clamping below the cap, or saying so in the README, would cover both.
- At or above Hermes'
-
hooks/README.md:309-316still showstimeout=2and the in-place assignment as the whole mechanism.
Filed as follow-ups
- CI runs none of the plugin test suites that live outside cargo (
hooks/hermesunittest,hooks/opencode/rtk.test.mjs,hooks/claude/test-rtk-rewrite.sh,hooks/copilot/test-rtk-rewrite.sh). That is pre-existing, so the pins above only bind when someone runs them by hand. Filed as #4588.
Checked and correct — no need to re-verify
- On v2026.8.16, v2026.8.31 and v0.22.2 the directive applies:
rtk git statusis tracked and the output is compact, inhandle_function_calland in the agent loop (quiet, verbose, parallel). stdin=subprocess.DEVNULLis passed, and the call assertion pins it.RTK_HERMES_TIMEOUTthrough Hermes v0.22.2:- unset,
abcand-3fall back to 5 s and the rewrite applies; 10rewrites;0.000001printsrtk: hermes plugin warning: rtk rewrite timed outand the original command runs.
- unset,
- The parsing rules (
nan,inf,1e999,0, negatives, whitespace, read per call, not truncated) each have a test that fails when the rule is removed. - Passthrough and error paths still return
None; asserted, and a mutation that makes them return a directive is caught. - Merge onto develop
f16becacdis clean.cargo fmt --check,cargo clippy --all-targetsandcargo test --all(49 suites) exit 0, and the Hermes unittest suite passes 18/18, including the installed flow. - One data point on #3797: develop's in-place rewrite does apply on v2026.8.31 (the release named there) in both dispatch paths above. If the failure came from another entry point (a gateway platform adapter, for instance), naming it would let a test cover that path.
Your questions
- None open; the stdin and timeout asks from the earlier comment are in and verified above.
Next
Make the rewrite reach both the payload that Hermes before v2026.8.16 executes and the modify merge of later releases, with the directive carrying only command. The rows under "Blocks merge" pass, with the two tests updated to pin it. After that, this merges.
Threads: 1 open (the line comment below), 0 resolved this round.
Resolve the hooks README table conflict by retaining Oh My Pi and the corrected Hermes contract. No upstream workflow or Rust changes beyond the merge. Validation: fmt, workspace clippy and workspace tests pass (4,954 tests, 8 existing ignored); Hermes Python suite passes 18/18 both normally and with inherited RTK_HERMES_TIMEOUT=1e-9.
|
@KuSh I've addressed the Hermes compatibility feedback: the hook now updates args["command"] for older Hermes and returns a command-only modify directive for newer versions, so it won't overwrite another plugin's workdir. The tests and hook documentation have been updated accordingly. |
KuSh
left a comment
There was a problem hiding this comment.
Round 2 — CHANGES REQUESTED
Claim: the Hermes plugin returns a pre_tool_call modify directive for terminal rewrites, closes the rewrite subprocess's stdin, and reads its timeout from RTK_HERMES_TIMEOUT (5 s default).
Scope: accept (round 1, frozen).
Ran: real Hermes v2026.7.30, v2026.8.13, v2026.8.16, v2026.8.31 and v0.22.2 (0.19.1 to 0.22.2, run from source in Docker) × rtk develop 5538d72b1 vs this PR merged onto it. Each run did rtk init --agent hermes, then a terminal git status through the AIAgent loop against a stub model (quiet, verbose, two parallel calls). Also: a second plugin, sorting before rtk-rewrite, that returns modify for workdir and for command, on 4 releases; RTK_HERMES_TIMEOUT × 6 values. Invariants: every decision, under the real host dispatch, non-default config. Savings n/a (no filter change).
Pins: 6 decision areas, 15 mutations, 0 survived the suite.
Matrix: executed this round; pin check: executed this round.
CI @b2e7ce8: all green (15/15).
Blocks merge (1, frozen at round 1; +1 regression found this round)
-
The round-1 item is fixed. The rewrite applies on all five releases in every mode (
rtk git statustracked, compact output), and an earlier plugin'sworkdirchange survives on v2026.8.16 and v0.22.2. Thread resolved. -
hooks/hermes/rtk-rewrite/__init__.py:88: themodifydirective replaces acommandanother plugin chose. Round 1's code had this too and my round-1 matrix only variedworkdir, so this one is mine to own. Hermes hands everypre_tool_callhook the original payload and merges theirmodifydirectives in hook order. A directive carryingcommandtherefore wins over an earlier plugin'scommand, and it carries rtk's rewrite of the original command. With a plugin that returns{"action": "modify", "args": {"command": "git status --porcelain"}}forgit statusand sorts beforertk-rewrite:- Develop: that plugin's command runs (
?? in_repo.txt) on v2026.8.16, v2026.8.31 and v0.22.2. - This PR: it runs
rtk git statusinstead (* master / ?? in_repo.txt).
On v2026.8.13 the two behave the same, since
modifyis ignored there. Develop loses rtk's rewrite in that setup, which is a safe failure; this PR drops the other plugin's change, which can be a sandbox or safety rewrite. The plugin cannot see the earlier directive, so no shape of acommanddirective avoids this.A correct fix passes these rows:
- the rewrite applies on all five releases above, in every mode;
- the earlier plugin's
workdirsurvives on v2026.8.16 and v0.22.2; - the earlier plugin's
commandruns on v2026.8.16 and v0.22.2, as on develop; - the stdin and timeout rows below are unchanged.
The in-place update this push added already passes the first row on every release I can run, including v2026.8.31, the release #3797 names. Without the directive it passes all four, and the tests then need to fail if a directive carrying
commandcomes back. If #3797 came from an entry point where the in-place update does not reach the terminal tool, that is the input this row set is missing; round 1 asked which one it was, and naming it would settle whether a directive is needed at all. - Develop: that plugin's command runs (
Optional — will not hold merge
hooks/hermes/README.md:plugins.hook_callback_timeoutonly exists from v2026.8.31 (Hermes 0.21.0); v2026.7.30 to v2026.8.16 have no callback limit. The "keep it below" sentence and the fail-open line could say so.- The version boundary is given as a date tag only.
hermes --versionreports 0.20.1 for v2026.8.13 and 0.20.2 for v2026.8.16, so naming both would let a user place their install.
Filed as follow-ups
- None this round (#4588 from round 1 still covers the plugin suites missing from CI).
Checked and correct — no need to re-verify
- The in-place update and the command-only directive are each pinned. Dropping the assignment, resending all keys, returning no directive, updating a copy, or leaving
commandout of the directive each failtest_rewrite_updates_payload_and_returns_command_only_directive. - Behaviour that matches develop, since develop also mutates the payload in place:
- later hooks see the rewritten command;
- a worker that Hermes abandons after its callback timeout can still write the payload.
- The installed-flow test no longer reads
RTK_HERMES_TIMEOUTfrom the environment. hooks/README.mdnow shows the current timeout, stdin and success path.RTK_HERMES_TIMEOUTthrough Hermes v0.22.2:- unset,
abcand-3fall back to 5 s and the rewrite applies; 10rewrites;0.000001warnsrtk rewrite timed outand runs the original command;31536000warnstimeout is too large, as the README now says.
- unset,
- Merge onto develop
5538d72b1is clean.cargo fmt --check,cargo clippy --all-targetsandcargo test --all(50 suites) exit 0, and the Hermes unittest suite passes.
Your questions
- No question in the last comment. Thanks for the Git 2.56 check: #4578 is on develop now, and CI is green on this head.
Next
Keep the rewrite reaching the payload on every release without overriding another plugin's command: the four rows under item 2. On what I could run, that is the in-place update alone, with stdin and timeout as they are. If #3797's entry point needs the directive, naming it is what decides between the two.
Threads: 1 open (item 2), 1 resolved this round (round 1's item, fixed).
|
Confirmed on Hermes Agent v0.22.5 (macOS and Ubuntu) with rtk 1.0.1 and 1.1.0. The plugin installed by |
The agent table still listed a command-only modify directive the plugin no longer returns. The README also spelled out how Hermes orders and merges hook results, which is Hermes behaviour; it now states only what the plugin does, and that from Hermes v2026.8.16 another plugin's modify directive setting `command` replaces the rewrite. Hermes enforces `plugins.hook_callback_timeout` from v2026.8.27 (0.20.6), not v2026.8.31. Co-Authored-By: Claude Opus 5.5 <[email protected]>
KuSh
left a comment
There was a problem hiding this comment.
Round 3 — APPROVED, follow-up filed
Claim: the Hermes plugin closes the rtk rewrite subprocess's stdin and reads its timeout from RTK_HERMES_TIMEOUT (5 s default), and keeps rewriting the terminal payload in place without returning a directive.
Scope: accept (round 1, frozen). The modify directive the original claim was about is gone from the head. #3797 is closed: the in-place rewrite reaches execution on current Hermes. I retitled the PR and rewrote its description to match the head. Maintainer PRs: checked against #4458, #4402 and #4269; each merges clean, and both test sets pass on each merge.
Ran: real Hermes v2026.7.30, v2026.8.13, v2026.8.16, v2026.8.31, v0.22.2 and v0.22.5 (0.19.1 to 0.22.5, run from source in Docker) × rtk develop 550a5c13d vs this PR merged onto it. Each run did rtk init --agent hermes, then a terminal git status through the AIAgent loop against a stub model (quiet, verbose, two parallel calls). Also: a second plugin, sorting before rtk-rewrite, that returns modify for workdir and for command (v2026.8.16, v0.22.5); RTK_HERMES_TIMEOUT × 6 values on v0.22.5. Invariants: every decision, under the real host dispatch, non-default config. Savings n/a (no filter change).
Pins: 6 decision areas, 14 mutations, 0 survived the suite.
Matrix: executed this round; pin check: executed this round.
CI @19339fd: all green (15/15)
Blocks merge (1 from round 1, 1 from round 2, both fixed)
- Round 1, older Hermes: fixed. The rewrite applies on all six releases in every mode (
rtk git statustracked, compact output). - Round 2,
commandoverride: fixed in f72f7c8. An earlier plugin'sworkdirandcommanddirectives both win, as on develop (?? in_repo.txtfor thecommandcase on v2026.8.16 and v0.22.5). Thread resolved.
Filed as follow-ups
- #4912 llm-proxy identity probe can panic inside ureq when the peer drops the connection: outside this PR's hunks. It is the source of the one red macOS job on f72f7c8 (
probe_rejects_a_stranger_on_the_port, ureq 2.12.1'sexpectat response.rs:403).
Checked and correct — no need to re-verify
- The in-place-only shape is pinned. Each of these fails
test_rewrite_updates_payload_without_returning_a_directiveand the new composition test:- dropping the assignment;
- returning a
commanddirective or a full-args directive; - updating a copy.
- The round-1 stdin and timeout mutations are still caught.
RTK_HERMES_TIMEOUTthrough Hermes v0.22.5:- unset,
abcand-3fall back to 5 s and the rewrite applies; 10rewrites;0.000001warnsrtk rewrite timed outand runs the original command;31536000warnstimeout is too large.
- unset,
- Merge onto develop
550a5c13dis clean.cargo fmt --check,cargo clippy --all-targetsandcargo test --all(61 suites) exit 0. The Hermes unittest suite passes 19/19, including the installed flow, and stays green withRTK_HERMES_TIMEOUTexported.
Your questions
- None open since round 2.
Next
Fixup 19339fd pushed, docs only and code-reviewed:
hooks/README.md: the agent table row is back to "In-place mutation" (it still listed the directive).hooks/hermes/README.mdstates what the plugin does and that another plugin'smodifysettingcommandreplaces the rewrite (v2026.8.16 and later), rather than describing Hermes' merge internals.- The host callback timeout is dated from v2026.8.27 (Hermes 0.20.6), not v2026.8.31. That date came from my round-2 note, which was wrong.
Approving. Thank you for carrying this through three rounds.
Threads: 0 open, 1 resolved this round (round 2's, fixed in f72f7c8).
Summary
The Hermes plugin keeps rewriting the terminal payload in place and returns no
modifydirective. That reaches execution on every Hermes release tested, from v2026.7.30 to v0.22.5, and leaves other plugins'modifydirectives in charge of the keys they set,commandincluded.rtk rewriteruns with stdin closed (subprocess.DEVNULL) instead of inheriting the host's.RTK_HERMES_TIMEOUT(5 s default, previously a fixed 2 s). Missing, malformed, non-positive or non-finite values fall back to the default.hooks/hermes/README.mdandhooks/README.mddescribe the hook contract, why no directive is returned, and how the timeout relates to Hermes' ownplugins.hook_callback_timeout.RTK_HERMES_TIMEOUTfrom the caller's environment.Test plan
python3 -m unittest discover -s hooks/hermes -v(19 tests, including the installed flow)cargo fmt --all --checkcargo clippy --all-targetscargo test --all