Skip to content

discover: split_command_chain's stop-at-pipe truncation blinds classification to everything after | #3683

Open

Description

@KuSh

Found by `/code-review max` while iterating on #3206 (pre-existing behavior, not introduced by that PR — it inherits the limitation, doesn't cause it — so flagged separately rather than folded in).

`discover::registry::split_command_chain` calls `lexer::split_on_operators(cmd, true)` with `stop_at_pipe=true`, which returns only the segment(s) before the first `|` — by design, per its own doc comment ("used by command rewriting — only the left side of a pipe gets rewritten"). `discover::run()`'s classification loop uses this same function to split transcript commands into parts for counting/classification, so a command like `cargo test | tail -50` becomes just `["cargo test"]` — the `| tail -50` half is silently dropped from the scan entirely (not counted in `total_commands`, not classified, invisible to every reporting bucket including the new hook-decision coverage estimate).

Separately, this also means `estimate_hook_coverage`'s registry-rewrite check can diverge from the real hook's own pipe-safety veto (`RewriteContext::PipelineFinal` in the real `rewrite_command` path) for the first segment too, since discover evaluates `"cargo test"` in isolation rather than the full `"cargo test | tail -50"` line the real hook sees — the real hook may correctly refuse to rewrite because of what follows the pipe, while discover's isolated-segment view has no way to know that.

Likely fix: discover's classification loop needs its own pipe-aware handling — either treat a piped command as a single opaque unit for counting purposes (matching what the real hook actually evaluates), or explicitly model the "rewrite only applies pre-pipe, but the whole line is one attestable unit" distinction the real hook already has. This touches how `rtk discover` counts/classifies commands generally, not just the hook_coverage estimate, so it's a bigger change than a coverage-estimate fixup.

Activity

  1. added
    bug
    help wanted
    on Aug 23, 2026
  2. pszymkowiak commented on Aug 23, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 88%

    Summary

    discover::registry::split_command_chain truncates at the first pipe, so discover's classification loop silently drops everything after '|' from counting/classification and evaluates pre-pipe segments in isolation, diverging from the real hook's pipe-aware rewrite decision — needs pipe-aware handling in discover's counting logic, not just the hook_coverage estimate.

    📁 Relevant files
    • src/discover/registry.rs
    • src/discover/mod.rs

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

  3. k4its1t commented on Aug 24, 2026

    @k4its1t

    I’d like to work on this. I’ll update discovery’s chain splitting so each pipeline stays intact as one counting/classification unit while &&, ||, and ; still split independent clauses. I’ll add regressions for plain, mixed-chain, quoted, and |& pipelines, including the session counting path that shares this helper.

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