Skip to content

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

Closed

Description

@squid-protocol

Summary

galaxyscope is non-deterministic for the whole-repo symbol-reference signal: scanning the same file blob with identical documented inputs can persist different state_unreferenced (→ risk_tech_debt) and risk_api_exposure values across runs. Surfaced by the temporal-crucible rung-6 instrument-control audit (epic #2982); it sets the spillover-tail max there and is a correctness bug in the risk vector.

Reproduction (observed)

File lib/curlx/base64.c in curl, scanned at two commit pairs where the file blob is byte-identical on both sides (same 40-hex blob hash), and every documented input to _calc_api_exposure/_calc_tech_debt is identical across the two scans:

inputs (identical both scans) persisted output (differs!)
arch_api 3=3, def_encapsulation 3=3, total_loc 286=286, popularity 0=0, pagerank_score 0.000346=0.000346 risk_api_exposure 2.4495 → 13.9454
good_debt=0, bad_debt=0 both risk_tech_debt 41.2713 → 0.0

The smoking gun: file_data.state_unreferenced reads 3 in one scan and 0 in the other, while a parallel tracking column raw_state_unreferenced correctly holds 3 in both. Since _calc_api_exposure(raw_signals, total_loc, popularity) is a pure function of arch_api/def_encapsulation/total_loc/popularity — all byte-identical — the output cannot legitimately differ. Reproduced on two unrelated commit pairs on this file.

Likely cause

state_unreferenced (unreferenced_by_name, "is this symbol referenced anywhere in the repo") is a whole-repo / cross-file computation — exactly the kind of shared state a multi-worker scan can corrupt under a race. A live galaxyscope --db-only run with ~10–12 workers was active during the audit. Two hypotheses to distinguish:

  1. Multiprocessing race in the symbol-reference index (shared cache / ordering).
  2. #ifdef-gated static-pass variance — curl builds base64 support conditionally per TLS backend; if the static pass resolves a different conditional branch depending on worker/thread scheduling, arch_api/state_unreferenced could vary without a shared-cache bug.

How to confirm

Re-scan just the two commit pairs single-worker (--workers 1 or equivalent) and diff state_unreferenced / risk_api_exposure for lib/curlx/base64.c against the captured values. If single-worker is stable (3/3, risk_tech_debt≈41.27 both), it's the race (1); if it still varies single-threaded, it's branch-resolution variance (2).

Pointers

Why it matters

raw_state_unreferenced holding the correct value while state_unreferenced drifts means the persisted risk vector is corrupted post-extraction. Any delta/ranking over these columns (and the whole score-contract program) inherits the nondeterminism; raw_state_unreferenced may be the trustworthy source to reconcile against.

Activity

  1. added
    bug
    data-integrity
    on Sep 13, 2026
  2. squid-protocol commented on Sep 13, 2026

    @squid-protocol
    OwnerAuthor

    Diagnosis update — this is NOT a multi-worker race. Ran the single-worker confirmation (scanned 2dfe421a6/e1f65937a9 with one worker); the child's state_unreferenced=0 / risk_api_exposure=13.9454 / risk_tech_debt=0.0 reproduce deterministically single-threaded (4/4 runs stable). Hypothesis (1) is disproven.

    Real cause: a cross-language import edge. The child commit added import base64 (Python stdlib) to tests/http/testenv/certs.py. 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 had no language guard (the #2684 stem fallback does). So Python's import base64 credited curl's C lib/curlx/base64.c with popularity=1, which fired the Contextual Baseline Fix (unreferenced_by_name 3→0, tech_debt→0) and _calc_api_exposure's network multiplier (2.4495→13.9454). _calc_api_exposure was pure all along — it just received a popularity the recorded column didn't reflect.

    Fix in #3001: guard FAST PATH 1 (and the fallback's extensionless case) by the importing file's language. base64.c now reports state_unreferenced=3, risk_api_exposure=2.4495, risk_tech_debt=41.2713 identically across both commit pairs.

  3. added 2 commits that reference 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

    bugdata-integrity

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions