Skip to content

fix(miner): add the tenant_id column to governor-ledger and plan-store - #6707

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
galuis116:fix/miner-ledger-tenant-id-columns
Jul 16, 2026
Merged

fix(miner): add the tenant_id column to governor-ledger and plan-store#6707
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
galuis116:fix/miner-ledger-tenant-id-columns

Conversation

@galuis116

Copy link
Copy Markdown
Contributor

Summary

#4939 ("Add tenant-scoping columns to all local ledger schemas") added an additive, nullable
tenant_id TEXT column to every local ledger schema as a prerequisite for any future hosted,
multi-tenant use of the same ledger logic. governor-ledger.js and plan-store.js — two of the
package's seven canonical local stores (tracked by both status.js's storeIntegrityChecks and
migrate-cli.js's STORES) — were left out despite #4939 being closed as complete; both still call
applySchemaMigrations(db, []) with an empty migrations array.

  • governor_events (governor-ledger.js) and miner_plans (plan-store.js) both gain an additive
    addTenantIdColumn migration, mirroring event-ledger.js's/run-state.js's existing implementation
    exactly: a PRAGMA table_info column-presence guard before ALTER TABLE ... ADD COLUMN tenant_id TEXT, idempotent against a file already migrated.
  • No consumer reads or writes tenant_id yet in either store — self-host behavior is byte-identical:
    every existing row and every newly-inserted row has tenant_id = NULL, matching Add tenant-scoping columns to all local ledger schemas #4939's own stated
    behavior for the other four stores.
  • A fresh governor-ledger.js/plan-store.js store now reports PRAGMA user_version = 2 (baseline 1
    plus the one new migration); a pre-existing on-disk file upgrades in place with every existing row
    preserved.

Test plan

  • test/unit/miner-governor-ledger.test.ts: new schema migrations (#6597) describe block —
    v1→v2 upgrade preserves existing rows and adds the column (verified via readSchemaVersion), a
    regression test for a v1 file that already unusually carries tenant_id (no duplicate-column
    error), and a fresh-store user_version = 2 assertion — 14/14 passing
  • test/unit/miner-plan-store.test.ts: identical three-test shape for plan-store.js — 14/14
    passing
  • Verified zero uncovered lines/branches on this diff's exact changed-line ranges in both source
    files via scoped vitest --coverage + direct lcov DA:/BRDA: inspection (the aggregate coverage
    numbers for these two files are below the informational 90% local threshold only because of
    pre-existing, unrelated gaps elsewhere in each file — none inside this diff)
  • Regression sweep: test/unit/miner-status.test.ts, test/unit/miner-migrate-cli.test.ts,
    test/unit/miner-governor-ledger-cli.test.ts, test/unit/miner-plan-store-cli.test.ts,
    test/unit/governor-ledger.test.ts — 64/64 passing
  • node --check on both changed files (this package's own build script convention) — clean
  • git diff --check, npm run actionlint, npm audit --audit-level=moderate — all clean
  • No manifest/OpenAPI/DB-migration changes needed — a packages/** + test/** diff only (these
    are the miner CLI's own local SQLite stores, unrelated to the product's root migrations/)

Closes #6597

JSONbored#4939 added an additive, nullable tenant_id column to every local ledger
schema as a prerequisite for any future hosted, multi-tenant use, but
governor-ledger.js and plan-store.js were left out despite being two of the
package's seven canonical local stores -- both still called
applySchemaMigrations(db, []) with an empty migrations array.

Adds addTenantIdColumn to both, mirroring event-ledger.js's and
run-state.js's existing implementation exactly (idempotent against a
column-presence guard). No consumer reads or writes tenant_id yet, so
self-host behavior is byte-identical: every row's tenant_id is NULL.

Closes JSONbored#6597
@galuis116
galuis116 requested a review from JSONbored as a code owner July 16, 2026 19:52
@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 (50d86f1).
⚠️ Report is 20 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6707   +/-   ##
=======================================
  Coverage   93.65%   93.65%           
=======================================
  Files         681      682    +1     
  Lines       68098    68120   +22     
  Branches    18695    18702    +7     
=======================================
+ Hits        63775    63796   +21     
  Misses       3347     3347           
- Partials      976      977    +1     
Flag Coverage Δ
shard-1 43.83% <100.00%> (-0.07%) ⬇️
shard-2 36.94% <50.00%> (+0.09%) ⬆️
shard-3 32.28% <50.00%> (-0.11%) ⬇️
shard-4 34.57% <50.00%> (-0.08%) ⬇️
shard-5 31.66% <100.00%> (+0.72%) ⬆️
shard-6 45.78% <50.00%> (+0.11%) ⬆️

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

Files with missing lines Coverage Δ
packages/loopover-miner/lib/governor-ledger.js 98.36% <100.00%> (+0.08%) ⬆️
packages/loopover-miner/lib/plan-store.js 92.38% <100.00%> (+0.22%) ⬆️

... and 1 file with indirect coverage changes

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 16, 2026
@loopover-orb

loopover-orb Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-16 20:09:05 UTC

4 files · 1 AI reviewer · no blockers · readiness 83/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This PR closes a gap left by #4939 by adding the same additive, nullable tenant_id migration to governor-ledger.js and plan-store.js that already exists in event-ledger.js/run-state.js/prediction-ledger.js. The implementation is a verbatim copy of the established pattern (PRAGMA table_info guard + ALTER TABLE, wired into applySchemaMigrations), and both stores are byte-identical for existing consumers since nothing reads/writes tenant_id yet. Tests cover v1→v2 upgrade with row preservation, an idempotency regression for an already-migrated file, and fresh-store version stamping, matching the pattern used elsewhere in the codebase.

Nits — 2 non-blocking
  • The migration comment block is duplicated verbatim across governor-ledger.js and plan-store.js (and prediction-ledger.js before it); consider a shared migration factory (e.g. `addTenantIdColumn(tableName)`) in schema-version.js to avoid drifting copies across five+ files.
  • Consider extracting the repeated PRAGMA table_info column-presence guard into a single exported helper in schema-version.js, parameterized by table name, since this is now the fourth or fifth near-identical copy of this function.

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #6597
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ❌ 8/20 High review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 1955 registered-repo PR(s), 1287 merged, 54 issue(s).
Contributor context ✅ Confirmed Gittensor contributor galuis116; Gittensor profile; 1955 PR(s), 54 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
The PR adds addTenantIdColumn (with the required PRAGMA table_info guard) to both governor-ledger.js and plan-store.js, wires it into applySchemaMigrations replacing the empty arrays, and adds matching tests in both test files verifying user_version=2, row preservation, and idempotency, fulfilling all stated requirements and deliverables.

Review context
  • Author: galuis116
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: JavaScript, Python, Dart, TypeScript, HTML, MDX, Rust, C++
  • Official Gittensor activity: 1955 PR(s), 54 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Add a concise scope and risk note.
  • Then work through the remaining 2 steps in the Signals table above.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask 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.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

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.

  • Re-run LoopOver review

@loopover-orb loopover-orb Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoopOver approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit 28f7f05 into JSONbored:main Jul 16, 2026
16 checks passed
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.

governor-ledger.js and plan-store.js are missing the tenant_id column #4939 was supposed to add everywhere

1 participant