Skip to content

fix(#2988): cross-language import edge corrupts popularity / risk vectors (not a race) - #3001

Merged
squid-protocol merged 2 commits into
mainfrom
fix/2988-unreferenced-determinism
Sep 13, 2026
Merged

squid-protocol merged 2 commits into
mainfrom
fix/2988-unreferenced-determinism

Conversation

@squid-protocol

@squid-protocol squid-protocol commented Sep 13, 2026 •

Copy link
Copy Markdown
Owner

Closes #2988.

The issue's hypothesis was wrong — it's not a multi-worker race

I ran the confirmation the issue asked for (single-worker re-scan of 2dfe421a6/e1f65937a9) and the "corrupted" child values reproduce deterministically with one worker (4/4 runs stable):

state_unref risk_api_exposure risk_tech_debt
parent (single-worker) 3 2.4495 41.2713
child (single-worker) 0 13.9454 0.0

No concurrency involved.

Actual root cause: a cross-language import edge

_calc_api_exposure is pure over {api, encapsulation, total_loc, popularity}; the math shows the only differing input is popularity (parent hit the popularity==0 branch → ×0.2; child hit popularity==1 → ×1.14). That same popularity>0 also fires the Contextual Baseline Fix that wipes state_unreferenced 3→0 / tech_debt→0.

base64.c is a .c file — nothing #includes it. Its spurious popularity=1 in the child comes from tests/http/testenv/certs.py, which the child commit gave an import base64 (Python stdlib). The resolver's FAST PATH 1 exact-matched the extensionless token 'base64' against the extensionless suffix key, which lumps every same-stemmed file across languages — and FAST PATH 1, unlike the #2684 stem fallback, had no language guard. So Python's import base64 credited curl's C lib/curlx/base64.c.

(base64 is referenced by 22 files in both commits; the diff touches only wolfssl/vquic-tls/tests — the flip was purely the newly-added Python import base64.)

Fix

Verified

  • base64.c now reports state_unreferenced=3, risk_api_exposure=2.4495, risk_tech_debt=41.2713 identically across both commit pairs — the "impossible delta" is gone.
  • 989 resolver/network/import tests pass; new regression test (test_resolver_rejects_cross_language_extensionless_import) passes; full suite 8798 passed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HqtNR72fsoL5g57yBBYGX3


Follow-on (golden crucible)

Regenerating the Golden Crucible baseline surfaced a second determinism bug: typosquat anchor selection iterated a set, so a token equidistant from two anchors recorded mimics <anchor> differently per run (string: → string vs strings). Fixed by iterating sorted(candidates). Both golden masters (full-precision + zero-dependency) regenerated against the fixed engine (api_exposure↓ / tech_debt↑ from removing spurious cross-language edges; typosquat_hits 11→13 as previously-masked externals now reach the check). Both legs pass deterministically (2/2 local runs each).

…risk vectors

`state_unreferenced` (→ risk_tech_debt) and risk_api_exposure appeared
non-deterministic on curl's lib/curlx/base64.c across byte-identical scans. Root
cause is NOT a multi-worker race (reproduces deterministically single-worker): a
bare `import base64` (Python stdlib) in tests/http/testenv/certs.py resolved to
curl's C `lib/curlx/base64.c` via the resolver's FAST PATH 1 — the extensionless
token "base64" exact-matches the extensionless suffix key, which lumps every
same-stemmed file across languages. FAST PATH 1 (unlike the #2684 stem fallback)
had no language guard, so the spurious Python→C edge gave base64.c popularity=1,
firing the Contextual Baseline Fix (wiping unreferenced_by_name 3→0, tech_debt→0)
and flipping _calc_api_exposure's network multiplier (2.4495→13.9454).

- galaxyscope: guard FAST PATH 1 by the IMPORTING file's extension via the
  existing _extensions_can_name_the_same_file (#2684), and extend the stem
  fallback's guard to fall back to the importer extension when the token itself
  is extensionless (bare module imports carry no extension, so the token-ext
  guard alone can't catch the cross-language case). A .py import can no longer
  credit a .c file.
- galaxyscope: add GALAXYSCOPE_MAX_WORKERS env override (pin worker count / force
  serial extraction) — used to confirm this is deterministic, not a race.
- tests: regression test (Python `import base64` must not credit C base64.c;
  same-language bare import still resolves); allowlist the new env var in the
  dead-key auditor (os.environ.get, not a repo-produced dict).

Verified: base64.c now reports state_unreferenced=3, risk_api_exposure=2.4495,
risk_tech_debt=41.2713 identically across both curl commit pairs. Full suite:
8798 passed.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HqtNR72fsoL5g57yBBYGX3
@squid-protocol squid-protocol changed the title fix(#2988): stop cross-language import edges corrupting popularity / … fix(#2988): cross-language import edge corrupts popularity / risk vectors (not a race) Sep 13, 2026
@squid-protocol
squid-protocol marked this pull request as draft September 13, 2026 20:12
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

…asters

Follow-on to the cross-language resolver fix. Two things surfaced by regenerating
the Golden Crucible baseline:

1. Typosquat anchor selection was non-deterministic: the candidate anchors were
   iterated as a set and the loop breaks on the first within-threshold match, so a
   token equidistant from two anchors recorded "mimics <anchor>" differently across
   runs (e.g. 'string:' -> 'string' vs 'strings'). Iterate sorted(candidates) so the
   first qualifying anchor is stable. (Same determinism class as the main fix; it
   became reachable because the resolver fix correctly reclassifies some
   previously-internal imports as external, so more tokens reach the typosquat check
   -- typosquat_hits 11 -> 13 on the crucible corpus.)
2. Regenerated tests/golden_master_audit.json and tests/golden_master_zero_dep_audit.json
   against the fixed engine. The drift is the intended effect of removing spurious
   cross-language popularity edges: api_exposure drops and tech_debt rises in lockstep
   across the same-stemmed cross-language corpus (e.g. rust/syn api 18.71->11.77 /
   debt 48.54->51.36). Both legs regenerated in their own venv with
   GITGALAXY_DISABLE_GIT_HISTORY=1 (matches the test); both pass deterministically (2/2).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HqtNR72fsoL5g57yBBYGX3
@squid-protocol
squid-protocol marked this pull request as ready for review September 13, 2026 20:40
@squid-protocol
squid-protocol merged commit 5409f82 into main Sep 13, 2026
29 checks passed
@squid-protocol
squid-protocol deleted the fix/2988-unreferenced-determinism branch September 13, 2026 20:40
squid-protocol added a commit that referenced this pull request Oct 4, 2026
…porter's language (part of #4265)

The #3199 language rule for source-member imports (COBOL COPY, PL/I %INCLUDE,
HLASM COPY) ran only when several files matched. A single match in another
language was taken. Examples: COBOL `COPY A` -> A.hlasm (che4z lsp fixtures),
DSF PL/I `%INCLUDE DFHBMSCA` -> carddemo's COBOL copybook, and zopeneditor
PSAM1LIB.pli -> COBOL DATETIME.cpy / REPTTOTL.cpy. This is the same class as
#3001's Python `import base64` -> base64.c.

A BMS mapset stays a valid COBOL member source (new language key
`source_members_generated_from`). Its symbolic map is a COBOL copybook
generated from it, so `COPY CUSTMS` may name CUSTMS.bms when the mapset is the
only CUSTMS.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FNWHcUSn5p7eMxFTsB5rFo
squid-protocol added a commit that referenced this pull request Oct 4, 2026
…porter's language (part of #4265) (#4366)

The #3199 language rule for source-member imports (COBOL COPY, PL/I %INCLUDE,
HLASM COPY) ran only when several files matched. A single match in another
language was taken. Examples: COBOL `COPY A` -> A.hlasm (che4z lsp fixtures),
DSF PL/I `%INCLUDE DFHBMSCA` -> carddemo's COBOL copybook, and zopeneditor
PSAM1LIB.pli -> COBOL DATETIME.cpy / REPTTOTL.cpy. This is the same class as
#3001's Python `import base64` -> base64.c.

A BMS mapset stays a valid COBOL member source (new language key
`source_members_generated_from`). Its symbolic map is a COBOL copybook
generated from it, so `COPY CUSTMS` may name CUSTMS.bms when the mapset is the
only CUSTMS.


Claude-Session: https://claude.ai/code/session_01FNWHcUSn5p7eMxFTsB5rFo

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

galaxyscope non-determinism: state_unreferenced / risk_api_exposure differ across identical-blob scans (whole-repo symbol resolution)

1 participant