Skip to content

feat(miner): add tenant-scoping columns to all four local ledger schemas - #6340

Merged
loopover-orb[bot] merged 1 commit into
mainfrom
review/rent-a-loop-tenant-scoping-columns
Jul 16, 2026
Merged

feat(miner): add tenant-scoping columns to all four local ledger schemas#6340
loopover-orb[bot] merged 1 commit into
mainfrom
review/rent-a-loop-tenant-scoping-columns

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Summary

  • Adds an additive tenant_id TEXT column to every local SQLite store the miner's ledger logic touches: run-state, claim-ledger, portfolio-queue, event-ledger.
  • Follows each file's own established schema-migration convention (applySchemaMigrations + PRAGMA user_version), including the same defensive column-presence guard used by every prior additive migration in these files (e.g. portfolio-queue.js's leased_at/attempts_count additions).
  • Part of Rent-a-Loop's v1 tenant-scoping approach (Multi-tenant hosted architecture spec #4783): a tenant_id column, not physical per-tenant sharding.

Test plan

  • 8 new tests: a legacy-fixture migration test + an idempotent-rerun regression test per store
  • Fixed 2 pre-existing assertions broken by the new column (miner-claim-ledger's strict column-list check, miner-migrate-cli's hardcoded versionAfter for portfolio-queue)
  • Full npm run test:ci gate green
  • npm audit --audit-level=moderate clean

Closes #4939

…mas (#4939)

Adds an additive tenant_id column to every local SQLite store the
miner's ledger logic touches -- run-state, claim-ledger, portfolio-queue,
event-ledger -- following each file's own established schema-migration
convention (applySchemaMigrations + PRAGMA user_version, the same
defensive column-presence guard as every prior additive migration in
these files, e.g. portfolio-queue.js's leased_at/attempts_count
additions).

Schema-only, per #4783's tenancy spec informing this issue: nothing
reads or writes tenant_id yet (no consumer exists until a future hosted
deployment populates it), so self-host behavior is byte-identical --
every migrated row's tenant_id is NULL, exactly like every other
optional column this file family already ships that way.

Each store gets two new tests: a legacy-file migration test proving
the column lands correctly with existing rows untouched, and a
regression test proving a file that already has the column (a partial
prior migration attempt) doesn't crash on re-open. Also updates
miner-migrate-cli.test.ts's hardcoded target-version assertion, which
was pinned to the pre-existing migration count.
@superagent-security

Copy link
Copy Markdown
Contributor

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

@loopover-orb loopover-orb Bot added the gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x 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 02:54:02 UTC

9 files · 1 AI reviewer · no blockers · readiness 98/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This PR adds an additive `tenant_id TEXT` column to four local SQLite stores (event-ledger, run-state, claim-ledger, portfolio-queue) using each file's existing migration convention, with defensive column-presence guards consistent with prior additive migrations in these same files. The migration logic is correct and consistently applied, self-host behavior is unaffected since nothing reads/writes the column yet, and each store gets both a legacy-fixture migration test and an idempotent-rerun regression test. Two pre-existing assertions (strict column-list check, hardcoded migration version) were correctly updated to account for the new column.

Nits — 5 non-blocking
  • The four `addTenantIdColumn`/inline migration functions in event-ledger.js, run-state.js, claim-ledger.js, and portfolio-queue.js are near-identical boilerplate (PRAGMA table_info check + ALTER TABLE); consider a small shared helper (e.g. `addColumnIfMissing(db, table, column, type)`) to reduce duplication across the four files.
  • The comments repeat the same lengthy justification ('NULL for every row today -- self-host behavior is byte-identical...') verbatim in all four files, which is a lot of repeated prose to maintain if the tenant-scoping rationale changes.
  • Factor the repeated column-presence-guard pattern into a shared utility in a common migrations helper module, since it now appears five times (four new + the pre-existing portfolio-queue v3->v4 pattern it mirrors).
  • Consider a single changelog/doc comment referencing Add tenant-scoping columns to all local ledger schemas #4939 in one canonical location rather than duplicating the full rationale in each of the four files.
  • PR author also opened the linked issue — Link an issue that was opened by a different contributor, or provide a rationale for why this self-authored issue represents genuine discovery work.

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 #4939
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low 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: 42 registered-repo PR(s), 34 merged, 443 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 42 PR(s), 443 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
The PR adds an additive tenant_id column via each store's own migration convention to all four ledger schemas (run-state, claim-ledger, portfolio-queue, event-ledger), matching the issue's ask, with tests confirming self-host rows remain untouched (NULL) so single-tenant behavior is preserved.

Review context
  • Author: JSONbored
  • Role context: owner (maintainer lane)
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: not available
  • Official Gittensor activity: 42 PR(s), 443 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Treat this as maintainer-lane context rather than normal contributor-lane activity.
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 <question> answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat <question> 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://gittensory.aethereal.dev/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 d4a2c64 into main Jul 16, 2026
16 checks passed
@loopover-orb
loopover-orb Bot deleted the review/rent-a-loop-tenant-scoping-columns branch July 16, 2026 02:54
@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 95.60%. Comparing base (b1d7cd1) to head (729d750).
⚠️ Report is 34 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6340   +/-   ##
=======================================
  Coverage   95.60%   95.60%           
=======================================
  Files         596      596           
  Lines       47140    47152   +12     
  Branches    15008    15008           
=======================================
+ Hits        45068    45080   +12     
  Misses       1290     1290           
  Partials      782      782           
Flag Coverage Δ
shard-1 43.96% <73.33%> (-0.18%) ⬇️
shard-2 36.81% <100.00%> (+0.29%) ⬆️
shard-3 32.25% <100.00%> (-0.16%) ⬇️
shard-4 34.36% <46.66%> (-0.22%) ⬇️
shard-5 31.82% <73.33%> (+0.13%) ⬆️
shard-6 45.32% <100.00%> (+0.55%) ⬆️

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

Files with missing lines Coverage Δ
packages/loopover-miner/lib/claim-ledger.js 100.00% <100.00%> (ø)
packages/loopover-miner/lib/event-ledger.js 88.46% <100.00%> (+0.46%) ⬆️
packages/loopover-miner/lib/portfolio-queue.js 97.34% <100.00%> (+0.07%) ⬆️
packages/loopover-miner/lib/run-state.js 100.00% <100.00%> (ø)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tenant-scoping columns to all local ledger schemas

1 participant