Context
packages/loopover-miner/lib/worktree-allocator.js's own header comment reads: "Mirrors the package's existing local-store pattern (run-state.js, claim-ledger.js, portfolio-queue.js) — plain JS + node:sqlite, never phones home." That comment is now stale: since #4272, run-state.js, claim-ledger.js, and portfolio-queue.js all open their SQLite handle through packages/loopover-miner/lib/local-store.js's openLocalStoreDb, which — beyond deduplicating the mkdirSync/chmodSync/PRAGMA busy_timeout boilerplate — registers the handle via registerCleanupResource (packages/loopover-miner/lib/process-lifecycle.js, #4826) so a SIGINT/SIGTERM/crash mid-write is flushed/closed cleanly.
worktree-allocator.js itself still hand-rolls the exact mkdirSync/new DatabaseSync(...)/chmodSync/PRAGMA busy_timeout sequence those three files used to have, and its own comment invokes them as the pattern it's supposedly following. Because it never calls openLocalStoreDb, the worktree-slot allocator — which tracks which git-worktree paths are leased to which fleet attempts, i.e. exactly the kind of state a killed process can leave stuck — is not registered for crash-safe cleanup, unlike the three stores its own comment claims to mirror.
Requirements
packages/loopover-miner/lib/worktree-allocator.js MUST open its database handle by calling openLocalStoreDb (imported from ./local-store.js) instead of hand-rolling mkdirSync/new DatabaseSync(...)/chmodSync/PRAGMA busy_timeout.
worktree-allocator.js MUST switch its resolveWorktreeAllocatorDbPath/path-normalization logic to use resolveLocalStoreDbPath/normalizeLocalStoreDbPath from ./local-store.js, matching claim-ledger.js's and run-state.js's existing usage.
resolveWorktreeBaseDir (the separate worktree-checkout directory resolver, not the SQLite DB path) MUST be left untouched — it resolves a filesystem directory for git worktrees, not a store DB path, and is out of scope for this migration.
- No behavior change to the public API, schema, or the env vars honored (
LOOPOVER_MINER_WORKTREE_ALLOCATOR_DB, LOOPOVER_MINER_CONFIG_DIR, XDG_CONFIG_HOME must all still resolve identically).
- The header comment's "Mirrors the package's existing local-store pattern" line MUST be updated to state that it now opens through
local-store.js's openLocalStoreDb directly, rather than merely resembling the other three files' pattern by hand.
- After the change, opening the worktree allocator MUST increase
packages/loopover-miner/lib/process-lifecycle.js's cleanupResourceCount() by one, and closing it via its own close() MUST decrease it back.
Deliverables
Test Coverage Requirements
packages/loopover-miner/lib/worktree-allocator.js is under packages/**, covered by this repo's 99%+ Codecov patch gate — every changed line (the new openLocalStoreDb/resolveLocalStoreDbPath call sites and the removed hand-rolled open code) must be exercised by the existing or newly-added unit tests.
Expected Outcome
worktree-allocator.js actually mirrors the local-store pattern its own comment describes, opening its SQLite handle identically to run-state.js/claim-ledger.js/portfolio-queue.js, and a SIGINT/SIGTERM/crash mid-write to the worktree-slot table is flushed/closed by installCliSignalHandlers exactly as it already is for those three stores.
Links & Resources
Context
packages/loopover-miner/lib/worktree-allocator.js's own header comment reads: "Mirrors the package's existing local-store pattern (run-state.js,claim-ledger.js,portfolio-queue.js) — plain JS + node:sqlite, never phones home." That comment is now stale: since #4272,run-state.js,claim-ledger.js, andportfolio-queue.jsall open their SQLite handle throughpackages/loopover-miner/lib/local-store.js'sopenLocalStoreDb, which — beyond deduplicating themkdirSync/chmodSync/PRAGMA busy_timeoutboilerplate — registers the handle viaregisterCleanupResource(packages/loopover-miner/lib/process-lifecycle.js, #4826) so a SIGINT/SIGTERM/crash mid-write is flushed/closed cleanly.worktree-allocator.jsitself still hand-rolls the exactmkdirSync/new DatabaseSync(...)/chmodSync/PRAGMA busy_timeoutsequence those three files used to have, and its own comment invokes them as the pattern it's supposedly following. Because it never callsopenLocalStoreDb, the worktree-slot allocator — which tracks which git-worktree paths are leased to which fleet attempts, i.e. exactly the kind of state a killed process can leave stuck — is not registered for crash-safe cleanup, unlike the three stores its own comment claims to mirror.Requirements
packages/loopover-miner/lib/worktree-allocator.jsMUST open its database handle by callingopenLocalStoreDb(imported from./local-store.js) instead of hand-rollingmkdirSync/new DatabaseSync(...)/chmodSync/PRAGMA busy_timeout.worktree-allocator.jsMUST switch itsresolveWorktreeAllocatorDbPath/path-normalization logic to useresolveLocalStoreDbPath/normalizeLocalStoreDbPathfrom./local-store.js, matchingclaim-ledger.js's andrun-state.js's existing usage.resolveWorktreeBaseDir(the separate worktree-checkout directory resolver, not the SQLite DB path) MUST be left untouched — it resolves a filesystem directory for git worktrees, not a store DB path, and is out of scope for this migration.LOOPOVER_MINER_WORKTREE_ALLOCATOR_DB,LOOPOVER_MINER_CONFIG_DIR,XDG_CONFIG_HOMEmust all still resolve identically).local-store.js'sopenLocalStoreDbdirectly, rather than merely resembling the other three files' pattern by hand.packages/loopover-miner/lib/process-lifecycle.js'scleanupResourceCount()by one, and closing it via its ownclose()MUST decrease it back.Deliverables
packages/loopover-miner/lib/worktree-allocator.jsmigrated ontoopenLocalStoreDb/resolveLocalStoreDbPath/normalizeLocalStoreDbPath, with its header comment updated.test/unit/miner-worktree-allocator.test.tsasserting the opened store is registered as a cleanup resource and unregistered onclose().Test Coverage Requirements
packages/loopover-miner/lib/worktree-allocator.jsis underpackages/**, covered by this repo's 99%+ Codecov patch gate — every changed line (the newopenLocalStoreDb/resolveLocalStoreDbPathcall sites and the removed hand-rolled open code) must be exercised by the existing or newly-added unit tests.Expected Outcome
worktree-allocator.jsactually mirrors the local-store pattern its own comment describes, opening its SQLite handle identically torun-state.js/claim-ledger.js/portfolio-queue.js, and a SIGINT/SIGTERM/crash mid-write to the worktree-slot table is flushed/closed byinstallCliSignalHandlersexactly as it already is for those three stores.Links & Resources
packages/loopover-miner/lib/local-store.js(feat(miner-manage): local SQLite schema for run-state, claim ledger, and PR portfolio #4272)packages/loopover-miner/lib/process-lifecycle.js(Add signal/crash handling to the miner CLI #4826)packages/loopover-miner/lib/claim-ledger.js/run-state.js(reference implementations already usingopenLocalStoreDb)