Skip to content

refactor(miner): open worktree-allocator through openLocalStoreDb for crash-safe cleanup - #6705

Closed
ultrahighsuper wants to merge 2 commits into
JSONbored:mainfrom
ultrahighsuper:fix/worktree-allocator-openlocalstore-6600
Closed

refactor(miner): open worktree-allocator through openLocalStoreDb for crash-safe cleanup#6705
ultrahighsuper wants to merge 2 commits into
JSONbored:mainfrom
ultrahighsuper:fix/worktree-allocator-openlocalstore-6600

Conversation

@ultrahighsuper

Copy link
Copy Markdown
Contributor

What

packages/loopover-miner/lib/worktree-allocator.js's header comment claimed to mirror the package's local-store pattern (run-state.js / claim-ledger.js / portfolio-queue.js), but those three migrated to local-store.js's openLocalStoreDb (#4272/#4826) — which, beyond deduplicating the mkdirSync/chmodSync/PRAGMA busy_timeout boilerplate, registers the handle via registerCleanupResource so a SIGINT/SIGTERM/crash mid-write is flushed/closed cleanly. worktree-allocator.js still hand-rolled its open and was therefore not registered — despite tracking exactly the kind of leased-slot state a killed process leaves stuck.

Resolves #6600.

Change

  • Open via openLocalStoreDb(resolvedPath) instead of the hand-rolled mkdirSync/new DatabaseSync/chmodSync/PRAGMA sequence.
  • Resolve/normalize the DB path via resolveLocalStoreDbPath / normalizeLocalStoreDbPath — the same env vars (LOOPOVER_MINER_WORKTREE_ALLOCATOR_DB, LOOPOVER_MINER_CONFIG_DIR, XDG_CONFIG_HOME, home default) resolve identically — matching claim-ledger.js / run-state.js.
  • resolveWorktreeBaseDir (the git-worktree checkout directory, not the DB path) is left untouched, per scope.
  • Header comment updated to state it now opens through openLocalStoreDb.

Test

Adds a case asserting opening the allocator increases process-lifecycle.js's cleanupResourceCount() by one and its own close() decreases it back — the crash-safe-registration guarantee the three sibling stores already have.

Locally green: the new test passes; the existing behavioral tests are unchanged. (The only failures in this file are 2 pre-existing Windows-only cases — POSIX path separators and Unix file-mode bits — unrelated to this change and green on CI's Linux.) LF-clean, eslint clean.

… crash-safe cleanup (JSONbored#6600)

worktree-allocator.js's header comment claimed to mirror the package's local-store
pattern (run-state.js / claim-ledger.js / portfolio-queue.js), but those three
migrated to local-store.js's openLocalStoreDb (JSONbored#4272/JSONbored#4826) — which, beyond
deduplicating the mkdirSync/chmodSync/PRAGMA busy_timeout boilerplate, registers
the handle via registerCleanupResource so a SIGINT/SIGTERM/crash mid-write is
flushed/closed cleanly. worktree-allocator.js still hand-rolled the open and was
therefore NOT registered — despite tracking exactly the kind of leased-slot state
a killed process leaves stuck.

- Open via openLocalStoreDb(resolvedPath) instead of the hand-rolled
  mkdirSync/new DatabaseSync/chmodSync/PRAGMA sequence.
- Resolve/normalize the DB path via resolveLocalStoreDbPath /
  normalizeLocalStoreDbPath (same env vars — LOOPOVER_MINER_WORKTREE_ALLOCATOR_DB,
  LOOPOVER_MINER_CONFIG_DIR, XDG_CONFIG_HOME, home default — resolve identically),
  matching claim-ledger.js / run-state.js.
- resolveWorktreeBaseDir (the git-worktree checkout dir, not the DB path) is left
  untouched, per scope.
- Update the header comment to state it now opens through openLocalStoreDb.

Adds a test asserting opening the allocator increases cleanupResourceCount by one
and its own close() decreases it back.

Closes JSONbored#6600
@superagent-security

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.65%. Comparing base (3acc512) to head (a7e1b9b).
⚠️ Report is 20 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6705      +/-   ##
==========================================
- Coverage   93.65%   93.65%   -0.01%     
==========================================
  Files         681      682       +1     
  Lines       68098    68108      +10     
  Branches    18695    18702       +7     
==========================================
+ Hits        63775    63784       +9     
  Misses       3347     3347              
- Partials      976      977       +1     
Flag Coverage Δ
shard-1 43.85% <0.00%> (-0.06%) ⬇️
shard-2 36.94% <100.00%> (+0.09%) ⬆️
shard-3 32.27% <100.00%> (-0.13%) ⬇️
shard-4 34.58% <0.00%> (-0.08%) ⬇️
shard-5 31.65% <0.00%> (+0.72%) ⬆️
shard-6 45.76% <100.00%> (+0.10%) ⬆️

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

Files with missing lines Coverage Δ
packages/loopover-miner/lib/worktree-allocator.js 91.30% <100.00%> (-0.86%) ⬇️

... and 1 file with indirect coverage changes

@ultrahighsuper

Copy link
Copy Markdown
Contributor Author

Withdrawing — #6600 was resolved on main by #6704 while this was in review, so this change is now a duplicate and conflicts. Closing; no defect here, just a timing overlap.

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 16, 2026
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.

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

1 participant