Repository navigation
Description
Summary
galaxyscope --incremental (Delta Scan) is broken on the current file_data schema and has been a silent no-op: every delta scan catches an internal error and falls back to a full scan. Fixing that first-layer crash then exposes a second, deeper correctness bug — the incremental path does not reproduce a full scan's output. There is no parity test guarding --incremental, which is how both layers went unnoticed.
Found while investigating why a 1,016-scan temporal-crucible run of curl (via --db-only) was slow — the harness wasn't passing --incremental, and when we tried it, it produced wrong results.
Layer 1 — Rehydration crashes, silently falls back to full (safe but slow)
StateRehydrator.load_state() (gitgalaxy/core/state_rehydrator.py) reconstructs each file's cache entry with:
"dependency_network": {
"total_downstream": f["total_downstream"],
"total_upstream": f["total_upstream"],
},Those columns do not exist in file_data. They are transitive reach counts computed at scan time (security_auditor.py reach_counts) and written only to the JSON audit — never persisted to the DB (the DB has internal_dependency_links, normalized_blast_radius, etc.). So f["total_downstream"] raises IndexError: No item with that key, which the broad except (sqlite3.Error, ValueError, TypeError, KeyError, IndexError) swallows → load_state returns None → galaxyscope.py logs ⚠️ Rehydration failed. Falling back to full baseline scan.
Measured (curl, one commit pair, baseline DB holds the parent):
FULL child scan: 6.27s
DELTA child scan: 6.22s <- no speedup: it silently ran a full scan
log: ⚠️ Rehydration failed. Falling back to full baseline scan.
Direct load_state() call: ⚠️ Database corruption or read error: No item with that key.
Net effect today: --incremental is safe but pointless — correct output, zero speedup, for every user on this schema.
Layer 2 — With rehydration fixed, delta output DOES NOT match a full scan
Applying the minimal schema-drift fix (patch below) makes rehydration succeed — and the shipped parity audit (temporal-crucible/tools/parity_check.py) then shows delta is not equivalent to full:
CURL-CVE-2026-82209 95c1e8915dce files inc=368 full=1134 DIVERGENT
only-full: <766 files missing from the delta child commit>
differs: include/curl/easy.h -> ['risk_api_exposure', 'class_count']
differs: include/curl/header.h -> ['risk_api_exposure', 'risk_dead_code', 'class_count']
CURL-CVE-2026-82208 ed0338befd1d files inc=0 full=1132 DIVERGENT
parity: 0/1 pairs identical
Two distinct defects:
- Partial persistence — the child commit ends up with only 368 of 1,134 files (one pair: 0).
execute_incremental_scandoes not re-emit the rehydrated (unchanged) files under the newcommit_hash; a full scan writes all of them. - Signal drift — files that are present differ on graph/exposure-derived signals (
risk_api_exposure,risk_dead_code,class_count). Root cause: rehydrated files come back with"raw_imports": set()(empty) and"hit_vector": [], so the ripple recompute (_resolve_dependency_graph/build_dependency_graph/_calculate_risk_exposures) sees a graph missing all edges from unchanged files.
Proposed fix direction
- Persist-and-re-emit:
execute_incremental_scanmust write the full surviving file set under the new commit, not only the surgically re-scanned files. - Rehydrate imports: either persist
raw_imports(or resolved edges) tofile_dataand restore them inload_state, or rebuild the edge set from the already-persistedinternal_dependency_links/edge tables, so the recomputed graph matches a full scan. - Guard with a parity test: promote
temporal-crucible/tools/parity_check.pyinto the engine's test suite (--incrementalchild vs independent full child must be row-identical). This is the missing check that let both layers ship.
⚠️ Do NOT merge the Layer-1 patch alone
The patch below is the diagnostic that exposes Layer 2 — not a shippable fix. Merging it by itself makes things worse: it flips --incremental from silently-slow-but-correct (full fallback) to silently-wrong (partial, drifted delta). Ship it only together with the Layer-2 fix + parity test.
diff --git a/gitgalaxy/core/state_rehydrator.py b/gitgalaxy/core/state_rehydrator.py
index bef10cb5..9b78046f 100644
--- a/gitgalaxy/core/state_rehydrator.py
+++ b/gitgalaxy/core/state_rehydrator.py
@@ -146,9 +146,18 @@ class StateRehydrator:
"ai_threat_score": f["ai_threat_score"],
"author_distribution": safe_silo_risk,
},
+ # Schema Drift Protection (same pattern as silo_risk/doc_loc above).
+ # total_upstream/total_downstream are TRANSITIVE reach counts computed
+ # at scan time (security_auditor.reach_counts) and written only to the
+ # JSON audit -- they were never persisted as file_data columns. An
+ # unguarded f["total_downstream"] therefore raises IndexError on every
+ # real DB, which the broad except below swallowed, silently dropping
+ # EVERY delta scan back to a full scan. The incremental ripple
+ # (execute_incremental_scan step 5) recomputes these for all files, so a
+ # rehydrated seed of 0 is both sufficient and correct.
"dependency_network": {
- "total_downstream": f["total_downstream"],
- "total_upstream": f["total_upstream"],
+ "total_downstream": f["total_downstream"] if "total_downstream" in row_keys else 0,
+ "total_upstream": f["total_upstream"] if "total_upstream" in row_keys else 0,
},
}
Activity
fix(delta): rehydrate equations (raw signal dict); drop the duplicati…
fix(delta): rehydrate functions & classes from function_data/class_da…
fix(delta): restore baseline identity lock so zero-structure files su…
fix(delta): key per-function hit_vector by signal name, not column na…
test(delta): assert full-fidelity vector reconstruction in the rehydr…
chore(delta): lint/type cleanups in the rehydrator (#3220)
fix(delta): persist + rehydrate mitigation_telemetry for exact score …
fix(delta): persist + rehydrate doc_umbrella so risk_documentation ma…
fix(delta): persist func impact (magnitude) for exact risk_verificati…
fix(delta): persist + rehydrate raw_imports for exact graph popularity (
fix(delta): decode calls_out_to to a list on rehydrate; drop debug (#…
fix(delta): persist synthetic function slices for exact risk_verifica…
fix(delta): green CI -- revert synthetic-slice persistence (corpus re…
style(delta): ruff-format record_keeper after the repo_data unpacking…
fix(delta): raw_imports can be (module, alias) tuples -- don't sort, …
Fix/incremental delta parity (#3227)
fix(delta): persist raw_imports in a deterministic order (follow-up to …
squid-protocol commentedon Sep 20, 2026
Fixed in #3227 (green, pending merge — this issue is wired to close on merge).
Root cause confirmed as reported: rehydration read nonexistent
total_downstream/total_upstreamcolumns →IndexErrorswallowed → silent full-scan fallback; and evenwhen engaged, rehydration was lossy (~10 of ~250 fields), so it couldn't reproduce a
full scan (partial persistence + signal drift).
The fix makes the DB a replayable snapshot: full
risk_vector/hit_vector/equationsreconstructed by inverting the recorder's own schema maps;
functions/classesrehydrated from their tables; and the transient score-layer inputs the DB never kept now
persisted + restored (
mitigation_telemetry,doc_umbrella,raw_imports,func.impact). A full-scan@X vs incremental→X oracle(
temporal-crucible/tools/parity_check.py) shows full file coverage + bit-exact on 12of 13 risk vectors, and the misleading unit test (mock DB inventing the missing
columns) is corrected.
Remaining tail (not blocking; intentionally deferred):
risk_verificationstilldiffers on a few files/repo — (1) synthetic top-level slices are consumed by the
verification math but persisting them regresses
units_documented, and (2) the repo-wideumbrella_bonusis computed over soon-excluded files' LOC a delta can't reconstruct(
excluded_artifactshas nocoding_loc). Both fixes ripple more than the 4th-decimalgain justifies. If exact
risk_verificationparity is ever required, that's thefollow-up scope.
squid-protocol commentedon Sep 20, 2026
Fix merged to main in #3227 (2026-09-20). Auto-close didn't fire because the
Closes #3220link was added to the PR body after it merged — closing manually. Resolution + the deferred risk_verification tail are documented in the comment above.import graph (kotlin): an import of a top-level property resolves to …