fix(miner): open the worktree allocator through local-store's openLocalStoreDb - #6704
Conversation
…alStoreDb (JSONbored#6600) The allocator's own header comment claimed to mirror run-state.js/claim-ledger.js/ portfolio-queue.js, but those have opened via openLocalStoreDb since JSONbored#4272 while this still hand-rolled the mkdirSync/DatabaseSync/chmodSync/PRAGMA sequence they used to have. Going through the helper is what calls registerCleanupResource (JSONbored#4826), so the allocator was never registered for crash-safe cleanup -- despite being the store where a SIGINT/SIGTERM mid-write strands a worktree slot leased to a dead process. Env-var resolution is unchanged: the deleted inline resolver was line-for-line what resolveLocalStoreDbPath already does. resolveWorktreeBaseDir is untouched -- it resolves a git-worktree checkout directory, not a store DB path. Closes JSONbored#6600
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6704 +/- ##
==========================================
- Coverage 93.65% 93.64% -0.01%
==========================================
Files 681 682 +1
Lines 68098 68090 -8
Branches 18695 18697 +2
==========================================
- Hits 63775 63766 -9
Misses 3347 3347
- Partials 976 977 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
|
Tip ✅ LoopOver review result - approve/merge recommendedReview updated: 2026-07-16 20:03:48 UTC
Review summary Nits — 4 non-blocking
Decision drivers
Context & advisory signals — never blocks the verdict
Linked issue satisfactionAddressed Review context
Contributor next steps
Signal definitions
🧪 Chat with LoopOverAsk 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.
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.
|
LOOPOVER_MINER_WORKTREE_ALLOCATOR_DB's default value in the generated docs went stale after lib/worktree-allocator.js's local-store DB open path changed (JSONbored#6704) without a regeneration; miner:env-reference:check has been failing on main since. Re-run npm run miner:env-reference.
Summary
worktree-allocator.js's header comment claimed it "Mirrors the package's existing local-store pattern (run-state.js,claim-ledger.js,portfolio-queue.js)". Since #4272 those three open throughlocal-store.js'sopenLocalStoreDb; this one still hand-rolled the identicalmkdirSync/new DatabaseSync(...)/chmodSync/PRAGMA busy_timeoutsequence they used to have.That's not cosmetic.
openLocalStoreDbis what callsregisterCleanupResource(#4826), so a SIGINT/SIGTERM/crash mid-write is flushed and closed byinstallCliSignalHandlers. Because the allocator never called it, it was not registered — and it is precisely the store where that matters most: it tracks which worktree paths are leased to which attempts, so a killed process is exactly what strands a slot leased to a PID that no longer exists. The comment asserting it mirrored those three files is what made the gap easy to miss.The change
openLocalStoreDb(resolvedPath); the hand-rolled mkdir/DatabaseSync/chmod/PRAGMA block is gone.resolveWorktreeAllocatorDbPath→resolveLocalStoreDbPath(defaultDbFileName, "LOOPOVER_MINER_WORKTREE_ALLOCATOR_DB", env), andnormalizeDbPath→normalizeLocalStoreDbPath(...), matchingrun-state.js/claim-ledger.jsexactly.Env-var resolution is unchanged: the inline resolver I deleted was line-for-line what
resolveLocalStoreDbPathalready does, soLOOPOVER_MINER_WORKTREE_ALLOCATOR_DB,LOOPOVER_MINER_CONFIG_DIRandXDG_CONFIG_HOMEstill resolve identically, in the same precedence order.close()needed no change:openLocalStoreDbwrapsdb.closeto unregister first, so the existingclose()unregisters for free.Two things worth a reviewer's eye
resolveWorktreeBaseDiris untouched, per the issue — it resolves a git-worktree checkout directory, not a store DB path.mkdirSynctherefore stays imported and is still used for that tree; only the DB handle's own mkdir/chmod moved into the helper. The import carries a comment saying so, since "why isnode:fsstill here?" is the obvious next question.normalizeDbPathgets slightly stricter, deliberately. The old code did(dbPath ?? resolve()).trim(), which threw aTypeErroron a non-string; the shared helper type-checks and throws the sameinvalid_worktree_allocator_db_paththe empty-string case already threw. That's the sibling stores' behavior and a strictly better error, not a behavior regression on any valid input.Tests
cleanupResourceCount()goes0 → 1on open and back to0onclose(); the other assertscloseAllCleanupResources()— whatinstallCliSignalHandlersinvokes on SIGINT/SIGTERM — actually closes an allocator left open mid-write. That second one is the real user-facing guarantee, not just the registration bookkeeping.miner-local-store.test.ts's existing#4826block.afterEachclose via a smallownClosehelper:close()is not idempotent (node:sqlite throws "database is not open"), so a test that closes the handle itself must own its lifetime. The helper documents that so the next person doesn't rediscover it via a confusing failure.Validation
codecov/patchwall onpackages/loopover-miner/lib/**.npm run build:miner(node --checkacross every lib file) passes.miner-worktree-allocator,miner-worktree-allocator-collisions,miner-concurrent-store-races,miner-local-store-readme,miner-local-store.The remaining local failures are pre-existing and not mine — verified, not assumed. The same 4 tests fail identically on clean
mainwith my work stashed:miner-local-store's andminer-worktree-allocator's DB-path and file-mode cases. They're Windows-only (\vs/separators, andstatSync().mode & 0o077returning54rather than0, since Windows has no POSIX permission bits). Same count, same tests, before and after.Scope
packages/,test/).resolveWorktreeBaseDir, and the honored env vars are all unchanged.site/,CNAME, orlovablechanges.Safety
Closes #6600