Skip to content

fix(static+history): flag/language filters for every analyzer; root-cause oracle timeout - #26

Merged
dmytrogajewski merged 2 commits into
mainfrom
fix/static-flag-filter-parity
Aug 8, 2026
Merged

dmytrogajewski merged 2 commits into
mainfrom
fix/static-flag-filter-parity

Conversation

@dmytrogajewski

@dmytrogajewski dmytrogajewski commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Part 1 — static flags & --languages (previously the whole PR)

Problem

codefang run -a static/complexity --format json --include-generated --include-vendored ... and the identical command with --format text reported divergent totals on generated-code-heavy repos (observed: 18 653 vs 2 178 total functions). Root cause:

  • Non-json formats of static/complexity, and all of static/halstead, static/cohesion, static/comments, static/imports, static/clones, walked with Options::default() — silently ignoring --include-generated / --include-vendored.
  • --languages was never consumed by static analyzers at all.

Fix

  • New StaticFilter (path policy + language globs) in cf-commands, threaded through every static walk, every format arm (json / text / yaml / compact / bin), multi-analyzer merges, and plot builders. Language globs use basename fnmatch (filepath.Match parity) via cf-langpath.
  • Cobra CSV parity: --languages "" means "no filter" (previously an unknown-language error) — verified byte-identical to the Go oracle.
  • Clones serialization parity: an empty non-nil clone_pairs now emits [] (Go's null is reserved for the nil case) — fixed via Option<Vec<ClonePair>> in cf-clones; all 8 previously divergent oracle cells now PASS.

Part 2 — history phase --languages + oracle-timeout root-cause (folded into this MR)

History --languages filter ported (FIXED, oracle-verified)

Ports Go's TreeDiffAnalyzer.checkLanguage to Rust as HistoryFilter, threaded through every history change-filter site (devs, burndown, anomaly, couples, shotness, file-history, imports, typos, quality, sentiment). Oracle-verified byte-identical for devs/burndown/anomaly/couples across language flagsets. flag:history/devs--languages:Go@hercules now PASSES.

HistoryFilter encodes two Go-history quirks measured against the live oracle:

  • History ignores --include-vendored/--include-generated — the flag channel never reaches the history pipeline (verified on hercules + kubernetes: byte-stable across flag/no-flag). policy is always Options::default().
  • --languages "" (empty value) restricts everything away (total_commits=0), distinct from --languages "all"/absent (no filter). Empty set ≠ no filter — matches Go's empty Languages map rejecting every change via checkLanguage.

Also fixes a latent burndown findLastTick parity bug exposed by language filtering: last_tick is now the max delta-recorded GlobalHistory key (Go findLastTick), not the max walked commit tick (this was the num_samples 1 vs 6 divergence on --languages Python).

6 --include-vendored@hercules oracle-timeout cells (ROOT-CAUSED, evidence-backed; stay RED)

Two layers, both diagnosed:

  1. The frozen-oracle timeout is a Go BUG, not untestability: pkg/uast/parser_dsl.go toCanonicalNode re-walks every unmapped subtree twice (2^depth blowup). A perf-only, output-byte-identical Go patch — the same restructure Rust already landed in cf-uast/src/lowering.rs — makes the oracle complete the cell with a full 5,351,785-byte report (proven byte-identical to the frozen binary on 9 diverse cells). Committed as tests/compat/oracle/patches/uast-unmapped-subtree-rewalk-perf.patch.
  2. The residual divergence is REAL and DELIBERATE on the Rust side: Rust's 64 MiB durability cap skips vendor/gopkg.in/vmarkovtsev/BiDiSentiment.v1/assets/bindata.go (70.5 MB; Go has no such cap and parses it) → 21473 vs Go's 21494 total functions (19 top-level funcs + 2 methods), plus tie-order diffs.

These 6 cells stay RED as tracked_known_failing (via a label_glob covering all 6 static cells). Measuring them in-suite needs an explicit oracle re-bless (tamper_check --bless) plus a policy call on the deliberate durability caps — the explicit remaining follow-up, not something to patch around.

Gate fix

gate.py _match had a tautology: rec.get("kind", entry["kind"]) defaulted the record's kind to the entry's own kind, so a family+kind allowlist entry matched every FAIL in that family (records carry no kind). Now requires an explicit kind match, so the 6 vendor cells correctly fall through to tracked_known_failing (honest RED) instead of being mis-counted as ALLOWED. Also added a go_nondeterminism allowlist entry for flag:static/clones--languages:Go (6 distinct live-Go output SHAs; Go MinHash/LSH map-iteration nondeterminism).

Verification (both parts)

  • Go-oracle sweep: 303 fixture cells (every static analyzer × every format × 8 flag sets + multi-merge + error paths) — clean.
  • History parity: byte-identical for devs/burndown/anomaly/couples across language flagsets.
  • Mutation self-test: the original bug shape re-planted is caught by 3 dispatch-level tests; two other flag-path mutations caught by 5 and 3 tests.
  • New regression coverage: 16 static unit/dispatch tests + 9 history_filter_tests (git2 fixture) and integration tests in crates/cf-commands/tests/flag_parity.rs. 163 workspace suites green.
  • Compat matrix: flag family 63 full cells; gate honest tally — TRACKED_KNOWN_FAILING: 6 (vendor cells stay RED), FAIL (un-allow): 0, ALLOWED: 0.
  • cargo fmt --check ✅ · cargo clippy exit 0 ✅ · cargo test --workspace ✅ (163 suites) · tamper-evidence gate GREEN ✅ · gate.py --tier full honest tally ✅.

Remaining follow-up (not in this MR)

  • Oracle re-bless (tamper_check --bless) to swap in the patched oracle (SHA is fingerprinted) + a durability-cap policy call on the 64 MiB cap — so the 6 vendor cells become economically measurable in-suite.

🤖 Generated with Claude Code

Non-json formats of static/complexity and all of halstead/cohesion/
comments/imports/clones walked with a default path policy, silently
ignoring --include-generated/--include-vendored; --languages was never
consumed by static analyzers at all. On generated-code-heavy repos this
made text/json report divergent totals for identical flags (observed:
2178 vs 18653 total functions on a protobuf-heavy repo).

- Add StaticFilter (path policy + language globs) in cf-commands and
  thread it into every static walk, every format arm, multi-analyzer
  merges, and plot builders; language globs use basename fnmatch
  (filepath.Match parity) via cf-langpath
- Match cobra csv semantics: --languages "" means no filter (was an
  unknown-language error); verified byte-identical to the Go oracle
- Fix clones serialization parity: empty non-nil clone_pairs now emits
  [] (vs Go's null for the nil case), via Option<Vec<ClonePair>
- Add 16 regression tests incl. dispatch-level tests through the real
  registry (mutation self-test verified they catch the shipped bug
  shape), plus integration tests in cf-commands/tests/flag_parity.rs
- Extend compat matrix flag family (flags x formats x analyzers,
  --languages axes): 9 -> 63 cells full tier, 0 -> 8 smoke tier;
  re-bless integrity baseline, refresh result artifacts
- Record the known gap in allowlist (tracked_known_failing): the
  history phase ignores --languages (Go TreeDiffAnalyzer.checkLanguage
  not yet ported); entry stays RED in the gate

Verified against the live Go oracle: 303 fixture-cell sweep clean,
smoke flag family 8/8 PASS, tamper-evidence GREEN.

Co-Authored-By: Claude <noreply@anthropic.com>
@cursor

cursor Bot commented Aug 2, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

…oot-cause oracle timeout

Port the Go history-phase --languages filter (TreeDiffAnalyzer.checkLanguage)
to Rust as HistoryFilter, threaded through every history change-filter site
(devs, burndown, anomaly, couples, shotness, file-history, imports, typos,
quality, sentiment). Oracle-verified byte-identical for devs/burndown/anomaly/
couples across language flagsets.

HistoryFilter encodes two Go-history quirks measured against the live oracle:
  * The history phase IGNORES --include-vendored/--include-generated (the flag
    channel never reaches the history pipeline; verified on hercules +
    kubernetes: byte-stable across flag/no-flag). policy is always Options::default().
  * --languages "" (empty value) restricts everything away (total_commits=0),
    distinct from --languages "all" / absent (no filter). Empty set != no filter.

Also fixes a latent burndown findLastTick parity bug exposed by language
filtering: last_tick is now the max delta-recorded GlobalHistory key (Go
findLastTick), not the max walked commit tick.

Root-cause the 6 --include-vendored@hercules static oracle-timeout cells:
  (1) The frozen-oracle timeout is a Go BUG (pkg/uast/parser_dsl.go
      toCanonicalNode re-walks every unmapped subtree twice, 2^depth blowup).
      A perf-only, output-byte-identical Go patch (the same restructure Rust
      landed in cf-uast/src/lowering.rs) makes the oracle complete the cell —
      committed as oracle/patches/uast-unmapped-subtree-rewalk-perf.patch.
  (2) The residual divergence is REAL and DELIBERATE: Rust's 64MiB durability
      cap skips vendor/.../bindata.go (70.5MB; Go has no cap) = 21473 vs 21494
      total functions. Cells stay RED pending an oracle re-bless + a durability-
      cap policy call — recorded as tracked_known_failing (label_glob covers all
      6 static cells).

Fix a gate.py _match tautology (rec.get("kind", entry["kind"]) defaulted the
record's kind to the entry's own kind, letting a family+kind entry swallow every
FAIL in that family). Records carry no kind; require an explicit match so the
6 vendor cells fall through to tracked_known_failing (honest RED) instead of
being mis-counted as ALLOWED.

Add go_nondeterminism allowlist entry for flag:static/clones--languages:Go
(6 distinct live-Go output SHAs; Go MinHash/LSH map-iteration nondeterminism).

Tests: +117 cf-commands lib tests incl. 9 history_filter_tests (git2 fixture),
flag_parity integration, 163 workspace suites green. Gate honest: 6 tracked
(still RED), 0 un-allowlisted FAIL.

Co-Authored-By: Claude <noreply@anthropic.com>
@dmytrogajewski dmytrogajewski changed the title fix(static): thread static flags into every analyzer and output format fix(static+history): flag/language filters for every analyzer; root-cause oracle timeout Aug 2, 2026
@dmytrogajewski
dmytrogajewski merged commit f54f1bb into main Aug 8, 2026
2 checks passed
dmytrogajewski pushed a commit that referenced this pull request Sep 22, 2026
The aggregate-int test helper in `mod history_filter_tests` (added by
f54f1bb / #26) carries two clippy findings that the advisory CI Clippy
step never failed on, but that `make lint` (`clippy --all-targets --
-D warnings`) does:

  * clippy::useless_format -- format!(r#""aggregate":{{"#) has no
    placeholders, so the brace escape was both pointless and a latent
    trap for whoever edits the literal next;
  * clippy::needless_borrows_for_generic_args -- once the literal is a
    &str, `json.find(&agg)` borrows a value that already satisfies the
    Pattern bound.

Both are test-only code paths; behaviour is unchanged. Verified with
`make lint`, `make deadcode`, `cargo fmt --all -- --check` (all clean)
and `make test` (2480 passed, 0 failed).
dmytrogajewski added a commit that referenced this pull request Sep 24, 2026
#28)

* fix(history): make --limit select the newest commits and --since work

`--limit N` streamed the N OLDEST commits, inherited from the retired Go
reference's `initStreamingIterator` (`logOpts.Reverse = true` + CollectN).
Measured on the pinned reference binary: `--limit 3` on kubernetes emits
`2c4b3a562ce3` (2014-06-06) -- the repository's first commits -- and the same
bytes are frozen in tests/golden/run/burndown.ndjson. No user means "the ten
first commits ever made" when they type `--limit 10`.

A partial `--since` window was worse: the planner counted the in-window
commits, then the oldest-first loading pass applied the author-time stop filter
and stopped at the first too-old commit, so the run aborted with
`expected N commits, got 0: EOF`, empty stdout, exit 1 -- the documented
`--since 2025-01-01` path never worked.

Both bounds are now taken from ONE newest-first pass (cap at `--limit`, then
reverse to the chronological order the analyzers require), which deletes the
planner/loader two-pass and the abort. `--since` additionally gains git
revision specs (`v1.2.0`, `HEAD~100`, a SHA) and CODEFANG_NOW-aware durations
by sharing cf-gitlib's single parser; the CLI's duplicate ~130-line parser is
deleted, not adapted. An unresolvable spec now reports
`Error: cannot resolve --since "<value>"` instead of the generic tier-8
dispatch placeholder (same rc=1, still no stdout).

Commits are still delivered oldest-first, so tick, burndown line survival and
identity semantics are unchanged -- only the selected window moves.

This is a deliberate divergence from the retired reference: superseded
`--limit`-bounded captures are annotated (not recaptured) in
tests/golden/MANIFEST.json and tests/compat/matrix.toml. The `cf-gitlib`
`testutil` feature its module docs already promised makes the deterministic
fixture repo usable from these tests.

See specs/frds/FRD-newest-commit-window.md.

Tests: 10 unit (`history_window_tests`) + 7 CLI-level e2e
(`bins/codefang/tests/history_window.rs`) driving the real binary over a real
repo, incl. the `--head` == `--limit 1` byte-identity invariant. Written
red-first against the old behavior. `make test`: 2455 passed, 0 failed.

* chore(quality): add the make lint / make deadcode gates and clear their backlog

AGENTS.md mandates both gates, but neither target existed -- and `cargo clippy`
could not pass anyway: it failed on deny-by-default lints (clippy::approx_constant
in cf-reportutil, cf-gojson and cf-goyaml; clippy::never_loop in bins/uast), so
the two pre-flight PR checkboxes were untickable by construction.

- Makefile: `lint` (clippy --workspace --all-targets -- -D warnings) and
  `deadcode` (RUSTFLAGS="-D dead_code" cargo check --workspace --all-targets).
  The limitation of the latter -- rustc treats any `pub` item in a library crate
  as reachable, so it proves "no private code is unreachable", not "no exported
  function is unused" -- is documented at the target instead of glossed over.
- Clear the workspace clippy backlog with real simplifications where the lint is
  right (single_match -> if let, if_not_else, get().is_none() -> assert against
  None, field_reassign_with_default -> struct update syntax, redundant closure,
  a no-op `& 0xFF` after `as u8`, doc backticks), and documented `#[allow]`s
  only where the flagged literal is a captured Go reference fixture: substituting
  f64::consts::PI for `3.14`/`3.14159` there would change the fixture under test,
  not the style. bins/uast's `for filename in files` could never iterate twice
  (it returns on the first pass while grammar wiring is pending), so it is now an
  explicit first-file bail with identical sentinel strings.
- cf-uast: drop the never-read `InitState.rule_index` field. The local is still
  used for rule resolution; the map no longer stays alive inside every parser's
  init state.

`make lint` and `make deadcode` both exit 0. The changelog entry for this work
landed with the previous commit. No behavior or output-byte change: the
workspace test suite is unchanged at 2455 passed / 0 failed.

* style: rustfmt the history-window tests and handler

CI's `Format check` step (`cargo fmt --all -- --check`) is a hard gate, and the
two files the previous commits added/extended were not rustfmt-clean. `main` was
clean, so `cargo fmt --all` touched only these two files -- verified before
committing. Behavior is unchanged: `cargo fmt --all -- --check` exits 0 and
`make test` is still 2455 passed / 0 failed.

* chore(quality): clear clippy debt introduced by #26

The aggregate-int test helper in `mod history_filter_tests` (added by
f54f1bb / #26) carries two clippy findings that the advisory CI Clippy
step never failed on, but that `make lint` (`clippy --all-targets --
-D warnings`) does:

  * clippy::useless_format -- format!(r#""aggregate":{{"#) has no
    placeholders, so the brace escape was both pointless and a latent
    trap for whoever edits the literal next;
  * clippy::needless_borrows_for_generic_args -- once the literal is a
    &str, `json.find(&agg)` borrows a value that already satisfies the
    Pattern bound.

Both are test-only code paths; behaviour is unchanged. Verified with
`make lint`, `make deadcode`, `cargo fmt --all -- --check` (all clean)
and `make test` (2480 passed, 0 failed).

---------

Co-authored-by: Dmitriy <dmit8815@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants