Skip to content

hooks/hermes: adapter rewrites silently with a hardcoded 2s timeout — add passthrough guard, timeout env, audit log and version check #4387

Closed as not planned

Description

@dinhtrung

Summary

hooks/hermes/rtk-rewrite (plugin v0.1.0, __init__.py @ 6dcf44e) bridges Hermes' pre_tool_call hook to rtk rewrite. Four gaps surfaced on a live Hermes gateway:

  1. No guard against rewrites the rtk parser itself rejects. The adapter substitutes unconditionally; when the installed binary lags the rewrite contract, every affected call becomes a guaranteed parse-fail + shell fallback (zero savings, one extra subprocess, one parse_failures row).
  2. Hardcoded 2s timeout — real rewrites can exceed it, and the adapter then skips the rewrite entirely.
  3. No stdin=subprocess.DEVNULL — the child inherits the gateway's stdin pipe.
  4. Rewrites are silent — nothing records which command was replaced, so a degraded no-op looks identical to a working install.

This is an adapter-side report. Root cause of the arg-parsing half is tracked in #1604 (grep flags; fixed in v0.47.0 via #2628 — confirmed by @KuSh in that thread). The hook-timeout reports #218 / #1804 cover Claude Code and Gemini CLI config entries, not this adapter.

Environment (where the evidence came from)

Evidence

Works overall — ~/.local/share/rtk/history.db → commands: 141 rows in one day, 18,848 tokens saved (34.4%), e.g. ls -la … at 63–85%, cat <log> at 82–98%. So the hook is live and useful.

But on the same day:

sqlite3 ~/.local/share/rtk/history.db "select count(*), sum(fallback_succeeded=1) from parse_failures;"
68|68

68 parse failures, 100% of them grep with native flags, all recovered by fallback:

  • grep -rn --include=*.go -E … → error: unexpected argument '-r' found
  • grep -c plugin <file> → unexpected argument '-c'
  • grep -ac rtk <log> → unexpected argument '-a'

And from the adapter's own stderr in journald:

rtk: hermes plugin warning: rtk rewrite timed out

Reproduction of the contract mismatch (on 0.42.1)

$ rtk rewrite "grep -rn foo ."          # exit 3
rtk grep -rn foo .
$ rtk grep -rn foo .                    # the command just handed to the agent
error: unexpected argument '-r' found

The rewriter returns a command its own parser rejects. On Hermes the substitution still happens, the call fails, and the shell falls back — a wasted subprocess on every occurrence.

Ask (adapter-side, version independent)

  1. Passthrough guard — do not substitute when the original shape is known-unparseable (or validate once per subcommand shape and cache the verdict).
  2. Configurable timeout — env such as RTK_HERMES_TIMEOUT, default 5s instead of 2s.
  3. stdin=subprocess.DEVNULL.
  4. Audit log — append {ts, from, to} JSONL (e.g. ~/.hermes/logs/rtk-rewrites.jsonl) so rewriting is observable.
  5. Version handshake at register — warn once when rtk --version is older than the minimum version whose rewrite contract the adapter assumes.

We run a local patch covering 1–4, verified with rtk 0.50.0 (and against the hook function directly, no gateway restart needed). Happy to send it as a PR for hooks/hermes/ if that helps.

Activity

  1. dinhtrung commented on Oct 2, 2026

    @dinhtrung
    Author

    Closing this — we resolved it locally and the underlying cause is already fixed upstream.

    Withdrawn rather than leaving duplicate work in your queue — no action needed from maintainers. If a PR for hooks/hermes/ is still welcome, I can send the patch; otherwise consider this withdrawn. Thanks!

  2. added
    bug
    help wanted
    on Oct 2, 2026
  3. rtk-wshm-sync-bot commented on Oct 2, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 82%

    Summary

    Hermes adapter substitutes rewrites unconditionally with a hardcoded 2s timeout, inherited stdin, and no audit trail, causing avoidable parse-fail fallbacks (grep flags) against older rtk binaries.

    📁 Relevant files
    • hooks/hermes/rtk-rewrite/__init__.py

    Suggested Actions

    1. Review the local patch the reporter offers to send as a PR for hooks/hermes/init.py
    2. Cross-check with Hook rewrite produces unparseable args for native grep flags and non-existent subcommands #1604/fix(grep): stop -l/-t shadowing native grep flags #2628 (grep flag fix) to confirm which rtk versions still need the passthrough guard
    3. Note overlap with Hardening (retracted as a bug): bundled hook calls rtk rewrite without a deadline from PreToolUse — see correction, rtk was NOT the cause of our timeouts #3589 (retracted hook-timeout report) when evaluating the timeout change
    4. Decide on default for RTK_HERMES_TIMEOUT and the version-handshake minimum before merging

    Triaged automatically by wshm · This is an automated analysis, not a human review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:clibughelp wantedpriority:medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions