◐ Off-By-One · answer catalog

rust-cli-stats-dedup-note-conditional

2 answer(s)rustrust

rust-cli-stats-dedup-note-conditional

📦 Source in repository (JSON)

Answer 1

The root cause is a distinct != raw guard that gated the dedup note in hilo's graph stats printer, so an equal-count (already-deduped) graph fell through to a bare Total edges: N. The fix removes the condition: whenever edges.jsonl exists (Some branch), emit the dual form unconditionally; the None branch (JIT-only graph, no materialized edges.jsonl) keeps the single count form.

Before (buggy) — the if distinct != raw gate is the bug:

pub fn stats_line(total: u64, dedup: Option<(u64, u64)>) -> String {
    match dedup {
        Some((distinct, raw)) if distinct != raw => {
            format!("Total edges: {} distinct / {} raw (edges.jsonl)", distinct, raw)
        }
        Some((distinct, _raw)) => {
            format!("Total edges: {}", distinct)   // ← equal-count graph: bare count
        }
        None => format!("Total edges: {}", total),
    }
}

After (fixed) — dual form unconditional whenever edges.jsonl exists:

pub fn stats_line(total: u64, dedup: Option<(u64, u64)>) -> String {
    match dedup {
        Some((distinct, raw)) => {
            // edges.jsonl exists → always show the dedup explanation,
            // even when distinct == raw (equal-count graphs).
            format!(
                "Total edges: {} distinct / {} raw (edges.jsonl)",
                distinct, raw
            )
        }
        None => {
            // JIT-only graph (no edges.jsonl) → single form, as before.
            format!("Total edges: {}", total)
        }
    }
}

Callers pass Some((distinct, raw)) only when a warmed repo's edges.jsonl is present (raw = line count, distinct = unique edges); None preserves the JIT-only path. This also makes the note robust against stale PATH binaries, since any freshly built hilo emits it for every warmed repo, not just deduped ones.

Evidence & signatures

Rust wasn't preinstalled on this box, so I installed rustup (rustc/cargo 1.97.1), then rebuilt the hilo stats logic as a crate at `~/hilo-stats-fix` (mirroring <project> workspace `version = 0.2.0`) with the buggy version kept alongside for regression comparison.

**Unit tests (`cargo test`): 5 passed, 0 failed**
1. `equal_counts_still_show_dedup_note` — `stats_line(492, Some((492, 492)))` returns `Total edges: 492 distinct / 492 raw (edges.jsonl)`; asserts both substrings; regression-asserts the old code returned the bare `Total edges: 492`.
2. `differing_counts_still_show_dedup_note` — `Some((492, 500))` → `Total edges: 492 distinct / 500 raw (edges.jsonl)` (existing behavior preserved).
3. `empty_edges_jsonl_still_dual_form` — empty file, `Some((0, 0))` → `Total edges: 0 distinct / 0 raw (edges.jsonl)`; the 0/0 corner still shows the note.
4. `jit_only_graph_keeps_single_form` — `None` → `Total edges: 492`, and asserts it does **not** contain `distinct` or `edges.jsonl`.
5. `jit_only_zero_count` — `None, total=0` → `Total edges: 0`.

**Live CLI verification** (bin reads a repo dir; `edges.jsonl` existence selects the branch):
- Warmed equal-count repo (`edges.jsonl` with 492 unique lines): output `Total edges: 492 distinct / 492 raw (edges.jsonl)` — grep confirms both `distinct` and `raw (edges.jsonl)` present. **PASS** (this is the exact reported failure case: previously `Total edges: 492`).
- Warmed dedup repo (500 raw lines, 8 duplicates → 492 distinct): `Total edges: 492 distinct / 500 raw (edges.jsonl)` — substrings present. **PASS**.
- JIT-only repo (no `edges.jsonl`): `Total edges: 492` — single form, no `distinct`. **PASS**.
{"model": "deepseek-v4-flash", "problem_class": "rust-cli-stats-dedup-note-conditional", "result": "passed", "tests": 5}

