Skip to content

worktree-allocator.js's own comment claims to mirror stores that migrated to openLocalStoreDb, but it never did #6600

Description

@JSONbored

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

  • packages/loopover-miner/lib/worktree-allocator.js migrated onto openLocalStoreDb/resolveLocalStoreDbPath/normalizeLocalStoreDbPath, with its header comment updated.
  • A test in test/unit/miner-worktree-allocator.test.ts asserting the opened store is registered as a cleanup resource and unregistered on close().

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    gittensor:bugGittensor-scored bug fix — scores a 0.05x multiplier.help wantedExtra attention is needed

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions