Skip to content

feat(miner-manage): local SQLite schema for run-state, claim ledger, and PR portfolio #4272

Description

@JSONbored

The three local stores this title names already exist and work — packages/gittensory-miner/lib/run-state.js (miner_run_state table, own run-state.sqlite3 file, initRunStateStore), claim-ledger.js (miner_claims table, own claim-ledger.sqlite3, openClaimLedger, #2291/#2314), and portfolio-queue.js (miner_portfolio_queue table, own portfolio-queue.sqlite3, initPortfolioQueueStore, #2292). Each is independently coded: its own resolveXDbPath env-var resolution (GITTENSORY_MINER_X_DBGITTENSORY_MINER_CONFIG_DIRXDG_CONFIG_HOME/~/.config), its own mkdirSync(…, 0o700) + chmodSync(…, 0o600) setup, its own PRAGMA busy_timeout — the same ~15 lines hand-duplicated four times (run-state.js:12-33, claim-ledger.js:17-38, portfolio-queue.js:17-38, and event-ledger.js:18-39 the same pattern again). There is no shared base module (local-store.js/db-common.js or similar) anywhere in packages/gittensory-miner/lib/.

There's also no dedicated "PR portfolio" table. manage-status.js (#2325/#3070) synthesizes PR-portfolio rows at READ time by joining portfolio-queue.js rows (using a pr:{number} identifier convention — MANAGED_PR_IDENTIFIER_PREFIX in manage-status.js:6) against event-ledger.js's free-form JSON manage_pr_update events, reduced via a full linear scan (indexLatestManageUpdates, manage-status.js:42-53) on every single read. The actual PR-shaped fields — branch, ciState, gateVerdict, outcome, lastPolledAt — live only as opaque JSON blobs in the general event ledger, not as indexed/queryable columns of their own.

So the remaining gap here isn't "create the schema" — it's (a) documenting the four local stores as one coherent local-storage model (the package README currently describes each store in isolated paragraphs — packages/gittensory-miner/README.md:27-37 — with no single section listing all local SQLite files/tables together), (b) extracting the duplicated path-resolution/permission boilerplate into one shared helper the four modules call into, and (c) deciding — and documenting the decision — whether the PR-portfolio's read-time join is the intended long-term shape or whether it should become a first-class indexed table once PR-portfolio reads get frequent (e.g., from the dashboard panel in the sibling manage-phase issue).

Deliverables

  • Extract the duplicated resolveXDbPath / mkdirSync(0o700) + chmodSync(0o600) / busy_timeout boilerplate (currently hand-copied in run-state.js:12-33, claim-ledger.js:17-38, portfolio-queue.js:17-38, event-ledger.js:18-39) into one shared internal helper in packages/gittensory-miner/lib/
  • Migrate all four stores to the shared helper without changing their public API or on-disk file layout (each keeps its own .sqlite3 file and env var — this is a DRY pass, not a merge into one database)
  • Add a "Local storage" section to packages/gittensory-miner/README.md documenting all four local SQLite stores together: file name, table name, module, and the env vars that override each path
  • Explicitly document (in the README or a short design note) that the "PR portfolio" is currently a read-time join of portfolio-queue.js (via the pr: identifier convention) against event-ledger.js's manage_pr_update events, not a dedicated table — and record the decision on whether that's intended to stay that way
  • Keep all existing tests green; add a regression test asserting the four stores still use independent files/paths after the refactor (no accidental merge)

References

  • packages/gittensory-miner/lib/run-state.js:12-33,52-93 (resolveRunStateDbPath, initRunStateStore, miner_run_state table)
  • packages/gittensory-miner/lib/claim-ledger.js:17-38,75-94 (resolveClaimLedgerDbPath, openClaimLedger, miner_claims table)
  • packages/gittensory-miner/lib/portfolio-queue.js:17-38,79-98 (resolvePortfolioQueueDbPath, initPortfolioQueueStore, miner_portfolio_queue table)
  • packages/gittensory-miner/lib/event-ledger.js:18-39,109-127 (same boilerplate pattern once more, for comparison)
  • packages/gittensory-miner/lib/manage-status.js:6,42-53 (MANAGED_PR_IDENTIFIER_PREFIX, indexLatestManageUpdates — the read-time PR-portfolio join)
  • packages/gittensory-miner/README.md:27-37 (current per-store documentation, no unified section)

Metadata

Metadata

Assignees

No one assigned

    Labels

    gittensor:featureGittensor-scored feature linked to a feature issue — scores a 0.25x multiplier.gittensor:priorityMaintainer-selected Gittensor priority — scores a 1.5x multiplier.help wantedExtra attention is needed

    Projects

    Status
    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions