Skip to content

fix(miner): stop doctor's ams-backtest-proposals check from creating and pruning the event ledger - #10264

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
bitfathers94:fix/issue-10002
Jul 31, 2026
Merged

fix(miner): stop doctor's ams-backtest-proposals check from creating and pruning the event ledger#10264
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
bitfathers94:fix/issue-10002

Conversation

@bitfathers94

Copy link
Copy Markdown
Contributor

fix(miner): stop doctor's ams-backtest-proposals check from creating and pruning the event ledger

checkAmsBacktestProposals opened the ledger through initEventLedger, which unconditionally
creates the file, runs schema migrations, and retention-prunes rows -- none of which a
read-only diagnostic command should ever trigger. Add openEventLedgerReadOnly, a
driver-enforced read-only connection mirroring checkStoreIntegrity's existsSync +
readOnly:true pattern, and only reach for it when the ledger file already exists; a missing
file now short-circuits straight to the "nothing to propose" detail without touching disk.

Closes #10002

…and pruning the event ledger

checkAmsBacktestProposals opened the ledger through initEventLedger, which unconditionally
creates the file, runs schema migrations, and retention-prunes rows -- none of which a
read-only diagnostic command should ever trigger. Add openEventLedgerReadOnly, a
driver-enforced read-only connection mirroring checkStoreIntegrity's existsSync +
readOnly:true pattern, and only reach for it when the ledger file already exists; a missing
file now short-circuits straight to the "nothing to propose" detail without touching disk.
@bitfathers94
bitfathers94 requested a review from JSONbored as a code owner July 31, 2026 15:01
@loopover-orb

loopover-orb Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-31 15:08:13 UTC

3 files · 1 AI reviewer · no blockers · readiness 93/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This PR fixes checkAmsBacktestProposals so it no longer opens the event ledger via initEventLedger (which unconditionally creates/migrates/prunes it), instead short-circuiting on a missing file via existsSync and using a new driver-enforced readOnly:true connection (openEventLedgerReadOnly) when the file exists. The fix correctly targets the root cause (the writer-oriented open path being used from a read-only diagnostic) and mirrors the existing checkStoreIntegrity pattern; tests add both a fresh-laptop no-create check and a regression test proving retention pruning isn't triggered even when an operator has opted into it. The fail-open catch-all is preserved and the new read-only-table-missing case correctly closes the connection before rethrowing.

Nits — 5 non-blocking
  • packages/loopover-miner/lib/event-ledger.ts: the `readOnly` vs `readonly` camelCase footgone is documented only in a comment; consider a small assertion or type-level guard so a future refactor can't silently reintroduce the lowercase typo.
  • test/unit/miner-status.test.ts: the two miner(doctor): checkAmsBacktestProposals creates and retention-prunes the event ledger from a read-only command #10002 tests (`doctor does not create the event ledger...` and the `REGRESSION:` one) overlap significantly in intent — worth consolidating or clearly differentiating their purpose in comments.
  • packages/loopover-miner/lib/status.ts:checkAmsBacktestProposals now has three exit paths (missing-file, success, catch) — consider a short comment noting that `existsSync` + readOnly open together close the TOCTOU window's only real consequence (throw, caught below), not a race that needs locking.
  • Consider extracting the `existsSync(dbPath)` + `openEventLedgerReadOnly` pattern into a small shared helper if a third read-only-only doctor check appears, to avoid re-deriving the same three-branch shape.
  • The JSDoc on `openEventLedgerReadOnly` is thorough; a one-line summary above the detailed block would make it skimmable for future readers.

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 #10002
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ⚠️ 20/25 Preflight is ready, but the PR body does not name the validation run.
Contributor workload ✅ 10/10 Author activity: 140 registered-repo PR(s), 99 merged, 3 issue(s).
Contributor context ✅ Confirmed Gittensor contributor bitfathers94; Gittensor profile; 140 PR(s), 3 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
The PR adds openEventLedgerReadOnly using the driver-enforced readOnly:true DatabaseSync form, and rewrites checkAmsBacktestProposals to short-circuit on existsSync(dbPath) before ever opening a handle, avoiding initEventLedger's create/migrate/prune path entirely while preserving the byte-identical detail strings and fail-open catch behavior. It leaves initEventLedger, pruneLedgerByRetention, and

Review context
  • Author: bitfathers94
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: not available
  • Official Gittensor activity: 140 PR(s), 3 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Add validation command/output.
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 <question> answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat <question> 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

@superagent-security

Copy link
Copy Markdown
Contributor

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

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

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.69%. Comparing base (0bc00ab) to head (711138a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10264      +/-   ##
==========================================
+ Coverage   80.60%   80.69%   +0.08%     
==========================================
  Files         283      285       +2     
  Lines       59101    59372     +271     
  Branches     7000     7086      +86     
==========================================
+ Hits        47641    47910     +269     
  Misses      11167    11167              
- Partials      293      295       +2     
Flag Coverage Δ
backend 99.26% <100.00%> (?)

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

Files with missing lines Coverage Δ
packages/loopover-miner/lib/event-ledger.ts 100.00% <100.00%> (ø)
packages/loopover-miner/lib/status.ts 98.85% <100.00%> (ø)

@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 6f3ac84 into JSONbored:main Jul 31, 2026
8 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 31, 2026
7 tasks
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.

miner(doctor): checkAmsBacktestProposals creates and retention-prunes the event ledger from a read-only command

1 participant