Skip to content

Hook rewrite ignores process-wrapper prefixes (timeout, time) so wrapped commands run raw/unfiltered #2375

Closed

Description

@meier-christoph

Component: hook rewrite engine (src/discover/registry.rs)
Version: rtk 0.42.2 (reproduced on develop)

What's wrong

When a command is prefixed with a process-wrapper such as timeout 60 …, rtk rewrite returns passthrough (exit 1) instead of rewriting the inner command. The hook then runs the raw command, so no filter is applied and the full, unfiltered output is returned.

This is not filter-specific — it affects every command/ecosystem identically. It shows up in practice because coding agents commonly wrap long-running build/test commands in timeout to bound them (e.g. timeout 300 cargo test).

Reproduction

$ rtk rewrite "cargo test"
rtk cargo test                       # rewritten (exit 3)

$ rtk rewrite "timeout 300 cargo test"
                                     # no output, exit 1 (passthrough) — runs raw

$ rtk rewrite "cargo clippy --all-targets"
rtk cargo clippy --all-targets       # rewritten
$ rtk rewrite "timeout 120 cargo clippy --all-targets"
                                     # no output, exit 1 (passthrough)

$ rtk rewrite "git log --oneline"
rtk git log --oneline                # rewritten
$ rtk rewrite "timeout 30 git log --oneline"
                                     # no output, exit 1 (passthrough)

Same passthrough for every common process wrapper:

Command Result
timeout 300 cargo test passthrough (raw)
timeout 5m cargo build passthrough
nice -n 10 cargo test passthrough
nohup cargo build passthrough
time cargo build passthrough
stdbuf -oL cargo test passthrough

For comparison, the prefixes that are stripped today work as expected:

$ rtk rewrite "sudo cargo test"
sudo rtk cargo test
$ rtk rewrite "RUST_LOG=debug cargo test"
RUST_LOG=debug rtk cargo test

Where it happens

src/discover/registry.rs peels a fixed set of prefixes before routing a command to its rule, then re-prepends them to the rewrite:

  • ENV_PREFIX regex — sudo, env, and VAR=val assignments.
  • SHELL_PREFIX_BUILTINS — noglob, command, builtin, exec, nocorrect.

Process-wrapper commands are in neither set. For timeout 300 cargo test, classify_command sees base word timeout, matches no rule, and rewrite_segment_inner returns None → passthrough.

Impact

Commands wrapped in timeout (and the other wrappers above) receive no RTK filtering and the full raw output, with no error or warning indicating the filter was skipped.

Activity

  1. added
    bug
    help wanted
    on Jun 11, 2026
  2. pszymkowiak commented on Jun 11, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 96%

    Summary

    Hook rewrite engine in registry.rs silently passes through any command prefixed with process-wrappers (timeout, nice, time, nohup, stdbuf), bypassing all filtering with no warning.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/discover/registry.rs

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

  3. added a commit that references this issue on Sep 11, 2026
  4. kauredo commented on Sep 11, 2026

    @kauredo

    Follow-up on the fix: four of the five wrappers listed above now peel correctly, stdbuf still passes through.

    rtk 0.49.0, Homebrew, arm64:

    $ rtk rewrite "timeout 30 git status"
    timeout 30 rtk git status            # exit 3
    
    $ rtk rewrite "nice -n 10 ls -la"
    nice -n 10 rtk ls -la                # exit 3
    
    $ rtk rewrite "nohup cargo build"
    nohup rtk cargo build                # exit 3
    
    $ rtk rewrite "time git log --oneline -5"
    time rtk git log --oneline -5        # exit 3
    
    $ rtk rewrite "git status"
    rtk git status                       # exit 3
    
    $ rtk rewrite "stdbuf -oL git status"
                                         # no output, exit 1 (runs raw)

    stdbuf -oL is a common wrapper when an agent wants line-buffered output from a long build or test run, which is the same situation that makes the timeout case worth fixing.

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:high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions