Skip to content

Scope golden-crucible to language-crucible/data, pin the corpus, and fix engine nondeterminism (#328 prep) - #395

Merged
squid-protocol merged 1 commit into
mainfrom
fix/328-golden-crucible-scope-and-baseline
Jul 25, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/328-golden-crucible-scope-and-baseline

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Part 1 of the golden-crucible cleanup plan (#328/#329/#330). Before wiring golden_diff.py into CI, this PR fixes the ground it stands on:

  • Real nondeterminism bugs found and fixed while regenerating the baseline: two unseeded randomized networkx calls (louvain_communities, approximate betweenness_centrality) and one ProcessPoolExecutor-order-dependent code path (ram_cache + everything downstream of it: parsed_files order, folder-dominant-language tie-breaks, spatial positioning, security-finding list ordering). Verified with back-to-back identical scans before/after: same repo, same code, previously different modularity scores and different flagged "Critical Files" on the security audit. Now byte-identical hashes across repeated runs, both full-precision and zero-dependency mode.
  • golden_diff.py gained math.isclose tolerance for numeric leaves (both pre-hash and in the deep-compare fallback) as defense in depth against any remaining sub-epsilon float noise.
  • golden-crucible.yml now pins language-crucible to the v1.0 tag (the earlier v1.0.0 pin attempt used a tag that never existed, which is probably why it silently fell back to an unpinned clone) and scans language-crucible/data specifically instead of the whole repo, so the corpus repo's own tools//README/raw_output can't cause spurious drift.
  • Regenerated both tests/golden_master_audit.json and tests/golden_master_zero_dep_audit.json from current main. The previous fixtures were last updated 2026-07-04, predating the [BUG/CORE-ENGINE] Comment/code separation is completely broken for all 58 languages -- prism.py's family dispatch never matches the real taxonomy #386 comment-engine fix and ~80 other commits -- they reflected pre-fix, buggy output.

Wiring the actual golden_diff.py comparison step into the CI workflow is the next PR (closes out #328).

Test plan

  • Ran the full-precision scan twice against language-crucible/data, diffed with golden_diff.py -- byte-identical hash both before regenerating (post-seed-fixes) and confirmed again post-ordering-fix
  • Same for zero-dependency mode
  • golden_diff.py tests/golden_master_audit.json tests/golden_master_audit.json self-check passes
  • pytest tests/ -q -- 866 passed, 1 pre-existing xfail
  • flake8 . --count --select=E9,F63,F7,F82 -- clean
  • python tests/dead_key_audit.py --ci -- clean

@github-actions

github-actions Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

…fix engine nondeterminism (#328 prep)

Regenerating a fresh golden master surfaced that the engine wasn't actually
deterministic between two runs of the same unchanged repo:

- network_risk_sensor.py: community.louvain_communities() and the
  k-sampled betweenness_centrality() both ran unseeded, so modularity,
  the "Critical Files" Logic Bomb/Sabotage list, and systemic-bottleneck
  rankings could all differ run-to-run. Both are now seeded.
- galaxyscope.py: ram_cache (and everything built from it -- parsed_files,
  folder-language tallies, spatial positioning) inherited whatever order
  ProcessPoolExecutor's as_completed() happened to yield in. Re-keyed into
  a path-sorted dict once at the end of Phase 1 so the rest of the
  pipeline sees a stable sequence. Also hardened the Folder Dominant Lang
  max() tie-break to break ties alphabetically instead of by dict
  insertion order.
- audit_recorder.py: explicit Path-sort on quarantined_files, each
  vulnerability exposure's Critical Files list, and the ML threat list's
  tie-break, so equal-score findings serialize in a stable order.
- golden_diff.py: added math.isclose tolerance for numeric leaves (both
  in the pre-hash sanitizer and the deep-compare fallback) to absorb any
  remaining sub-epsilon float noise without masking real drift.

Two runs of the full-precision and zero-dependency-mode scans now produce
byte-identical hashes.

Also, ahead of wiring the actual golden_diff.py comparison into CI (#328):
- golden-crucible.yml now pins language-crucible to the v1.0 tag (the
  prior "lock to v1.0.0" attempt used a tag that didn't exist, which is
  likely why it silently fell back to an unpinned clone) and scans
  language-crucible/data specifically instead of the whole repo, so
  changes to the corpus repo's own tools/README/raw_output can't produce
  spurious drift.
- Regenerated both golden_master_audit.json and
  golden_master_zero_dep_audit.json from current main (the committed
  fixtures were last updated 2026-07-04, predating the #386 comment-engine
  fix and ~80 other commits -- they reflected pre-fix, buggy output).

Wiring golden_diff.py into the workflow itself is the next PR (#328).
@squid-protocol
squid-protocol force-pushed the fix/328-golden-crucible-scope-and-baseline branch from c0a7d57 to f665559 Compare July 25, 2026 01:59
@squid-protocol
squid-protocol merged commit 9b3d387 into main Jul 25, 2026
23 checks passed
@squid-protocol
squid-protocol deleted the fix/328-golden-crucible-scope-and-baseline branch July 25, 2026 02:09
squid-protocol added a commit that referenced this pull request Jul 25, 2026
* Wire golden_diff.py into golden-crucible.yml (closes #328)

The workflow scanned language-crucible and printed a debug tree, but
never actually compared the output against a golden master -- CI passed
regardless of what the engine produced.

Split crucible-audit into a fail-fast:false matrix (full-precision,
zero-dependency) since those are genuinely different code paths with
their own golden master fixture, and each leg now ends with a
"Compare Against Golden Master" step that runs golden_diff.py and fails
the job on real drift.

Validated locally: both legs, run against the golden masters regenerated
in #395, produce a Stage 1 hash match against tests/golden_master_audit.json
and tests/golden_master_zero_dep_audit.json respectively.

* Strip environment-specific fields from golden_diff.py's sanitizer

#397's CI run caught what my local validation couldn't: I'd only ever
diffed two runs on my own machine, both against my own local
language-crucible checkout on the main branch. CI clones with
`--branch v1.0 --depth 1` (detached HEAD) into /home/runner/work/...,
so three more fields in "1. Forensic Trail" are legitimately different
per-environment and were never volatile-stripped:

  - Absolute Project Path (machine-specific filesystem path)
  - Remote Origin URL (HTTPS clone appends .git; my local remote didn't)
  - Active Branch ("HEAD" for a detached tag checkout vs "main" locally)

None of these describe anything about the analyzed repository's
structure, so they're stripped the same way timestamps and commit
hashes already are. Verified by simulating CI's values on a copy of the
committed golden master and confirming the sanitized hash now matches.

* Sort unparsable_files and anomalies for determinism (missed in the original ordering fix)

CI caught what my local validation couldn't: the "Unparsable Artifacts"
list differed between my golden master and CI's run, even though the
prior determinism fix (sorting ram_cache) made two consecutive local
runs hash-identical.

unparsable_files.append() and _record_anomaly() are both called from the
same as_completed() parallel loop as ram_cache -- I sorted ram_cache
after that loop but missed these two. Two runs on the same idle local
machine happened to interleave identically both times, masking the bug;
a genuinely different machine (a GitHub Actions runner) did not.

Both lists are now sorted right alongside ram_cache, at the same point
in _extract_features_parallel. Regenerated both golden masters and
reverified: two consecutive runs of each mode now produce byte-identical
hashes again.

---------

Co-authored-by: Joe Esquibel <[email protected]>
squid-protocol added a commit that referenced this pull request Jul 25, 2026
#398)

Adds tests/test_golden_crucible.py: runs the real `galaxyscope` CLI entry
point against the language-crucible corpus and diffs the result against
whichever golden master fixture matches the current environment (reuses
the same zero_dependency_mode detection galaxyscope.py itself uses), via
golden_diff.py's comparison functions imported as a library rather than
shelled out to.

Opt-in via a new `golden_crucible` pytest marker, excluded from the
default `pytest tests/` run through pyproject.toml's addopts (it needs
the language-crucible corpus checked out locally -- LANGUAGE_CRUCIBLE_PATH
env var, or a sibling `../language-crucible` directory by default -- and
takes real wall-clock time). Skips cleanly with a clear message if the
corpus isn't present, rather than failing.

golden-crucible.yml now runs `pytest -m golden_crucible` instead of
duplicating the "run galaxyscope, diff against golden master" logic
directly in the workflow, so there's one implementation instead of two
that could drift apart.

Verified: both full-precision and zero-dependency modes pass locally
against the fixtures from #395/#397; the CI workflow YAML parses cleanly;
866 passed, 1 deselected (this new test, correctly excluded from the
default run), 1 pre-existing xfail; flake8 and dead_key_audit clean.

Co-authored-by: Joe Esquibel <[email protected]>
squid-protocol added a commit that referenced this pull request Jul 25, 2026
* Convert golden_diff.py's CLI invocation into a real pytest test (#329)

Adds tests/test_golden_crucible.py: runs the real `galaxyscope` CLI entry
point against the language-crucible corpus and diffs the result against
whichever golden master fixture matches the current environment (reuses
the same zero_dependency_mode detection galaxyscope.py itself uses), via
golden_diff.py's comparison functions imported as a library rather than
shelled out to.

Opt-in via a new `golden_crucible` pytest marker, excluded from the
default `pytest tests/` run through pyproject.toml's addopts (it needs
the language-crucible corpus checked out locally -- LANGUAGE_CRUCIBLE_PATH
env var, or a sibling `../language-crucible` directory by default -- and
takes real wall-clock time). Skips cleanly with a clear message if the
corpus isn't present, rather than failing.

golden-crucible.yml now runs `pytest -m golden_crucible` instead of
duplicating the "run galaxyscope, diff against golden master" logic
directly in the workflow, so there's one implementation instead of two
that could drift apart.

Verified: both full-precision and zero-dependency modes pass locally
against the fixtures from #395/#397; the CI workflow YAML parses cleanly;
866 passed, 1 deselected (this new test, correctly excluded from the
default run), 1 pre-existing xfail; flake8 and dead_key_audit clean.

* Require deliberate, reviewable golden master updates (#330)

Nothing previously stopped a contributor from making a failing
crucible-audit diff "pass" by just copying fresh output over
tests/golden_master_audit.json / _zero_dep_audit.json -- a green check
would then mean either "matches the last accepted snapshot" or "was just
silently re-blessed," indistinguishable from the CI result alone.

- tests/tools/update_golden_master.py: the one sanctioned update path.
  Regenerates output for whichever mode matches the current environment,
  prints the full diff against the existing fixture before touching
  anything, and requires interactive y/N confirmation (skippable with
  --yes for scripted use, but the diff is always shown either way).
  No-op with a clear message if there's no actual drift.
- .github/workflows/golden-master-guard.yml: non-blocking -- writes a
  GITHUB_STEP_SUMMARY callout on any PR that touches either fixture file,
  so it's never invisible in a large diff. Doesn't block merge; the point
  is reviewer visibility, not enforcement.
- CONTRIBUTING.md: documents the update path and that PRs touching the
  fixture must explain why in the description.

Verified: tested both the abort path (diff shown, 'n' leaves the file
untouched) and the accept path (diff shown, 'y' writes it) against an
artificially-injected drift, then restored the real fixture and confirmed
golden_diff.py still reports parity. flake8, dead_key_audit, full test
suite (866 passed, 1 deselected, 1 pre-existing xfail), and the new
workflow's YAML all clean.

---------

Co-authored-by: Joe Esquibel <[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.

1 participant