Repository navigation
fix(core-engine): a bare filename import must not credit every same-stemmed file in the scan (#2684) - #2687
Merged
Conversation
…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]>
Contributor
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]>
24 of 27 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2684. Found while attributing gitgalaxy#2685's golden-master diff.
The defect
_resolve_dependency_graph's popularity tally ends its stem fallback with: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 > 0convertsorphaned_logicintoapiand 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:
cobol/gnucobol_internals/codegen.ccodegen.zigjavascript/threejs/Editor.jseditor.cssphp/symfony/EventDispatcher.phpEventDispatcher.jsperl/spamassassin/HTML.pmHTML.hcobol/che-che4z.../BASIC.cblbasic.dartdockerfile/moby/.../windows.Dockerfile#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:
COPY SQLCAnames no file type — 66 suchcredits are deliberately left alone),
That precision is the whole argument for it.
.hmaps to c/cpp/objective-c and.yto c/yacc, soa header still credits its own language's sources — including the exact case this was found
through: gnucobol's
scanner.lincludingparser.hkeeps crediting that repo's ownparser.y,while the four cross-language
Parser.*victims in unrelated repos lose it. Fixing the collisionwithout breaking the legitimate credit sitting right next to it was the design constraint.
javascript/typescriptare declared interchangeable because TypeScript's ESM imports name theemitted file —
import "./lifecycle.js"resolving tolifecycle.tsis the documented norm, not astem collision. vscode exercises it and the first cut of this guard broke it.
Verification
audit_checkall clear; tree-sitter 30/30, tri-comparison 3/3.origin/main(including every row of the cross-languagetable), so they gate the regression rather than describe it.
ext_tally, orfoo.his rewritten tofoo/hbefore 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 Rankdoes not move at all (that column is the network sensor'sin_degree, a differentquantity 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 → 368by hand for the pure line shift, message text untouched. Notregenerated: this venv is full-precision, and
mypy_audit.py's own docstring records thatregenerating outside CI's lean environment silently produced a baseline that passed locally and
failed in CI (PR #436).
🤖 Generated with Claude Code