Repository navigation
Persist the dependency graph edge list as edge_data (#2992) - #3025
Merged
Merged
Conversation
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]>
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.repo_name,commit_hashsrc_file_id,dst_file_idfile_data.id(ON DELETE CASCADE, both indexed)edge_kind'import'(reserved so another relation can share the table later)import_statementsentity_importsfrom x import y) formweightNew column,
repo_data.network_edges_unrecorded: the statistical audit runs after the graph is built and can relegate a node toexcluded_artifacts. Its edges then have nofile_datarow 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 onNetworkRiskSensor.dependency_edges. It deliberately stays out of file telemetry andnetwork_macro, because both of those are serialized into the audit/GPU JSON.record_keeper.py: the table and indexes, an idempotent per-snapshot wipe, apath → file_idmap built in the existing insert loop, and a batched insert. It carries no FK torepo_dataon purpose, because that table'sINSERT OR REPLACEwould cascade-delete the rows. Pre-Persist the dependency graph edge list (enables neighborhood/interaction-level risk hypotheses) #2992 DBs heal throughCREATE TABLE IF NOT EXISTSplus_ensure_columns.galaxyscope.py: bothrecord_missioncall sites (full and delta) pass the edges.--db-onlygoes 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: therecord_keeper.pyentries 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):import_statementssums)internal_dependency_links/popularityinternal_dependency_linksand rows by dst equalpopularity, with 0 mismatches and 0 unrecorded.v1.2.0: 2,817 files, 1,354 edges (43,058function_datarows, so the table is tiny next to them).sum(internal_dependency_links)= 1,365 = 1,354 + 11network_edges_unrecorded. Exactly 11 files have an out-mismatch, all edges into relegated files. There are 0 in-mismatches.crucible_check.pyagainst language-cruciblev1.2.0passes 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. Fullpytest 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
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/popularitycount 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_datamakes the gap explicit: reconcile withSUM(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_datacolumn, so existing temporal-crucible queries are unaffected. INT-level hypotheses (#2982, temporal-crucible#29) can start readingedge_datafrom any snapshot recorded after this merges. Earlier snapshots have no edges and need a rescan.🤖 Generated with Claude Code