Skip to content

fix(#2983): explicit baseline commit for StateRehydrator / --incremental - #3000

Merged
squid-protocol merged 3 commits into
mainfrom
fix/2983-explicit-baseline
Sep 13, 2026
Merged

squid-protocol merged 3 commits into
mainfrom
fix/2983-explicit-baseline

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Closes #2983.

Problem

StateRehydrator picked its delta-scan baseline as SELECT commit_hash FROM repo_data WHERE repo_name=? ORDER BY commit_date DESC LIMIT 1. That's right only for a DB holding one lineage scanned forward. The exposure-history program (#2982) accumulates many commits of one repo in a single DB (the schema keys state by (repo_name, commit_hash)), and there:

  1. "Latest by commit_date" isn't the baseline the caller means — an incremental scan rehydrates whichever commit has the newest author date, then git diff <that> produces a nonsense delta silently.
  2. Even forward walks aren't safe: commit dates are non-monotonic (rebases, clock skew, imported history).

Change

  • state_rehydrator.py — load_state(repo_name, commit_hash=None). None keeps today's latest-by-date behavior; an explicit hash is verified present for the repo and used directly. A missing hash returns None and prints a refusal — it never substitutes a different commit (the silent nonsense-delta this issue is about). load_latest_state kept as a thin back-compat alias.
  • galaxyscope.py — new --baseline COMMIT_SHA (default unset → unchanged behavior), threaded into the --incremental rehydrate call as load_state(project_name, args.baseline). Warns if --baseline is passed without --incremental. execute_incremental_scan needs nothing new — it already diffs against the baseline commit recorded in the rehydrated state.

Fully backward-compatible: default path is byte-identical to before.

Tests

tests/core_engine/test_state_rehydrator.py (8 existing + 3 new, all green):

  • explicit baseline rehydrates that commit's files, not the newest-by-date one;
  • a missing explicit baseline returns None (no silent substitution);
  • load_state(None) matches the legacy load_latest_state alias.

Ruff: source files clean; test file only trips S101 (assert-in-test), consistent with the rest of the suite.

Unlocks

The longitudinal mode #2982 is heading toward: onboard at commit X with one full scan, then walk history applying --incremental DB --baseline <previous> per commit.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HqtNR72fsoL5g57yBBYGX3

StateRehydrator picked its delta-scan baseline as `ORDER BY commit_date DESC
LIMIT 1`. That is correct only for a DB holding one lineage scanned forward. The
exposure-history program (#2982) accumulates many commits of one repo in a single
DB (keyed `(repo_name, commit_hash)`), where "latest by date" is not the baseline
the caller means — an incremental scan rehydrates whichever commit has the newest
author date and `git diff <that>` produces a nonsense delta silently. Commit dates
are also non-monotonic (rebases, clock skew, imported history), so even forward
walks aren't safe.

- state_rehydrator: add `load_state(repo_name, commit_hash=None)`. None keeps the
  latest-by-date behavior; an explicit hash is verified present for the repo and
  used directly — a missing hash returns None (refuses to substitute a different
  commit) rather than producing a silent nonsense diff. `load_latest_state` kept
  as a thin back-compat alias.
- galaxyscope: new `--baseline COMMIT_SHA` (default None, fully backward
  compatible), threaded into the `--incremental` rehydrate call; warns if given
  without `--incremental`. `execute_incremental_scan` unchanged — it already
  diffs against the baseline commit recorded in the rehydrated state.
- tests: explicit baseline selects that commit (not newest-by-date), missing
  baseline returns None, and `load_state(None)` matches the legacy alias.

Unlocks the longitudinal mode #2982 is heading toward: onboard at commit X, then
walk history with `--incremental DB --baseline <previous>` per commit.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HqtNR72fsoL5g57yBBYGX3
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

squid-protocol and others added 2 commits September 13, 2026 15:24
…state)

The CLI incremental path now calls StateRehydrator.load_state(...) (#2983), so
the rehydrator mocks in test_galaxyscope.py must stub load_state, not the
load_latest_state alias — otherwise the auto-mock returns a truthy value and the
None-baseline fallback assertion (execute_pipeline) never fires.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HqtNR72fsoL5g57yBBYGX3
@squid-protocol
squid-protocol marked this pull request as ready for review September 13, 2026 19:33
@squid-protocol
squid-protocol merged commit 7597946 into main Sep 13, 2026
29 checks passed
@squid-protocol
squid-protocol deleted the fix/2983-explicit-baseline branch September 13, 2026 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StateRehydrator: select an explicit baseline commit — 'latest by commit_date' breaks multi-commit history DBs and non-monotonic walks

1 participant