Skip to content

Persist the dependency graph edge list as edge_data (#2992) - #3025

Merged
squid-protocol merged 1 commit into
mainfrom
feat/2992-edge-data
Sep 14, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
feat/2992-edge-data

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Closes #2992.

What

The engine builds the full file-to-file import graph every scan (network_risk_sensor) but the scan DB kept only per-node summaries of it (popularity, internal_dependency_links, pagerank_score, ...). The edges were thrown away, so none of the neighbourhood / interaction-level hypotheses in #2982 could be tested against a scan. This PR persists them.

New table, edge_data: one row per resolved (importer, imported) pair.

column meaning
repo_name, commit_hash snapshot key, same as the other tables
src_file_id, dst_file_id FKs to file_data.id (ON DELETE CASCADE, both indexed)
edge_kind 'import' (reserved so another relation can share the table later)
import_statements resolved captures src→dst (repeats collapse into one row)
entity_imports how many of those were the entity (from x import y) form
weight the weight pagerank/betweenness read

New column, repo_data.network_edges_unrecorded: the statistical audit runs after the graph is built and can relegate a node to excluded_artifacts. Its edges then have no file_data row to key on, so they are counted here instead of being dropped silently. The value is NULL when the caller passes no edge list.

How

  • network_risk_sensor.py: a single _resolve_edges() now feeds both graph builders, DiGraph and the zero-dependency fallback, so the persisted edges can't drift from the degrees and pagerank computed from them. Degrees, weights (same float accumulation order) and edge insertion order are unchanged. The list is left on NetworkRiskSensor.dependency_edges. It deliberately stays out of file telemetry and network_macro, because both of those are serialized into the audit/GPU JSON.
  • record_keeper.py: the table and indexes, an idempotent per-snapshot wipe, a path → file_id map built in the existing insert loop, and a batched insert. It carries no FK to repo_data on purpose, because that table's INSERT OR REPLACE would cascade-delete the rows. Pre-Persist the dependency graph edge list (enables neighborhood/interaction-level risk hypotheses) #2992 DBs heal through CREATE TABLE IF NOT EXISTS plus _ensure_columns.
  • galaxyscope.py: both record_mission call sites (full and delta) pass the edges. --db-only goes through the same path, so history batches capture them.
  • recorders/README.md: table reference, reconciliation rules, and two example queries (neighbourhood marker load, per-language edge coverage). Both were run against a real scan DB.
  • tests/ruff_audit_baseline.json: the record_keeper.py entries were refreshed for shifted lines. Stripping the trailing whitespace in the SQL strings removed 12 baselined W291s.

Verification

  • tests/tools_recorders/test_edge_data.py (10 tests):
    • the edge list matches the degrees in DiGraph mode (row counts) and in zero-dependency mode (import_statements sums)
    • a later build replaces the list (delta mode reuses the sensor instance)
    • FK-keyed persistence, with per-file reconciliation against internal_dependency_links / popularity
    • a relegated endpoint is counted, not recorded
    • re-recording a commit doesn't duplicate rows
    • two snapshots keep their own edges, with no cross-snapshot endpoints
    • no edge list gives no rows and a NULL count
    • a pre-Persist the dependency graph edge list (enables neighborhood/interaction-level risk hypotheses) #2992 DB heals
  • Full-precision self-scan: 395 files, 497 edges. Per file, rows by src equal internal_dependency_links and rows by dst equal popularity, with 0 mismatches and 0 unrecorded.
  • Full-precision scan of language-crucible v1.2.0: 2,817 files, 1,354 edges (43,058 function_data rows, so the table is tiny next to them). sum(internal_dependency_links) = 1,365 = 1,354 + 11 network_edges_unrecorded. Exactly 11 files have an out-mismatch, all edges into relegated files. There are 0 in-mismatches.
  • Golden master: crucible_check.py against language-crucible v1.2.0 passes in both modes (full_precision and zero_dependency) with zero differences. The audit JSON is untouched, and so are degrees, pagerank and weights. No bless is owed.
  • ruff_audit --ci, mypy_audit --ci, dead_key_audit --ci, ruff format --check: pass. Full pytest tests/: 8,883 passed, 4 skipped, 9 xfailed, 3 xpassed.

Per-language edge coverage (language-crucible v1.2.0)

The issue asked for this to be surfaced. It is now one query away: the second example in the README.

captures vs resolved edges by language
language         files  captures  files_w_caps  files_w_edges  edges
---------------  -----  --------  ------------  -------------  -----
assembly         232    81        39            0              0
agc_assembly     10     56        9             0              0
yacc             4      23        4             0              0
kotlin           5      18        4             0              0
abap             7      6         1             0              0
scheme           4      6         1             0              0
swift            6      6         6             0              0
rust             43     780       42            4              4
java             14     572       13            7              9
scala            7      531       7             7              9
dart             7      175       7             3              3
csharp           8      110       8             2              2
php              36     1242      34            17             28
cpp              28     731       28            13             20
groovy           188    597       141           15             17
solidity         7      26        5             1              1
ruby             14     84        12            4              4
c                40     377       39            16             18
javascript       18     268       17            11             13
fortran          6      163       6             4              8
haskell          7      133       7             4              7
perl             22     597       22            17             41
dockerfile       5      59        4             2              5
typescript       24     506       21            18             43
objective-c      5      34        5             3              3
powershell       110    23        16            3              3
markdown         96     21        9             3              3
jcl              185    404       139           49             60
zig              32     231       32            20             43
html             54     100       31            19             19
go               46     600       44            41             124
python           272    1654      266           236            386
tcl              29     63        27            13             19
shell            213    33        23            9              10
lua              109    137       45            19             46
livecode         98     61        29            20             25
embedded_python  7      46        7             6              19
css              21     4         2             1              3
cobol            560    446       126           90             359

Seven languages capture imports but resolve no edge in this corpus: assembly (81 captures), agc_assembly (56), yacc (23), kotlin (18), abap (6), scheme (6) and swift (6). Crucible files are mostly standalone samples whose imports name things outside the corpus, so this is a measurement, not a defect claim. A history-enabled temporal-crucible run on real repos is the place to judge it. The js/ts "no edges" note from the issue no longer holds: #2668 fixed that. In this corpus, javascript resolves 13 edges and typescript 43.

Found along the way, not changed here

In zero-dependency mode the fallback's internal_dependency_links / popularity count import statements. In full-precision mode they count distinct neighbours, so the same file gets different values depending on which engines are installed. This PR keeps that byte-identical, because the zero-dependency golden master records it. edge_data makes the gap explicit: reconcile with SUM(import_statements) in zero-dependency mode. Filed as #3024.

Cross-repo

No companion PR, and nothing here needs to merge first. The change is additive: a new table plus one nullable repo_data column, so existing temporal-crucible queries are unaffected. INT-level hypotheses (#2982, temporal-crucible#29) can start reading edge_data from any snapshot recorded after this merges. Earlier snapshots have no edges and need a rescan.

🤖 Generated with Claude Code

The network sensor builds the full file-to-file import graph every scan
but the DB kept only per-node summaries of it (popularity, pagerank_score,
internal_dependency_links), so no neighbourhood / interaction-level
hypothesis was testable from a scan.

- network_risk_sensor: one _resolve_edges() now feeds both graph builders
  (DiGraph and the zero-dependency fallback), so the persisted edges cannot
  drift from the degrees and pagerank computed off them. Degrees, weights
  and edge order are unchanged. The list is left on
  NetworkRiskSensor.dependency_edges -- not in telemetry or macro metrics,
  both of which reach the audit/GPU JSON exports.
- record_keeper: new edge_data table (repo_name, commit_hash, src/dst
  file_id FKs to file_data, edge_kind, weight, import_statements,
  entity_imports), wiped with the snapshot like the other tables. Edges
  whose endpoint the statistical audit relegated after the graph was built
  are counted in repo_data.network_edges_unrecorded, not dropped silently.
- galaxyscope: both record_mission call sites (full + delta) pass the
  edges, so --db-only history batches capture them.
- ruff baseline: record_keeper entries refreshed for shifted lines; the
  SQL strings' trailing whitespace is stripped.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@squid-protocol squid-protocol added enhancement New feature, sensor, or structural signature schema Data schema updates for JSON outputs or SQLite tables 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 5cf368b into main Sep 14, 2026
38 of 41 checks passed
@squid-protocol
squid-protocol deleted the feat/2992-edge-data branch September 14, 2026 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature, sensor, or structural signature schema Data schema updates for JSON outputs or SQLite tables

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Persist the dependency graph edge list (enables neighborhood/interaction-level risk hypotheses)

1 participant