Skip to content

fix(gain): count RTK_DISABLED bypasses with discover's gate - #4376

Open
Cedric921 wants to merge 3 commits into
rtk-ai:developfrom
Cedric921:fix/gain-bypass-count-uses-discover-gate
Open

Cedric921 wants to merge 3 commits into
rtk-ai:developfrom
Cedric921:fix/gain-bypass-count-uses-discover-gate

Conversation

@Cedric921

Copy link
Copy Markdown
Contributor

fix(gain): count RTK_DISABLED bypasses with discover's gate

Fixes #4277

Problem

rtk gain and rtk discover disagreed on what counts as an RTK_DISABLED= bypass:

  • gain (check_rtk_disabled_bypass) checked each whole, unsplit history line and counted it whenever its leading env prefix contained RTK_DISABLED=.
  • discover splits the line into chain segments, strips the prefix, and counts a segment only if it is supported and the hook would actually have rewritten it without the prefix (would_be_covered_without_bypass).

So gain over-counted, for example RTK_DISABLED=1 xargs -n1 git show, which the hook never rewrites, and under-counted bypasses in later segments, for example git status && RTK_DISABLED=1 git diff.

Change

  • src/discover/mod.rs
    • New shared per-segment gate classify_bypass returning NotBypassed | Counted | Uncovered | Irrelevant. Discover's loop now uses it (same behaviour as before).
    • line_has_counted_bypass(raw_cmd, ctx) splits the chain and returns true if any segment is Counted.
    • CoverageContext::load_without_hook_log() loads hook-installed status, config exclusions and transparent prefixes, and permission rules. discover::run uses it and adds its measured hook log on top. The counterfactual never reads that log.
  • src/analytics/gain.rs: counts a line only via line_has_counted_bypass. A cheap contains("RTK_DISABLED=") check runs first, and the context is built lazily on the first matching line, so lines without the prefix cost nothing extra.
  • src/discover/registry.rs: removed the now-unused cmd_has_rtk_disabled_prefix. Its test now covers prefix_contains_rtk_disabled + strip_disabled_prefix. Fixed a stale reference to it in AWARENESS_CONFIG.md.

The runtime #508 hint emitted by the hook is unchanged and is left for a follow-up.

Tests

New regression tests in discover::tests (written first; 3 failed against the old whole-line logic):

  • RTK_DISABLED=1 xargs -n1 git show is not counted
  • RTK_DISABLED=1 git status is counted
  • git status && RTK_DISABLED=1 git diff is counted
  • no hook installed: not counted
  • no prefix: not counted

cargo fmt --check, cargo clippy --all-targets (clean) and the full cargo test suite pass.

`rtk gain`'s overuse warning counted every history line whose env prefix
contained `RTK_DISABLED=`, while `rtk discover` splits the chain and only
counts a segment that is supported and that the hook would have rewritten
absent the prefix. So `RTK_DISABLED=1 xargs -n1 git show` inflated gain's
warning, and `git status && RTK_DISABLED=1 git diff` was missed by it.

Move the per-segment decision into one shared gate in discover
(`classify_bypass`, wrapped by `line_has_counted_bypass` for whole lines)
and use it from both. `CoverageContext::load_without_hook_log` builds the
context gain needs; gain loads it lazily, only once a line contains
`RTK_DISABLED=`. Drop the now-unused `cmd_has_rtk_disabled_prefix`.

Fixes rtk-ai#4277
@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added analytics bug Something isn't working discover labels Oct 1, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟡 Risk medium

Summary

Fixes a discrepancy where rtk gain and rtk discover disagreed on what counts as an RTK_DISABLED= bypass by refactoring discover's per-segment bypass classification logic into a shared classify_bypass/line_has_counted_bypass function that gain now also uses. This replaces gain's old whole-line prefix check with the same segment-splitting, hook-coverage-aware gate discover already used, fixing both over-counting (unsupported commands) and under-counting (bypasses in later chain segments…

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #4277


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

Resolve conflicts with rtk-ai#3808, which reworked discover's RTK_DISABLED=
handling (wrapper-aware `strip_disabled_prefix_for_analytics` and
`judge_disabled_segment`). Keep develop's per-segment logic as the one
gate and route `line_has_counted_bypass` (gain's count) through it,
replacing this branch's own `classify_bypass`. Drop
`cmd_has_rtk_disabled_prefix` again: gain was its only caller. Its rtk-ai#3808
regression cases move to `line_has_counted_bypass` tests.
Resolve conflicts: keep line_has_counted_bypass with develop's
rtk proxy -> rtk bypass doc rename, and accept develop's removal of
AWARENESS_CONFIG.md (this branch only fixed one reference in it).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

analytics bug Something isn't working discover

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gain: RTK_DISABLED bypass warning counts commands the hook would not have rewritten anyway

1 participant