Skip to content

galaxyscope popularity tally: a bare filename import raises popularity on every same-stemmed file in the repo, unscoped by language or directory (#2540's shape, in the tally instead of the DAG) #2684

Closed

Description

@squid-protocol

Found while measuring the golden-master diff for #2668/#2652 (Batch C.2 of #2669). Not caused by
that PR
-- the PR only made yacc reach a code path c/cpp have always reached.

What happens

galaxyscope.py's Pass-1.5 popularity tally (~L1900) ends its stem fallback with:

guess_stem = Path(clean_path).stem.lower()
if guess_stem in stem_to_paths and guess_stem not in stop_stems and len(guess_stem) >= 3:
    for target_path in stem_to_paths[guess_stem]:
        if clean_path in target_path or guess_stem == clean_path or "/" not in clean_path:
            self.popularity_scores[target_path] += 1

The third clause -- "/" not in clean_path -- is true for every bare filename import, so a
token like parser.h credits popularity to every file in the scan whose stem is parser, in any
directory, in any language. stem_to_paths is built over the whole scan with no language or
directory scoping.

This is the same class of defect as #2540, which found haskell's import Text.Pandoc.Generic
folding onto go's generic.go. That fix scoped the DAG resolver's folded map per language.
The tally was never scoped, and it is the tally -- not the DAG -- that feeds the Contextual
Baseline Fix (galaxyscope.py ~L2169: popularity > 0 converts orphaned_logic into api and
wipes the debt).

Evidence

cobol/gnucobol_internals/scanner.l in language-crucible carries #include "parser.h". There is
no parser.h anywhere in the corpus, so the stem fallback fires on stem parser and credits five
files in five unrelated repositories, each of which then had its orphan debt converted to API
surface:

file Orphaned Logic Exposed API
typescript/assemblyscript/parser.ts 4 -> 0 7 -> 11
perl/spamassassin/Parser.pm 8 -> 0 1 -> 9
php/symfony/Parser.php 3 -> 0 13 -> 16
zig/bun/Parser.zig 3 -> 0 11 -> 14
cobol/gnucobol_internals/parser.y 1 -> 0 1 -> 2

Group-level fallout in the same scan: php/symfony avg tech debt 41.35 -> 38.38,
perl/spamassassin api_exposure 0.08 -> 0.12.

Why it is pre-existing, not new

The tally iterates raw_imports for every file regardless of language, and c/cpp's
_dependency_capture produces exactly this token shape (#include \"foo.h\") all over the corpus
already. #2668's PR is only the first time a yacc/flex file contributed one, which is why it
surfaced there.

Severity

In a single real repository the fuzzy bare-filename match is defensible and probably intended --
#include \"parser.h\" next to parser.c should credit it. The failure mode is cross-directory and
cross-language collision on a generic stem, and stop_stems only guards a hand-written list
(text, type, types, ...) with a len >= 3 floor; parser, config, utils, client,
server, main are not in it.

Fix shape (unimplemented; needs a T1 design call)

Options, cheapest first:

  1. Require the bare-filename clause to also agree on language family (the importing file's
    language, or the target's extension being one that language can include). Mirrors fortran USE targets resolve case-sensitively in the dependency DAG (uppercase legacy style loses the whole import graph) #2540's
    scoping decision.
  2. Prefer a same-directory / nearest-ancestor candidate when several files share the stem, and
    only fall back to the corpus-wide credit when exactly one candidate exists.
  3. Extend stop_stems, which does not fix the class -- it only moves the boundary.

Any of these moves golden masters (the five rows above at minimum), so it is a bless-bearing
change and belongs in its own PR, not bundled with #2668.

Related: #2540 (same shape, DAG side), #2652 (why the tally matters -- it gates orphan->api
conversion), #2669 Batch C.

Activity

  1. added
    bug
    core-engine
    on Sep 3, 2026
  2. added a commit that references this issue on Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcore-engine

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions