Skip to content

fix(miner): report the real post-failure schema version for a partially-applied migration - #6860

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
jeffrey701:fix-migrate-partial-version-6767
Jul 17, 2026
Merged

fix(miner): report the real post-failure schema version for a partially-applied migration#6860
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
jeffrey701:fix-migrate-partial-version-6767

Conversation

@jeffrey701

Copy link
Copy Markdown
Contributor

Closes #6767

Problem

migrateStore (packages/loopover-miner/lib/migrate-cli.js) reports versionAfter: versionBefore in its catch branch — "nothing changed". But schema-version.js's applySchemaMigrations applies and stamps each migration in its own transaction, specifically so a failure part-way through leaves the file at the last fully-applied version. So when open(dbPath) throws while applying migration N of several pending ones, the migrations before N have already committed to disk and the real on-disk version has advanced past versionBefore — but the catch never re-reads it, and the failed result misreports what's actually on disk.

Fix

Re-read the real on-disk version in the catch branch, guarded by its own try: a genuinely corrupt/unopenable file (the same case that can leave versionBefore null) may fail this read too, in which case the pre-failure reading is all we can honestly report.

Tests

test/unit/miner-migrate-cli.test.ts adds a regression test that injects a store whose open runs a migrations array where the first migration commits (stamping BASELINE+1) and the second throws — asserting the reported versionAfter is BASELINE+1 (the real partial progress) and that it matches the file's actual on-disk PRAGMA user_version. It fails before the fix (expected 1 to be 2).

Both branches of the new guard are covered:

  • re-read succeeds → the new regression test;
  • re-read throws → the existing "corrupted file" case, whose unreadable file makes the re-read throw too, falling back to versionBefore.

Existing expectations are unchanged (the fake-store case still reports versionAfter: 0).

Validation

  • npx vitest run test/unit/miner-migrate-cli.test.ts11/11 pass (10 existing + 1 new)
  • npm run typecheckclean (0 errors)
  • Scope: 1 source file + 1 test file (+67/−1)

@jeffrey701
jeffrey701 requested a review from JSONbored as a code owner July 17, 2026 09:03
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.64%. Comparing base (615dd46) to head (03bef9e).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6860   +/-   ##
=======================================
  Coverage   93.64%   93.64%           
=======================================
  Files         685      685           
  Lines       68238    68242    +4     
  Branches    18707    18707           
=======================================
+ Hits        63903    63907    +4     
  Misses       3350     3350           
  Partials      985      985           
Flag Coverage Δ
shard-1 43.23% <0.00%> (-0.46%) ⬇️
shard-2 36.93% <0.00%> (+0.24%) ⬆️
shard-3 32.59% <0.00%> (-0.12%) ⬇️
shard-4 34.36% <0.00%> (-0.40%) ⬇️
shard-5 31.48% <100.00%> (+0.33%) ⬆️
shard-6 45.97% <0.00%> (+0.27%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/loopover-miner/lib/migrate-cli.js 100.00% <100.00%> (ø)

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 17, 2026
@loopover-orb

loopover-orb Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-17 09:11:49 UTC

2 files · 1 AI reviewer · no blockers · readiness 88/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This fixes a real bug: migrateStore's catch branch hardcoded versionAfter to versionBefore, misreporting the schema version when applySchemaMigrations commits some migrations before a later one throws. The fix re-reads the on-disk version in the catch, guarded by its own try/catch to handle the case where the file itself is now unreadable, falling back to versionBefore. The regression test correctly exercises the real applySchemaMigrations per-migration-transaction behavior rather than fabricating an impossible state, and verifies against the actual on-disk PRAGMA user_version.

Nits — 2 non-blocking
  • migrate-cli.js: the inner try/catch could just let peekSchemaVersion's exception fall through since versionAfter is already initialized to versionBefore, making the explicit catch block redundant (`let versionAfter = versionBefore; try { versionAfter = peekSchemaVersion(dbPath); } catch {}` would suffice without reassigning in the catch).
  • migrate-cli.js:88-93: simplify the try/catch to an empty catch block since versionAfter is already defaulted to versionBefore before the try.

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #6767
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ❌ 8/20 High review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 121 registered-repo PR(s), 59 merged, 30 issue(s).
Contributor context ✅ Confirmed Gittensor contributor jeffrey701; Gittensor profile; 121 PR(s), 30 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
The diff adds a guarded re-read of the on-disk schema version in migrateStore's catch branch, falling back to versionBefore only if that read itself throws, exactly matching the issue's requirement, and includes a regression test with a multi-migration array where a later migration fails after an earlier one commits, asserting the reported versionAfter reflects real partial progress.

Review context
  • Author: jeffrey701
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: TypeScript, Clojure, JavaScript, Rust
  • Official Gittensor activity: 121 PR(s), 30 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Add a concise scope and risk note.
  • Then work through the remaining 1 step in the Signals table above.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@loopover-orb loopover-orb Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoopOver approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit 4b786b1 into JSONbored:main Jul 17, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

migrate's per-store failure report understates a partially-applied migration

1 participant