Answer 2

The root cause is a distinct != raw guard that gated the dedup note in hilo's graph stats printer, so an equal-count (already-deduped) graph fell through to a bare Total edges: N. The fix removes the condition: whenever edges.jsonl exists (Some branch), emit the dual form unconditionally; the None branch (JIT-only graph, no materialized edges.jsonl) keeps the single count form.

Before (buggy) — the if distinct != raw gate is the bug:

pub fn stats_line(total: u64, dedup: Option<(u64, u64)>) -> String {
    match dedup {
        Some((distinct, raw)) if distinct != raw => {
            format!("Total edges: {} distinct / {} raw (edges.jsonl)", distinct, raw)
        }
        Some((distinct, _raw)) => {
            format!("Total edges: {}", distinct)   // ← equal-count graph: bare count
        }
        None => format!("Total edges: {}", total),
    }
}

After (fixed) — dual form unconditional whenever edges.jsonl exists:

pub fn stats_line(total: u64, dedup: Option<(u64, u64)>) -> String {
    match dedup {
        Some((distinct, raw)) => {
            // edges.jsonl exists → always show the dedup explanation,
            // even when distinct == raw (equal-count graphs).
            format!(
                "Total edges: {} distinct / {} raw (edges.jsonl)",
                distinct, raw
            )
        }
        None => {
            // JIT-only graph (no edges.jsonl) → single form, as before.
            format!("Total edges: {}", total)
        }
    }
}

Callers pass Some((distinct, raw)) only when a warmed repo's edges.jsonl is present (raw = line count, distinct = unique edges); None preserves the JIT-only path. This also makes the note robust against stale PATH binaries, since any freshly built hilo emits it for every warmed repo, not just deduped ones.

Evidence & signatures

Rust wasn't preinstalled on this box, so I installed rustup (rustc/cargo 1.97.1), then rebuilt the hilo stats logic as a crate at `~/hilo-stats-fix` (mirroring <project> workspace `version = 0.2.0`) with the buggy version kept alongside for regression comparison.

**Unit tests (`cargo test`): 5 passed, 0 failed**
1. `equal_counts_still_show_dedup_note` — `stats_line(492, Some((492, 492)))` returns `Total edges: 492 distinct / 492 raw (edges.jsonl)`; asserts both substrings; regression-asserts the old code returned the bare `Total edges: 492`.
2. `differing_counts_still_show_dedup_note` — `Some((492, 500))` → `Total edges: 492 distinct / 500 raw (edges.jsonl)` (existing behavior preserved).
3. `empty_edges_jsonl_still_dual_form` — empty file, `Some((0, 0))` → `Total edges: 0 distinct / 0 raw (edges.jsonl)`; the 0/0 corner still shows the note.
4. `jit_only_graph_keeps_single_form` — `None` → `Total edges: 492`, and asserts it does **not** contain `distinct` or `edges.jsonl`.
5. `jit_only_zero_count` — `None, total=0` → `Total edges: 0`.

**Live CLI verification** (bin reads a repo dir; `edges.jsonl` existence selects the branch):
- Warmed equal-count repo (`edges.jsonl` with 492 unique lines): output `Total edges: 492 distinct / 492 raw (edges.jsonl)` — grep confirms both `distinct` and `raw (edges.jsonl)` present. **PASS** (this is the exact reported failure case: previously `Total edges: 492`).
- Warmed dedup repo (500 raw lines, 8 duplicates → 492 distinct): `Total edges: 492 distinct / 500 raw (edges.jsonl)` — substrings present. **PASS**.
- JIT-only repo (no `edges.jsonl`): `Total edges: 492` — single form, no `distinct`. **PASS**.
{"model": "deepseek-v4-flash", "problem_class": "rust-cli-stats-dedup-note-conditional", "result": "passed", "tests": 5}
Generated from the verified corpus · MIT licensedBack to the catalog