Skip to content

Zero-dependency mode: exact degree counts + document what the mode costs (#3024) - #3030

Merged
squid-protocol merged 3 commits into
mainfrom
fix/3024-zero-dep-degree
Sep 14, 2026
Merged

squid-protocol merged 3 commits into
mainfrom
fix/3024-zero-dep-degree

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Closes #3024.

Why

Zero-dependency mode exists so people who don't want third-party packages can still get a useful scan. It should give them the best numbers it can, and say plainly which numbers it can't give. Before this PR it fell short on both:

  1. Degree counts meant different things depending on what was installed (internal_dependency_links / popularity count import statements in zero-dependency mode but distinct neighbours with networkx #3024). Without networkx, the fallback counted every resolved import statement. With networkx, the DiGraph counted distinct neighbouring files. So popularity, internal_dependency_links, dependency_density, producer_ratio, ecosystem_role, "Popularity Rank" and "Direct Downstream" all depended on the environment. Degree is one of the few graph measurements the fallback can compute exactly, so it should.
  2. Nothing told a user what the mode costs, and the runtime text that tried was wrong. The startup banner said missing metrics "will be safely set to NULL". The SARIF note said "safely reported as NULL". In practice they are NULL only in the SQLite DB and read as 0.0 everywhere else. The end-of-run note checked only networkx and tiktoken. The README never mentioned the mode, and pyproject.toml offered no way to install full precision.
  3. --max-systemic-threat silently could never fail without networkx. It multiplies by blast radius, which is always a 0.0 placeholder in that mode. A CI job relying on the gate got no protection and no warning.

What

  • network_risk_sensor.py (internal_dependency_links / popularity count import statements in zero-dependency mode but distinct neighbours with networkx #3024): the fallback counts one per resolved edge, i.e. distinct neighbours, using the same _resolve_edges() edge set the DiGraph wires (Persist the dependency graph edge list (enables neighborhood/interaction-level risk hypotheses) #2992). Degree-derived fields are now identical in both modes.
  • --max-systemic-threat: without networkx it now logs a clear warning that the gate was not evaluated, and skips it (Orchestrator._effective_systemic_threat_ceiling). Behaviour with networkx is unchanged.
  • New docs/zero_dependency_mode.md: a field-by-field reference. For each optional package it lists what is identical, what is not computed (and how each output shows that), and the knock-on effects: the gates that can't fire, the guardrail flags, the archetype features. It also shows how each output flags the mode, and has a caveats section linking the open behaviour issues.
  • Corrected runtime text:
    • The startup banner now says what each missing package actually costs, and that degree counts stay exact.
    • The end-of-run note now triggers on any missing package.
    • The SARIF GG-SYS-ZERO-DEP note now says NULL in the DB and placeholder 0 elsewhere.
    • The LLM-brief banner now names the actual missing packages and says "placeholder, not a measurement". Its "ZERO-DEPENDENCY MODE ACTIVE" heading is kept.
  • pip install "gitgalaxy[full]": a new extra, the same unpinned set CI installs. A plain pip install gitgalaxy still installs nothing.
  • README: the Installation section shows both installs, plus a short "Zero-dependency mode" section linking the reference.
  • Other doc fixes:
    • The 02-16-network-risk-sensor wiki line had described the fallback as "basic in/out degree ratios".
    • The edge_data reconciliation note in recorders/README.md said the modes differ, which is no longer true.

Golden master (zero-dependency re-blessed; full precision unchanged)

The re-bless is scoped by an uncapped diff of a fresh zero-dependency scan of language-crucible v1.2.0 against the committed fixture:

  • 36 differences in total, all on 18 files across 13 languages (5 python, 2 livecode, and 1 each of javascript, dockerfile, dart, lua, haskell, shell, swift, ruby, perl, php and typescript).
  • Each of those files has exactly 2 moved fields, Popularity Rank and Direct Downstream (Dependency Blast Radius).
  • Every value decreased (0 increases), 43 in total. These are exactly the files one of whose importers imports them more than once. Example: fastapi types.py, 34 → 25.
  • No coordinate ripple, no risk ripple.
  • The fixture's other changed lines are sanitized scan metadata (path, timestamp, remote URL, duration) written by crucible_check.py --update; they are not hand-edited.

crucible_check.py --mode full passes unchanged. Only the no-networkx path moved.

Verification

  • New tests/core_engine/test_zero_dependency_gate.py: skip-with-warning without networkx, enforced with networkx, and no noise when the flag is unset.
  • tests/tools_recorders/test_edge_data.py: the zero-dependency test now asserts distinct-neighbour degrees. A new test_degree_family_is_identical_in_both_modes builds the same universe in both modes and asserts in_degree / out_degree / producer_ratio / ecosystem_role / popularity are equal, including the file that imports one target twice.
  • 224 tests pass across the gate, recorder, network-sensor, zero-dependency and galaxyscope suites.
  • ruff_audit --ci, mypy_audit --ci and dead_key_audit --ci pass, and the changed files are ruff format-clean.

Follow-ups filed (behaviour, deliberately not in this PR)

Both are documented as current behaviour in the new reference page's caveats section, which should be updated when they land.

Cross-repo

None required. Downstream history consumers (temporal-crucible) should note that zero-dependency snapshots recorded before this merge have statement-count degrees; the reference page's caveats say so.

🤖 Generated with Claude Code

…sts (#3024)

- network_risk_sensor: the no-networkx fallback now counts distinct
  neighbours (one per resolved edge), the same thing the DiGraph's
  in/out degree reports. popularity, internal_dependency_links,
  dependency_density, producer_ratio, ecosystem_role, "Popularity Rank"
  and "Direct Downstream" no longer depend on which optional engines are
  installed (they used to count import statements in this mode).
- galaxyscope: --max-systemic-threat multiplies by blast radius, which
  only networkx computes, so without it the gate could never fail. It now
  warns that it was not evaluated and is skipped.
- docs/zero_dependency_mode.md: field-by-field reference of what each
  optional package provides, what is identical / not computed without it,
  how each output flags the mode, and known caveats (#3027, #3028).
- Corrected runtime text that claimed missing metrics are "NULL" (they are
  NULL only in the DB, 0.0 placeholders elsewhere): startup banner,
  end-of-run note (now triggers on any missing package), SARIF
  GG-SYS-ZERO-DEP, LLM-brief banner.
- pyproject: `pip install "gitgalaxy[full]"` extra; README installation +
  zero-dependency section; wiki + recorders README corrected.
- Zero-dependency golden master re-blessed: 36 diffs = 18 files x
  (Popularity Rank, Direct Downstream), all decreases (43 in total); full
  precision unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@squid-protocol squid-protocol added bug Unintended behavior or logic failure in the engine metrics Heuristics, risk exposures, and topological math updates labels Sep 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit 12c262d into main Sep 14, 2026
29 checks passed
@squid-protocol
squid-protocol deleted the fix/3024-zero-dep-degree branch September 14, 2026 20:38
squid-protocol added a commit that referenced this pull request Sep 14, 2026
…PageRank (#3027) (#3032)

* Uncomputed graph metrics are None, and zero-dep mode computes PageRank (#3027)

A graph metric that was never computed was written as 0.0 -- every
networkx-only metric in zero-dependency mode, closeness above 1,500 files
in every mode, everything on a convergence failure -- and consumers read
it as a measurement: a false "Containment (Low Risk)" AI verdict,
bottleneck rankings of five zero-score files, a 0.0 macro table, zeroed
archetype features, a HITL flag and --max-systemic-threat that could
never fire.

- network_risk_sensor: pure-Python _pagerank() (nx.pagerank's parameters
  and conventions; max |delta| 6.6e-16 on the crucible graph, identical at
  the stored 6 dp) so zero-dependency PageRank, blast radius and
  systemic_threat_vector match full precision. Everything still not
  computed is None via a shared _network_metrics().
- Consumers made None-aware: AI topology skips insights it can't
  evaluate; each bottleneck ranking holds only files whose metric was
  computed; the LLM brief renders n/a; supply_chain_firewall and the
  --max-systemic-threat gate no longer crash on None. #3030's gate skip
  is removed -- blast radius is computed in every mode now.
- record_keeper reads network columns straight from the sensor instead
  of NULLing them on the zero-dependency flag (the network half of #3028).
- Docs/messages: zero_dependency_mode.md, banner, SARIF, LLM banner,
  README, wiki, CLAUDE.md, self_scan.py's zero-dep detector.
- Golden masters re-blessed. Full precision: 1 diff (fragile_dependency_
  chain -> []). Zero-dependency: 2,360 diffs, all from real PageRank --
  its composition archetypes / fit z-scores / distribution now equal the
  full-precision fixture's exactly (52 + 2,275 mismatches -> 0).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Run the native PageRank in full-precision mode too (#3027)

Both graph builders now call one _native_pagerank(), fed identical node
and edge order, so the two modes produce the same floats and no networkx
release can move them. nx.pagerank is no longer called: in networkx 3.x
it dispatches to a numpy/scipy backend networkx does not install, so
with networkx alone it raised and every file's PageRank was silently
lost. PageRank is also computed outside the networkx try-block now, so a
centrality failure can't take it down.

Golden masters: both modes unchanged (crucible_check --mode both PASS).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

---------

Co-authored-by: Joe Esquibel <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Unintended behavior or logic failure in the engine metrics Heuristics, risk exposures, and topological math updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

internal_dependency_links / popularity count import statements in zero-dependency mode but distinct neighbours with networkx

1 participant