Skip to content

fix(core-engine): a bare filename import must not credit every same-stemmed file in the scan (#2684) - #2687

Merged
squid-protocol merged 2 commits into
mainfrom
fix/2684-tally-extension-guard
Sep 3, 2026
Merged

squid-protocol merged 2 commits into
mainfrom
fix/2684-tally-extension-guard

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Closes #2684. Found while attributing gitgalaxy#2685's golden-master diff.

The defect

_resolve_dependency_graph's popularity tally ends its stem fallback with:

if clean_path in target_path or guess_stem == clean_path or "/" not in clean_path:
    self.popularity_scores[target_path] += 1

That third clause is true of every bare filename, so one import token credits every file in the
scan sharing its stem — unscoped by language, directory or repository. And because it is this tally,
not the DAG, that gates the Contextual Baseline Fix (popularity > 0 converts orphaned_logic into
api and wipes the debt), each bogus credit also rewrote a file's risk profile.

Measured over language-crucible: 203 credits came from that clause alone, 136 of them (67%)
crossing a repository boundary.
A sample of what that means in practice:

file whose orphan debt was wiped was credited by
cobol/gnucobol_internals/codegen.c zig's codegen.zig
javascript/threejs/Editor.js vscode's editor.css
php/symfony/EventDispatcher.php three.js's EventDispatcher.js
perl/spamassassin/HTML.pm WorldWideWeb's Objective-C HTML.h
cobol/che-che4z.../BASIC.cbl Flutter's basic.dart
dockerfile/moby/.../windows.Dockerfile C++ #include <windows.h>

This is #2540's defect one layer over: that issue fixed cross-language stem collisions in the DAG
resolver's folded map; the tally was never scoped.

The guard

If a token names an extension, that extension says which languages the target can be written in —
so a candidate whose own extension shares no language with it is not the file being imported,
whatever its stem says.

Deliberately permissive at both edges, so it fires only on a positive contradiction:

  • a token with no extension is untouched (COBOL's COPY SQLCA names no file type — 66 such
    credits are deliberately left alone),
  • an extension the registry does not know is untouched.

That precision is the whole argument for it. .h maps to c/cpp/objective-c and .y to c/yacc, so
a header still credits its own language's sources — including the exact case this was found
through
: gnucobol's scanner.l including parser.h keeps crediting that repo's own parser.y,
while the four cross-language Parser.* victims in unrelated repos lose it. Fixing the collision
without breaking the legitimate credit sitting right next to it was the design constraint.

javascript/typescript are declared interchangeable because TypeScript's ESM imports name the
emitted file — import "./lifecycle.js" resolving to lifecycle.ts is the documented norm, not a
stem collision. vscode exercises it and the first cut of this guard broke it.

Verification

  • Full suite 7471 passed; audit_check all clear; tree-sitter 30/30, tri-comparison 3/3.
  • 7 strict tests, of which 4 fail on origin/main (including every row of the cross-language
    table), so they gate the regression rather than describe it.
  • Worth recording: the test harness must populate ext_tally, or foo.h is rewritten to foo/h
    before the stem stage is ever reached — the negative cases then pass for entirely the wrong
    reason. The first version of these tests did exactly that.

Golden master — 214 diffs, NOT blessed here

Popularity Rank does not move at all (that column is the network sensor's in_degree, a different
quantity from the tally). The substantive movement is 12 files whose orphan→API conversion is
reversed
, each individually attributed to the single cross-language credit it loses — the table
above is that attribution. Everything else is the coordinate ripple and the group/global aggregates
downstream of those 12.

The direction is a visible "regression" that is actually a correction: tech debt goes up on
those 12 files, because they were never really imported by anything.

Awaiting a bless go-ahead — not taken on my own authority.

mypy baseline

One key rekeyed 320 → 368 by hand for the pure line shift, message text untouched. Not
regenerated: this venv is full-precision, and mypy_audit.py's own docstring records that
regenerating outside CI's lean environment silently produced a baseline that passed locally and
failed in CI (PR #436).

🤖 Generated with Claude Code

…file (#2684)

`_resolve_dependency_graph`'s popularity tally ends its stem fallback with
`"/" not in clean_path`, which is true of EVERY bare filename, so a single
import token credited every file in the scan sharing its stem -- unscoped by
language, directory or repository. Because that tally (not the DAG) gates
galaxyscope's Contextual Baseline Fix, each bogus credit also converted a
file's orphaned logic into API surface and wiped its tech debt.

Measured over language-crucible before the fix: 203 credits came from that
clause alone and 136 of them (67%) crossed a repository boundary. The
fallout is not subtle -- zig's `codegen.zig` credited gnucobol's `codegen.c`,
vscode's `editor.css` credited three.js's `Editor.js`, three.js's
`EventDispatcher.js` credited symfony's `EventDispatcher.php`, Flutter's
`basic.dart` credited a COBOL `BASIC.cbl`, and `#include <windows.h>` from
C++ credited a `windows.Dockerfile`.

The guard: if an import token names an extension, that extension says which
languages the target can be written in, so a candidate whose own extension
shares no language with it is not the file being imported, whatever its stem
says. Permissive at both edges -- a token with no extension is left alone
(COBOL's `COPY SQLCA` names no file type) and so is any extension the
registry does not know -- so it fires only on a positive contradiction.

That precision is what makes it safe: `.h` maps to c/cpp/objective-c and
`.y` to c/yacc, so a header still credits its own language's sources,
including the real generated-parser case this was found through --
gnucobol's `scanner.l` including `parser.h` keeps crediting that repo's own
`parser.y`, while the four cross-language `Parser.*` victims in unrelated
repos lose it.

javascript/typescript are declared interchangeable because TypeScript's ESM
imports name the *emitted* file: `import "./lifecycle.js"` resolving to
lifecycle.ts is the documented norm, not a stem collision. vscode exercises
it, and the first cut of this guard broke it.

The strict tests fail on origin/main (4 of them, including every row of the
cross-language table). One trap they cover: the harness must populate
`ext_tally`, or `foo.h` is rewritten to `foo/h` before the stem stage is
reached and the negative cases pass for entirely the wrong reason.

mypy baseline entry rekeyed 320 -> 368 by hand for the pure line shift --
NOT regenerated, because this venv is full-precision and the audit's own
docstring records that regenerating outside CI's lean env silently produced
a baseline that passed locally and failed in CI (PR #436).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

214 differences in each fixture, regenerated with `crucible_check.py
--update --yes` (user-authorised). The zero-dep diff is byte-identical to
the one measured and attributed before the bless.

The only `7. Structural Signatures` columns that move are `Orphaned Logic`
and `Exposed API / Public Exports`, on the same 12 files -- these are
outputs of the Contextual Baseline Fix, not counts of anything extracted.
`Popularity Rank` does not move at all: that column reports the network
sensor's in_degree, a different quantity from the tally this fixes.

Each of the 12 is attributed to the single cross-language credit it loses:

  cobol/gnucobol_internals/codegen.c   <- zig's codegen.zig
  javascript/threejs/Editor.js         <- vscode's editor.css
  php/symfony/EventDispatcher.php      <- three.js's EventDispatcher.js
  php/symfony/Parser.php               <- a cobol flex file's parser.h
  php/magento2/Http.php                <- objective-c's HTTP.h
  perl/spamassassin/Parser.pm          <- the same parser.h
  perl/spamassassin/HTML.pm            <- objective-c's HTML.h
  typescript/assemblyscript/parser.ts  <- the same parser.h
  zig/bun/Parser.zig                   <- the same parser.h
  shell/serenity/package.sh            <- zig's Package.zig
  cobol/.../BASIC.cbl                  <- Flutter's basic.dart
  dockerfile/moby/.../windows.Dockerfile <- C++ #include <windows.h>

Tech debt rises on all 12, which is the correction, not a regression: none
of them was ever imported by the file that was crediting it. The legitimate
neighbour survives -- gnucobol's own parser.y keeps the credit from the
scanner.l in the same repo, and is absent from this list.

Everything else in the 214 is coordinate ripple and the group/global
aggregates downstream of those 12.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@squid-protocol
squid-protocol merged commit 77a46ec into main Sep 3, 2026
29 checks passed
@squid-protocol
squid-protocol deleted the fix/2684-tally-extension-guard branch September 3, 2026 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant