Skip to content

Pin internal_discriminator and shebang resolution order for contested extensions #3118

Closed

Description

@squid-protocol

Found by a design review of the language-detection cascade (gitgalaxy/standards/language_lens.py). Claimant tables below were produced by sweeping LANGUAGE_DEFINITIONS on origin/main (2fa685e).

The problem

Both content-evidence loops in _tier_2_fingerprint_check are first-match-wins over self.languages.items(), so LANGUAGE_DEFINITIONS insertion order silently arbitrates ties:

Nothing asserts the intended order. Reordering the registry, or adding a language mid-list, can change classification with no test failing.

Where order is load-bearing right now

Sweeping the 13 COLLISION_FREQUENCIES extensions on main for discriminator-bearing claimants (D = declares an internal_discriminator, listed in registry order):

ext claimants (registry order) order load-bearing?
.cmd batch D, rexx D yes — 2 discriminators
.m matlab D, objective-c D yes — 2 discriminators
.py python D, embedded_python D yes — 2 discriminators
.asm assembly -, hlasm D no (single)
.sql / .ddl / .dml sqlite -, db2_sql D no (single)
.h c -, objective-c D no (single)
.y c -, yacc D no (single)
.map bms D no (single)
.inc cpp -, c -, php -, fortran -, assembly - no (none)
.c c - no (none)
.cshtml csharp -, html - no (none)

Three extensions have multiple discriminator-bearing claimants, not two: .cmd joined the list when rexx landed (#2504/#3107), and it is simultaneously the worked precedent for why this matters. batch.py documents the dependency in a comment:

Collision resolution for .cmd (#2504: rexx claims it too, and batch's … registry order checks batch's discriminator FIRST, so a false batch hit on real REXX would lock the …)

That ordering requirement exists only as a comment, not as an assertion. The .m and .py pairs have no statement of intended precedence at all.

Ask

A test in tests/core_engine/ that, for every COLLISION_FREQUENCIES extension, pins the claimant list in registry order and asserts the intended winner for a realistic sample of each claimant's content. Adding or reordering a language then surfaces as an explicit, reviewable test change rather than a silent behavior change.

Include the shebang trigger table from #3116 in the same pin once #3116 is fixed — the basename-matching fix replaces substring-vs-registry-order with a deterministic rule, and that rule is worth pinning at the same time.

Note for the implementer: the claimant list should be derived from the registry at test time and compared against a committed expectation, not hand-copied — otherwise the test drifts from the registry it is supposed to guard.

Related

Siblings from the same review: #3116 (the shebang half of this first-match-wins problem, a live defect) and #3117 (the broader detection-accuracy harness — this issue is the narrower, cheaper guard over the collision subset).

Activity

  1. added
    enhancement
    testing
    core-engine
    on Sep 17, 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

    core-engineenhancementtesting

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions