Skip to content

fix(co-occurrence): clone gate vacuous on .mts/.mjs — CODE_EXT dropped module-suffixed extensions - #305

Merged
norvalbv merged 1 commit into
mainfrom
fix/clone-gate-mts-vacuous
Aug 2, 2026
Merged

fix(co-occurrence): clone gate vacuous on .mts/.mjs — CODE_EXT dropped module-suffixed extensions#305
norvalbv merged 1 commit into
mainfrom
fix/clone-gate-mts-vacuous

Conversation

@norvalbv

@norvalbv norvalbv commented Aug 2, 2026

Copy link
Copy Markdown
Owner

The bug (gate integrity hole, flagged by the opus reviewer during #303's gates)

guard-clone scan reported 0 clones repo-wide while raw jscpd found real ones. Root cause: the post-filter CODE_EXT = /\.(tsx?|jsx?)$/ kept only .ts/.tsx/.js/.jsx — but devkit's own cloneRoots (inherited from scanRoots = ["cli", "gate-engine"]) are pure .mts. jscpd tokenizes mts/cts as typescript and mjs/cjs as javascript and duly reported the clones; the filter then discarded every one. The gate has been silently dead on this repo (and any .mts/.mjs consumer) since it shipped — the allowlist has zero clone entries because nothing ever surfaced.

The fix

  • CODE_EXT/\.([cm]?[tj]s|[tj]sx)$/ (adds .mts .cts .mjs .cjs, exactly the extensions jscpd tokenizes).
  • Regression tests: .mts and .mjs cross-file clone fixtures must block (exit 1). All 28 detector tests pass; full suite green (182 files / 3087 tests). Empirical repro: identical fixture pair → 1 clone as .ts, 0 as .mts before the fix; 1/1 after, .ts unchanged.

What it surfaces (heads-up, not part of this PR)

Repo-wide scan now reports 62 cross-file clones (min-tokens 50), dominated by the review/eval vs review/eval/conventions bench+matcher family (~20 clones — the conventions eval harness is a copy) plus a 23-line sync-agents/sync-skills block. Once a release wires the fixed gate into hooks, commits touching those files will block until each clone is fixed or approved. The designed migration path already exists:

guard-clone json | guard-dup-allowlist baseline-clones

freezes the pre-existing clones as decaying baseline entries (same pattern as the matcher baseline burndown). Preference order: dedupe the copied eval harness (real DRY debt), baseline the rest. No baseline is pre-seeded here — running it is a repo-owner call.

🤖 Generated with Claude Code

…d module-suffixed extensions

The post-filter kept only .ts/.tsx/.js/.jsx, but devkit's own scanRoots (cli,
gate-engine) are pure .mts — jscpd tokenizes mts/cts as typescript and mjs/cjs
as javascript and reported the clones, then CODE_EXT discarded every one.
`guard-clone scan` returned 0 repo-wide while raw jscpd found real clones
(verified during #303's gates): a silently dead gate.

With the fix the same scan reports 62 cross-file clones (min-tokens 50),
dominated by the review/eval vs review/eval/conventions bench+matcher family.
Regression tests: .mts and .mjs clone fixtures must block (exit 1).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@norvalbv, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 18 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f0fccf64-91a2-47c6-94ac-2d2305061db2

📥 Commits

Reviewing files that changed from the base of the PR and between 41348e6 and a4ada11.

📒 Files selected for processing (2)
  • gate-engine/co-occurrence/__tests__/clone-detector.test.mts
  • gate-engine/co-occurrence/clone-detector.mts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@norvalbv
norvalbv merged commit 46e97df into main Aug 2, 2026
1 of 2 checks passed
norvalbv added a commit that referenced this pull request Aug 2, 2026
…at the tokenizer

Two modules using the same shared libs are forced into identical, linter-sorted
import blocks — the module system working, not copy-paste debt — and a big
enough preamble clears jscpd's 50-token floor on its own, false-blocking any
commit touching sibling files once the gate is wired into hooks (post-#305 the
repo scan showed two such blocks).

Imports are now removed from the token stream itself via jscpd
--ignore-pattern (four bounded, comma-free regexes: named/multi-line,
default/namespace single-line, side-effect, re-export barrels; dynamic
import(...) deliberately matches none). The semantic becomes "clones are
measured over non-import code": nothing can ride a preamble over the token
floor, and nothing real can hide behind one.

A post-hoc fragment classifier was tried first and abandoned after six
opus-confirmed reviewer holes across seven gate rounds (ratio leaks, dynamic
import absorption, quote-terminated statements, import attributes, ...) — each
patch surfaced the next hole because classifying jscpd's token-boundary
fragments after the fact is unfixable by construction. The adversarial cases
live on as end-to-end gate-contract tests: preamble-only pair passes, a real
body behind identical imports still blocks, a duplicated dynamic-import block
still blocks. Live scan 62 -> 60; the dropped sync-agents fragment's residual
interface dup is sub-floor on its own merits (it only crossed 50 tokens by
riding the imports).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
norvalbv added a commit that referenced this pull request Aug 2, 2026
…clone-gate ruling (#310)

benchmarks-grow-from-telemetry gains its convergence record before the release
that ships it: capture loop closed end-to-end (#295/#302/#303/#309, first 8
pure-telemetry rows, corpus 128), label-trust precondition met (#304: κ 0.735
post-triage, 4.2% noise floor; cleanlab floor still pending bench pred_probs),
and the Target's c-CRAB/CR-Bench known-answer path recorded as falsified
(#307) with the replacement candidates awaiting ratification.

New axis clone-gate-non-import-code ([VALIDATED]): clones are measured over
non-import code, excluded at the jscpd tokenizer — with the six-hole failure
of post-hoc fragment classification recorded as the rejected road so a future
simplifier can't silently re-vacuous the gate (#305/#308).

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
norvalbv added a commit that referenced this pull request Aug 2, 2026
…rerequisite (sc-1414) (#311)

The repaired clone gate (#305/#308) goes live in consumer hooks at the next
release; without a baseline every commit touching a cloned file blocks on
debt that predates the gate working. `guard-clone json | guard-dup-allowlist
baseline-clones` freezes all 60 as decaying baseline entries (the matcher
baseline burn-down pattern).

Disposition choice: baseline ALL 60, not just the 43 eval-harness clones —
leaving the 16 product clones unbaselined would block unrelated commits
touching those files before the dedup work (sc-1414 part 2) lands. Baseline
entries decay, so the product clones resurface on schedule; the eval-harness
family stays frozen deliberately (deduping it would drift published
runner/scorer checkpoint hashes for 2-3 suites — the overrides.mts precedent),
as does the deliberate run-review<->bench mirror. Gate verified clean after:
scan --gate exit 0.

Co-authored-by: Claude Fable 5 <noreply@anthropic.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.

1 participant