Repository navigation
Fix/incremental delta parity - #3227
Merged
Merged
Conversation
…cols (Layer 1 of #3220) StateRehydrator.load_state read f["total_downstream"]/f["total_upstream"], which are not file_data columns (they are transitive reach counts written only to the JSON audit). The unguarded read raised IndexError, swallowed by the broad except, so every --incremental scan silently fell back to a full scan. Guard both reads with the existing schema-drift pattern; they are recomputed by the ripple anyway. NOTE: this alone makes delta ENGAGE but not CORRECT -- it exposes the Layer 2 divergence (partial persistence + signal drift, #3220). Must NOT ship without the Layer 2 fix + parity test. Branch WIP. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Wg5S99Jrd2oXxnUmeKwvx2
…m columns (#3220) The mock_db fixture hand-wrote a file_data schema that included total_downstream and total_upstream -- columns the engine's record_keeper has NEVER created. So every rehydrator test validated against a fictional DB that had exactly the columns production lacks, staying green while real --incremental scans crashed on the missing columns and silently fell back to full scans. Remove the invented columns from the shared fixture + its inserts, and assert the schema-drift default (0) the guarded rehydrator now returns. This is the unit-level half of the missing coverage; the integration half (full-scan@X must equal incremental->X on a REAL engine-produced DB) is tracked next. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Wg5S99Jrd2oXxnUmeKwvx2
…lumns (#3220) The rehydrator restored ~10 fields and left hit_vector=[] with no risk_vector, so rehydrated (unchanged) files could not be re-persisted or re-audited like a full scan -- the root of the incremental/full divergence. Reconstruct both vectors by inverting the recorder's own write: risk_<name> columns (RISK_SCHEMA order) and SHORT_KEY_MAP-renamed hit columns (SIGNAL_SCHEMA order), reading those maps from RecordKeeper so the inversion can never drift from the write. Round-trip verified against a real curl scan: risk_vector (13) and hit_vector (98) both reconstruct byte-identical to the persisted columns. WIP toward full parity: still to wire the rehydrated objects into parsed_files (execute_incremental_scan) so all files persist, and persist raw_imports for add/delete graph exactness. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Wg5S99Jrd2oXxnUmeKwvx2
execute_incremental_scan only put surgically re-scanned (changed) files into parsed_files, so the persist step wrote just those (the 368-of-1134 gap). Inject full rehydrated objects for surviving unchanged files before the ripple so audit + record_mission see the whole repo. Progress, not done: child-commit coverage rises 368 -> 735 files, but audit still drops ~400 (build_dependency_graph 1133->2267 node doubling, then audit->735 needs investigation) and graph-derived signals (risk_api_exposure, risk_dead_code, class_count) still diverge -- raw_imports persistence is the likely remaining piece. Parity NOT yet green. WIP checkpoint. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Wg5S99Jrd2oXxnUmeKwvx2
…ng inject (#3220) Two corrections on the road to parity: - _calculate_risk_exposures ALREADY iterates ram_cache and appends every file, so the manual parsed_files injection was redundant and double-added (1133 + 1134 = 2267 nodes). Reverted. - That loop recomputes each file via calculate_risk_vector(meta, meta["equations"]). Rehydrated files had no "equations", so unchanged files recomputed from an empty signal dict -> all-zero drift and drops. `equations` is the exact inverse of hit_vector, so reconstruct it in the rehydrator. Effect on the curl oracle: child-commit coverage 368 -> 880 of 1134, and the risk diffs shrink. Still divergent: class_count/function_count (functions/classes not yet rehydrated from function_data/class_data) and a few unparsed helper scripts. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Wg5S99Jrd2oXxnUmeKwvx2
…ta (#3220) The statistical auditor keeps an ambiguous file only if it has named structure (len(functions)+len(classes) > 0); rehydrated files had neither, so ~254 unchanged files were banished to the exclusion queue, and every file's function_count/ class_count read 0. Reconstruct both lists per file from function_data/class_data: - per-function hit_vector is a DICT keyed by hit-column (signal_processor does hv.get(col)), NOT a list like the file-level vector; - func["branch"] carries the complexity metric the z-score/archetype math reads; - parent_class_name resolved via parent_class_id -> class_data.class_name; - all other persisted per-function/-class columns carried through unchanged. curl oracle: child-commit coverage 880 -> 1028 of 1134, no more crashes. Remaining: ~106 zero-structure config/data files still dropped (need lock_tier restored) and a few risk_cognitive_load/safety_score/state_flux diffs on script files. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Wg5S99Jrd2oXxnUmeKwvx2
Contributor
…rvive audit (#3220) Files with no named structure (config/data: .yaml, .txt, extensionless helper scripts) are kept by the statistical auditor only if their identity_lock_tier < 4. _calculate_risk_exposures rebuilds that tier from meta["lock_tier"] (default 4), so rehydrated files all looked like tier-4 guesses and the zero-structure ones were dropped. A rehydrated file WAS confidently identified in the baseline, so restore a confident lock at the meta level (lock_tier/source_proof/intensity -- none are persisted columns, so row parity is unaffected). curl oracle: child-commit coverage 1028 -> 1134 of 1134 == FULL COVERAGE. Only value diffs remain: risk_cognitive_load/safety_score/state_flux on a few script files. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Wg5S99Jrd2oXxnUmeKwvx2
…me (#3220) network_risk_sensor / signal_processor read a function's hit_vector as hv.get("test"), hv.get("decorators"), hv.get("branch") -- SIGNAL_SCHEMA names -- while function_data stores the SHORT_KEY_MAP-renamed columns (def_test, struct_decorators, struct_branch). Reconstruct the dict keyed by signal name with values from those columns so per-function archetype/density lookups resolve. Full file coverage (1134/1134) holds; remaining diff is 3 risk signals on ~5 files in small perl/shell strata (under investigation: likely per-stratum normalization sensitivity). Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Wg5S99Jrd2oXxnUmeKwvx2
…ator test (#3220) test_rehydrator_successful_load asserted the old lossy hit_vector == []. The rehydrator now reconstructs full risk_vector/hit_vector + an equations dict; on the minimal mock DB (no risk_/hit columns) those come back as correctly-sized all-zero containers. Assert that instead. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Wg5S99Jrd2oXxnUmeKwvx2
Drop an unused BLE001 noqa and guard the parent_class_id lookup so mypy is happy (the key can be None on rows without a parent class). Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Wg5S99Jrd2oXxnUmeKwvx2
…weighting (#3220) The score layer computes cognitive_load/safety_score/state_flux from _weighted(raw_signals, _proximity_tally(meta)), where _proximity_tally reads meta["mitigation_telemetry"] -- the detector's proximity-correlation tally (mitigated_danger / amplified_cascading_flux ...). It was never persisted, so a delta scan's rehydrated files got an empty tally and those three signals came back un-amplified (lower). Persist it as a JSON file_data column (guarded-ALTER heal for old DBs) and restore it in the rehydrator. curl oracle: the cognitive_load/safety_score/state_flux diffs are gone. Next layer exposed: risk_verification/documentation (doc_umbrella not yet restored) and risk_api_exposure (graph popularity -> raw_imports). Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Wg5S99Jrd2oXxnUmeKwvx2
…tches (#3220) _calc_documentation dampens risk_documentation by meta["metadata"]["doc_umbrella"], a parse-time documentation shield that was never persisted -> rehydrated files defaulted it to 0.0 and risk_documentation drifted. Persist it as a file_data column and seed it back into meta["metadata"] (which _calculate_risk_exposures preserves). curl oracle: risk_documentation diffs gone. Remaining: risk_verification (per-function untested-impact) and risk_api_exposure (graph popularity of widely-included headers). Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Wg5S99Jrd2oXxnUmeKwvx2
…on (#3220) _calc_verification sizes untested impact from each function's "impact" (round(magnitude,1), a parse-time structural weight). function_data never stored it, so rehydrated functions defaulted impact=0.0 and risk_verification drifted. Persist it as a trailing function_data column; the rehydrator's column carry-through restores func["impact"]. curl oracle: 3 of 4 risk_verification diffs cleared. Remaining: 1 verification file and risk_api_exposure on widely-included headers (graph popularity -> raw_imports). Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Wg5S99Jrd2oXxnUmeKwvx2
#3220) Rehydrated files carried an empty raw_imports, so the delta graph resolver rebuilt no edges FROM unchanged files -> in-degree (popularity) of widely-imported headers was undercounted and risk_api_exposure drifted. Persist the pre-resolution import strings (JSON file_data column) and restore them so build_dependency_graph resolves the full edge set. curl oracle: all risk_api_exposure header diffs cleared. Remaining: risk_verification on 5 files (next: calls_out_to is persisted as a JSON string but consumed as a list). Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Wg5S99Jrd2oXxnUmeKwvx2
…3220) function_data.calls_out_to is persisted as a JSON string but consumed as a list (network_risk_sensor's test-coverage mapping iterates it); decode it via a small _json_list helper. Also removes the temporary #3220 diagnostics. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Wg5S99Jrd2oXxnUmeKwvx2
…tion (#3220) The slicer's synthetic top-level buckets (__global_context__ / Anonymous_Block) are excluded from function_count/aggregations but _calc_verification DOES sum their impact. They were never persisted, so a delta rehydrate saw zero functions for files whose only "functions" are synthetic (shell/config scripts) and risk_verification diverged. Persist ALL functions incl. synthetic (flagged is_synthetic_slice + impact); counts/aggregations still use the filtered list, so function_count is unchanged, and the rehydrator's column carry-through restores the flag so real_functions filtering and verification both see the same set a full scan does. curl oracle: clears risk_verification on pure-synthetic files (appveyor.sh etc.). Remaining residual is the umbrella_bonus coefficient computed over excluded-file LOC (excluded_artifacts stores no coding_loc) -- a whole-repo-statistic gap; rounding it proved to be whack-a-mole (perturbs other umbrella-derived signals), so that is left for a targeted excluded-LOC fix, not a coefficient round. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Wg5S99Jrd2oXxnUmeKwvx2
…gression) + lint (#3220) CI on this branch surfaced three real problems with the previous commit: 1. rosetta-audit REGRESSION: persisting synthetic function slices to function_data inflated units_documented (audit_score_inputs.py counts function_data rows) across db2_sql/matlab/ruby/sqlite. That corpus-metric regression outweighs the 4th-decimal risk_verification parity gain on synthetic-only files, so REVERT the synthetic-slice write. Keep the func `impact` column (real functions only -- no extra rows, no regression; it fixed risk_verification on real-function .c files). 2. ruff RUF005: convert the func-row and repo_data-row list concatenations to iterable unpacking; ruff format the rehydrator. 3. dead-key-audit: allowlist the delta rehydrator's sqlite Row column reads (func_name/func_archetype/parent_class_id/complexity/class_name + _cid/_fp join aliases) -- Row columns the recorder wrote, same false-positive class as the manifest/model-file keys already allowlisted. (The earlier TypeError was from the reverted synthetic-slice path; gone now.) Net: keeps every non-regressing fidelity fix; drops the one change that moved the control corpus. Residual parity gap is risk_verification on synthetic-slice files (irreducible without regressing units_*) + the umbrella/excluded-LOC coefficient. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Wg5S99Jrd2oXxnUmeKwvx2
… edit (#3220) The zero-tolerance format check flagged record_keeper.py (whitespace only, from the agg_hits -> iterable-unpacking change). No logic change. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Wg5S99Jrd2oXxnUmeKwvx2
…round-trip safely (#3220) raw_imports entries are usually import strings but can be (module, alias) tuples (aliased imports), so sorted() over the mixed list raised TypeError('<' tuple vs str) in the golden-record recorder tests. Persist without sorting, encoding tuples as lists; the rehydrator restores lists->tuples into the set (hashable, and the resolver distinguishes string vs tuple imports). Order is irrelevant -- it round-trips to a set. Fixes the full-suite golden-record failures (test_uncomputed_graph_metrics / test_edge_data): 15 pass locally. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Wg5S99Jrd2oXxnUmeKwvx2
squid-protocol
added a commit
that referenced
this pull request
Sep 20, 2026
…#3227) (#3234) * fix(delta): persist raw_imports in a deterministic order (follow-up to #3227) #3220 persisted raw_imports with `json.dumps(sorted(...))`. That raised TypeError('<' not supported between tuple and str) on the mixed str/(module, entity) list, and #3227 fixed it by dropping the sort entirely. The order is not irrelevant. A rehydrated file's raw_imports is a set (state_rehydrator._json_import_set; test_state_rehydrator.py:132 asserts it), so persisting it in iteration order makes the column hash-seed dependent: seed 0: ["m/n.py", "missing_pkg", "src/lib.py", "z/y.py", ...] seed 1: ["m/n.py", "missing_pkg", ["src/lib.py","helper"], "a/b.py", ...] seed 2: ["src/util.py", ["src/lib.py","helper"], "src/lib.py", ...] That order is the order the resolver walks the imports, which is the order `_publish_edges` emits rows, which is the order #3183 assigns AUTOINCREMENT ids in. Edge VALUES are safe -- weight/import_statements/entity_imports accumulate with `+=`, and addition is commutative -- but row order and ids are not, in a change whose purpose is delta parity. `_ordered_raw_imports` sorts in two groups so a str is never compared to a tuple, which is what broke the original sorted(). Verified stable across PYTHONHASHSEED 0/1/2/99/12345. Scope note: no production path actually emits a tuple today. galaxyscope.py:734 builds raw_imports from `raw_imports.add(clean_module)` (strings only), and both it and :2048 would themselves raise on a tuple. The (module, entity) shape is live only in network_risk_sensor's "Level 2" branch and the test_edge_data fixture, so the tuple handling stays as defensive support -- the reachable bug is the ordering one, over a rehydrated set of plain strings. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * test(delta): import _json_import_set directly instead of the module CodeQL note: `gitgalaxy.core.state_rehydrator` was imported both as a module (`import ... as sr`) and with `from ... import StateRehydrator`. Only one symbol was needed from the module form, so it joins the existing `from` import and the alias goes away entirely -- rather than the suggested `StateRehydrator = sr.StateRehydrator` rebinding, which keeps both import forms and adds a shadowing assignment. 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]>
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.
Description
Closes #3220.
--incremental(Delta Scan) was a silent no-op:StateRehydrator.load_statereadfile_datacolumns that don't exist (total_downstream/total_upstream), threwIndexError, and a broadexceptswallowed it — so every delta scan fell back to afull scan. Fixing that exposed the deeper problem: rehydration was lossy (restored
~10 of ~250 fields), so even when engaged it couldn't reproduce a full scan.
This makes the rehydrator faithful — the persisted DB becomes a replayable
snapshot:
risk_vector/hit_vector/equationsby inverting therecorder's own schema maps (can't drift from the write).
functions/classesfromfunction_data/class_data(per-functionhit_vectorkeyed by SIGNAL_SCHEMA name;impactnow persisted).mitigation_telemetry,doc_umbrella,raw_imports(tuples handled),func.impact.Result (curl oracle, full-scan@X vs incremental→X): full file coverage and
bit-exact on 12 of 13 risk vectors + all structural/graph/function columns, up
from "silent full-fallback / garbage".
Known residual (follow-up):
risk_verificationstill differs on a few files/repo.Two causes, both deliberately left: (1) synthetic top-level slices are consumed by the
verification math but persisting them regresses
units_documented(corpus metric), and(2) the repo-wide
umbrella_bonuscoefficient is computed over soon-to-be-excludedfiles' LOC that a delta can't reconstruct (
excluded_artifactsstores nocoding_loc).Neither is worth the ripple; tracked as the remaining tail on #3220.
Notes
CI
flag-golden-master-changes/crucible-auditare green.file_dataschema inventing the missing columns)is corrected, and a full-vs-incremental parity oracle exists
(
temporal-crucible/tools/parity_check.py).🤖 Generated with Claude Code