Repository navigation
Description
Summary
gitgalaxy/galaxyscope.py's main parallel file-scanning phase (lines 1581-1698) uses concurrent.futures.as_completed() to yield worker results in whatever order processes finish — inherently non-deterministic run-to-run. The codebase already has three confirmed, documented instances of this exact bug class (all with fixes applied), visible in comments right in the same function:
-
Line 1681:
self.ram_cache = dict(sorted(self.ram_cache.items()))— re-sorted into stable path order because downstream consumers (folder dominant-language tallies, parsed_files construction, spatial positioning) inherited the non-deterministic order fromas_completed(). -
Line 1692:
self.unparsable_files.sort(key=lambda entry: entry["path"])— same fix pattern, applied after discovering that "two back-to-back runs on the same machine happened to interleave identically and masked it, but a genuinely different machine (e.g. a CI runner) did not." -
Line 1698:
self.anomalies.sort(key=lambda entry: (entry["star"], entry["diagnostic"]))— same pattern again.
This pattern strongly suggests at least one more piece of shared state fed by the same as_completed() loop never got the same stable-sort treatment. Evidence suggests it affects:
- Popularity Rank field (
gitgalaxy/recorders/audit_recorder.py:257,"Popularity Rank": telemetry.get("popularity", 0)) - Directory Group composition percentages and avg_exposures aggregates (from
"Global Ecosystem Summary"in the audit report) - High-Value Forensic Report exposures field ordering/values
Impact
This makes crucible_check.py / test_golden_crucible.py's full-corpus golden-master diff untrustworthy when per-file processing time changes even slightly (a new regex scan, a differently-loaded CI runner, a slower machine). Real code changes and pure task-scheduling noise become indistinguishable in the diff output without manual investigation each time — exactly as already happened twice before for ram_cache, unparsable_files, and anomalies.
How It Manifests
When verifying an unrelated detector.py change (adding one extra cpp/c regex scan per file — small but real added per-file timing), crucible_check.py's full-corpus diff started showing different random files/languages flagged as mismatched on every run (run 1: zig/xml; run 2: lua/rust/cpp with varying mismatch counts). Running the exact same check twice on unmodified main produced zero mismatches both times, confirming this is not corpus drift but genuine scheduling-dependent non-determinism.
The underlying structural-signature extraction itself verified completely stable (3 repeated full-corpus scans of cpp produced byte-identical function-name lists), confirming this is specifically about some ranking/aggregate field's value depending on which worker finishes first, not extraction correctness.
Suggested fix
Whoever picks this up should:
-
Find the culprit: Trace where "popularity" (feeding
telemetry.get("popularity", 0)ataudit_recorder.py:257) and thedirectory_groups/composition/avg_exposuresaggregates in the audit summary get computed. Determine if any of them:- Iterate over
self.ram_cacheor an equivalent per-file result structure before the existingdict(sorted(...))stabilization point at line 1681, OR - Iterate over some other
as_completed()-order-dependent list/dict that was never given the same stable-sort treatment (examineself.splicing_telemetry,self.file_speed_telemetry, or any other shared state modified in lines 1581-1698)
- Iterate over
-
Apply the fix: Use the identical pattern already proven three times in the same function — sort by a stable key (file path, or whatever the field's natural stable key is) at the point where non-deterministic-order data gets consumed. If the data structure is a dict, use
dict(sorted(...)). If it's a list, use.sort(key=lambda...). -
Verify locally: Run
crucible_check.pytwice in a row without re-blessing in between and confirm zero diff, ideally under an artificially slowed-down or reordered worker schedule to ensure the fix isn't just papering over the specific timing this was found under.
Activity
Fix cpp/c func_start false positives on known macro invocations (#2031)
Fix non-deterministic ordering in telemetry (Issue 2030) (#2153)