Skip to content

fix(miner): route orb-export, deny-hook-synthesis, and laptop-init through openLocalStoreDb (#8319)#8500

Closed
philluiz2323 wants to merge 1 commit into
JSONbored:mainfrom
philluiz2323:fix-miner-local-store-crash-safety-8319
Closed

fix(miner): route orb-export, deny-hook-synthesis, and laptop-init through openLocalStoreDb (#8319)#8500
philluiz2323 wants to merge 1 commit into
JSONbored:mainfrom
philluiz2323:fix-miner-local-store-crash-safety-8319

Conversation

@philluiz2323

Copy link
Copy Markdown
Contributor

Summary

  • Three local SQLite stores in packages/loopover-miner hand-rolled the same open boilerplate directly against node:sqlite's DatabaseSync instead of routing through local-store.ts's openLocalStoreDb, bypassing its crash-safety registration entirely — a SIGINT/SIGTERM/uncaught-exception mid-write was not guaranteed to close the handle cleanly the way every openLocalStoreDb-routed store already is (Add signal/crash handling to the miner CLI #4826). Closed issue governor-ledger.js, prediction-ledger.js, and plan-store.js bypass local-store.js's crash-safe openLocalStoreDb #6595 previously fixed this exact bypass class for governor-ledger.js/prediction-ledger.js/plan-store.js.
  • orb-export.ts's openOrbExportStore and deny-hook-synthesis.ts's initDenyHookSynthesisStore: replaced the manual mkdirSync/new DatabaseSync/chmodSync/PRAGMA busy_timeout sequence with openLocalStoreDb(resolvedPath), dropping the now-redundant steps, mirroring plan-store.ts's openPlanStore exactly.
  • laptop-init.ts's initLaptopState: same substitution — this was the one store with no busy-timeout and no crash-safety registration at all.
  • No on-disk contract changes (table names, permissions, busy-timeout value all unchanged). checkLaptopStateSqlite's separate read-only DatabaseSync open and laptop-init.ts's local resolveMinerStateDir duplication are untouched, per the issue's explicit scope.
  • Adds a crash-safe-cleanup-registration test to each file's suite, mirroring local-store.ts's own openLocalStoreDb registration test (cleanupResourceCount()/resetProcessLifecycleForTesting()).

Closes #8319

Scope

  • The PR title follows type(scope): short summary Conventional Commit format, for example fix(api): restore profile access checks.
  • This PR is focused and does not mix unrelated backend, UI, MCP, docs, dependency, and deploy changes.
  • This follows CONTRIBUTING.md and does not reintroduce GitHub Pages, VitePress, site/, or CNAME.
  • I linked an issue, or this is small enough that the summary explains why an issue is not needed.

Validation

  • git diff --check
  • npm run actionlint
  • npm run typecheck
  • npm run test:coverage locally; codecov/patch requires ≥99% coverage of the lines AND branches you changed (aim for 100% on your diff so CI variance does not fail near the threshold). Global coverage is a non-blocking trend with a loose 90% backstop, not the gate.
  • npm run test:workers
  • npm run build:mcp
  • npm run test:mcp-pack
  • npm run ui:openapi:check
  • npm run ui:lint
  • npm run ui:typecheck
  • npm run ui:build
  • npm audit --audit-level=moderate
  • New or changed behavior has unit/integration tests for new branches, fallback paths, and sanitizer boundaries

If any required check was skipped, explain why:

  • packages/loopover-miner/** is not Codecov-gated per the issue's own note, and this change touches no UI/MCP/workers/OpenAPI surface. Both npm run typecheck (root) and npm --workspace @loopover/miner run build:tsc (the package's own, separate tsconfig) pass clean. Verified via npx vitest run test/unit/miner-orb-export.test.ts test/unit/miner-deny-hook-synthesis.test.ts test/unit/miner-laptop-init.test.ts: 60/64 tests pass, including all 3 new crash-safety-registration tests. The 4 pre-existing failures (Windows path-separator assertions expecting forward slashes, and a Windows file-lock EBUSY on temp-dir cleanup) are confirmed unrelated — reproduced identically on a clean stash of this branch's base commit before any of this PR's changes existed; none of the 4 touch the functions this PR changes.

Safety

  • No secrets, wallet details, hotkeys, coldkeys, user PATs, private keys, raw trust scores, private rankings, or private maintainer evidence are exposed.
  • Public GitHub text stays sanitized, low-noise, and does not imply compensation guarantees or optimization tactics.
  • Auth, cookie, CORS, GitHub App, Cloudflare, or session changes include negative-path tests. (N/A — no auth/session/CORS changes.)
  • API/OpenAPI/MCP behavior is updated and tested where needed. (N/A — no API/OpenAPI/MCP surface changed.)
  • UI changes use live API data or real empty/error/loading states, not production mock/demo fallbacks. (N/A — no UI changes.)
  • Visible UI changes include a UI Evidence section below with JPG/JPEG or PNG screenshots. (N/A — no visible UI changes.)
  • Public docs/changelogs are updated where needed; changelogs are only edited for release-prep PRs. (N/A.)

Notes

  • Verified no import cycle for laptop-init.ts importing openLocalStoreDb from ./local-store.js, per the issue's own guidance: local-store.ts imports only from process-lifecycle.js and store-db-adapter.js, neither of which imports laptop-init.ts.

…rough openLocalStoreDb (JSONbored#8319)

Three of the package's local SQLite stores hand-rolled the same open
boilerplate directly against node:sqlite's DatabaseSync instead of routing
through local-store.ts's openLocalStoreDb, bypassing its crash-safety
registration entirely -- a SIGINT/SIGTERM/uncaught-exception mid-write
was not guaranteed to close the handle cleanly the way every
openLocalStoreDb-routed store already is (JSONbored#4826, closed issue JSONbored#6595
previously fixed this exact bypass for governor-ledger/prediction-ledger/
plan-store).

- orb-export.ts's openOrbExportStore and deny-hook-synthesis.ts's
  initDenyHookSynthesisStore: replace the manual mkdirSync/new
  DatabaseSync/chmodSync/PRAGMA busy_timeout sequence with
  openLocalStoreDb(resolvedPath), dropping the now-redundant steps.
- laptop-init.ts's initLaptopState: same substitution -- this was the one
  store with no busy-timeout and no crash-safety registration at all.

No on-disk contract changes (table names, permissions, busy-timeout
value). Adds a crash-safe-cleanup-registration test to each file's test
suite, mirroring local-store.ts's own openLocalStoreDb registration test
(cleanupResourceCount()/resetProcessLifecycleForTesting()).
checkLaptopStateSqlite's separate read-only DatabaseSync open and
laptop-init.ts's local resolveMinerStateDir duplication are untouched,
per the issue's explicit scope.
@philluiz2323
philluiz2323 requested a review from JSONbored as a code owner July 24, 2026 15:50
@superagent-security

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.24%. Comparing base (b554e15) to head (eecad9d).
⚠️ Report is 30 commits behind head on main.

Files with missing lines Patch % Lines
packages/loopover-miner/lib/deny-hook-synthesis.ts 0.00% 1 Missing ⚠️
packages/loopover-miner/lib/laptop-init.ts 0.00% 1 Missing ⚠️
packages/loopover-miner/lib/orb-export.ts 0.00% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (99.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8500      +/-   ##
==========================================
- Coverage   92.50%   88.24%   -4.27%     
==========================================
  Files         791      100     -691     
  Lines       79335    23051   -56284     
  Branches    23964     3990   -19974     
==========================================
- Hits        73388    20341   -53047     
+ Misses       4807     2532    -2275     
+ Partials     1140      178     -962     
Flag Coverage Δ
shard-1 0.00% <0.00%> (-57.78%) ⬇️
shard-2 0.00% <0.00%> (-47.31%) ⬇️
shard-3 0.00% <0.00%> (-55.83%) ⬇️

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

Files with missing lines Coverage Δ
packages/loopover-miner/lib/deny-hook-synthesis.ts 0.00% <0.00%> (-96.97%) ⬇️
packages/loopover-miner/lib/laptop-init.ts 0.00% <0.00%> (-99.30%) ⬇️
packages/loopover-miner/lib/orb-export.ts 0.00% <0.00%> (-100.00%) ⬇️

... and 691 files with indirect coverage changes

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

loopover-orb Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Caution

🛑 LoopOver review result - fixes required

Review updated: 2026-07-24 16:39:22 UTC

6 files · 1 AI reviewer · no blockers · CI failing · unstable

🛑 Suggested Action - Fix Blockers

Review summary
This PR routes three miner-local SQLite stores (orb-export, deny-hook-synthesis, laptop-init) through the shared openLocalStoreDb helper, replacing hand-rolled mkdirSync/chmodSync/PRAGMA busy_timeout sequences with the centralized call that also registers crash-safe cleanup. The change is a faithful, narrow substitution matching plan-store.ts's existing pattern, with no on-disk contract changes, and each modified file gets a matching crash-safe registration/unregistration test. laptop-init.ts is correctly called out as the one store that previously had no busy-timeout and no crash-safety registration at all.

Nits — 3 non-blocking
  • The codecov/patch check failed at 0% coverage, which given BASE BRANCH STATUS showing this branch is 15 commits behind default is more likely explained by branch staleness than by these changes lacking tests — but it's worth confirming after a rebase.
  • test/unit/miner-orb-export.test.ts and miner-deny-hook-synthesis.test.ts import cleanupResourceCount/resetProcessLifecycleForTesting via relative path rather than any shared test helper — consistent with existing imports in the same files, so just a style note, not an issue.
  • Rebase onto the current default branch to see whether the codecov/patch failure resolves, before treating it as a real coverage gap in this diff.

CI checks failing

  • codecov/patch — 0.00% of diff hit (target 99.00%)

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 #8319
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 ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 1040 registered-repo PR(s), 615 merged, 126 issue(s).
Contributor context ✅ Confirmed Gittensor contributor philluiz2323; Gittensor profile; 1040 PR(s), 126 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
All three files (orb-export.ts, deny-hook-synthesis.ts, laptop-init.ts) now open their DB via openLocalStoreDb, dropping the redundant manual mkdirSync/chmodSync/PRAGMA calls exactly as requested, and each has an added test asserting crash-safe cleanup registration/unregistration.

Review context
  • Author: philluiz2323
  • 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: 1040 PR(s), 126 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Triage stale or unlinked PRs.
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 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

LoopOver is closing this pull request on the maintainer's behalf (CI is failing (codecov/patch)). This is an automated maintenance action — to pursue this change, please open a new pull request with the issues resolved. Closed PRs may be analyzed later to improve review accuracy, but they are not automatically reopened or re-reviewed.

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.

fix(miner): orb-export.ts, deny-hook-synthesis.ts, and laptop-init.ts bypass local-store.js's crash-safe openLocalStoreDb

1 participant