Skip to content

fix(miner): scope run-state by forge host, not bare repoFullName - #5585

Merged
JSONbored merged 1 commit into
mainfrom
forge-scope-run-state
Jul 13, 2026
Merged

fix(miner): scope run-state by forge host, not bare repoFullName#5585
JSONbored merged 1 commit into
mainfrom
forge-scope-run-state

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Summary

  • run-state.js's repo_full_name TEXT PRIMARY KEY let two forge hosts (github.com vs. a GitHub Enterprise host, De-hardcode discovery from gittensory's own conventions #4784) serving a same-named owner/repo share one "current discover/plan/prepare state" row.
  • Rebuilds the constraint to PRIMARY KEY (api_base_url, repo_full_name), backfilling existing rows with the pre-De-hardcode discovery from gittensory's own conventions #4784 implicit default https://api.github.com. The migration uses INSERT OR IGNORE so a pre-existing row with an already-invalid state (this store's own read path already fails closed on those, per an existing test) can't abort the whole rebuild.
  • Threads an optional apiBaseUrl through the store's API (getRunState/setRunState) and the admin CLI (--api-base-url on state get/state set).
  • Every existing caller is unaffected: apiBaseUrl defaults to https://api.github.com when omitted.
  • manage-status.js's collectRunPortfolio folds run state into one row per repo name (not per host) for its dashboard view — documented in-code as a known, safe (no data loss, read-only) display limitation for the narrow case of the same repo name existing on two hosts, rather than silently patched over.

Third of 5 stores from #5563 (claim-ledger.js landed in #5576, portfolio-queue.js in #5583; governor-state.js's reputation table and deny-hook-synthesis.js follow).

Test plan

  • npx vitest run test/unit/miner-run-state.test.ts test/unit/miner-cli-run-state.test.ts test/unit/miner-manage-status.test.ts test/unit/miner-migrate-cli.test.ts test/unit/miner-loop-cli.test.ts — all passing, including a migration test (pre-existing on-disk file upgrades and preserves rows) and cross-host coexistence regression tests
  • Caught and fixed a real bug during testing: the migration originally crashed on a legacy row with an invalid state value (rejected by the rebuilt table's CHECK constraint) — fixed with INSERT OR IGNORE, consistent with the store's existing fail-closed read behavior for the same corrupt-data case
  • npx tsc --noEmit clean
  • npm run build:miner clean
  • npm run test:coverage (full, unsharded) — 15817/15829 passing (12 pre-existing skips), 100% patch coverage on touched lines/branches
  • npm audit --audit-level=moderate — 0 vulnerabilities

@superagent-security

Copy link
Copy Markdown
Contributor

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

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 13, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
loopover-ui 742f5ed Commit Preview URL

Branch Preview URL
Jul 13 2026, 07:27 AM

@JSONbored JSONbored self-assigned this Jul 13, 2026
@JSONbored JSONbored linked an issue Jul 13, 2026 that may be closed by this pull request
4 tasks
repo_full_name TEXT PRIMARY KEY let two forge hosts (github.com vs. a
GitHub Enterprise host, #4784) serving a same-named owner/repo share one
"current discover/plan/prepare state" row. Rebuild the constraint to
PRIMARY KEY (api_base_url, repo_full_name), backfilling existing rows with
the pre-#4784 implicit default. The migration uses INSERT OR IGNORE so a
pre-existing row with an already-invalid state (this store's read path
already fails closed on those) can't abort the whole rebuild.

Thread an optional apiBaseUrl through the store's API (getRunState/
setRunState) and the admin CLI (--api-base-url on state get/set). Every
existing caller is unaffected: apiBaseUrl defaults to
https://api.github.com when omitted.

manage-status.js's collectRunPortfolio folds run state into one row per
repo NAME (not per host) for its dashboard view -- documented in-code as a
known, safe (no data loss, read-only) display limitation for the narrow
case of the same repo name existing on two hosts, rather than silently
patched over; broadening that fold to be host-aware is a separate,
larger dashboard-shape change.

Advances #5563 (run-state.js of 5 affected stores; claim-ledger.js landed
in #5576, portfolio-queue.js in #5583).
@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5585   +/-   ##
=======================================
  Coverage   94.99%   94.99%           
=======================================
  Files         573      573           
  Lines       45490    45512   +22     
  Branches    14680    14680           
=======================================
+ Hits        43212    43235   +23     
+ Misses       1527     1526    -1     
  Partials      751      751           
Flag Coverage Δ
shard-1 44.04% <57.14%> (+<0.01%) ⬆️
shard-2 35.66% <0.00%> (-0.01%) ⬇️
shard-3 31.94% <28.57%> (-0.23%) ⬇️
shard-4 31.77% <0.00%> (-1.10%) ⬇️
shard-5 32.94% <31.42%> (+1.08%) ⬆️
shard-6 44.38% <60.00%> (+0.20%) ⬆️

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

Files with missing lines Coverage Δ
packages/gittensory-miner/lib/manage-status.js 96.80% <ø> (ø)
packages/gittensory-miner/lib/run-state-cli.js 96.59% <100.00%> (+1.99%) ⬆️
packages/gittensory-miner/lib/run-state.js 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JSONbored
JSONbored merged commit b1d3e8d into main Jul 13, 2026
18 checks passed
@JSONbored
JSONbored deleted the forge-scope-run-state branch July 13, 2026 07:32
@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 13, 2026
JSONbored added a commit that referenced this pull request Jul 13, 2026
… repoFullName (#5591)

repo_full_name TEXT PRIMARY KEY let two forge hosts (github.com vs. a
GitHub Enterprise host, #4784) serving a same-named owner/repo share one
reputation-history row. Rebuild the constraint to
PRIMARY KEY (api_base_url, repo_full_name), following governor-state.js's
existing idempotent-ALTER convention (ensurePauseColumns) rather than
introducing the applySchemaMigrations framework into this file for the
first time -- a full PRIMARY KEY rebuild still needs the create-new/copy/
drop/rename dance, just gated by a column-presence check instead of a
version stamp.

Uses INSERT OR IGNORE for the copy step (a corrupted legacy row violating
the rebuilt table's NOT NULL columns is dropped, not a migration-aborting
crash), regression-tested the same way as run-state.js's #5563 fix.

Threads an optional apiBaseUrl through loadReputationHistory/
saveReputationHistory. loadReputationHistory/saveReputationHistory have no
real callers yet (attempt-runner.js's own comments note this governor
input isn't wired into the attempt pipeline yet), so there is no CLI
surface or call site to thread through -- this is purely the storage-layer
fix, mirroring openClaimLedgerReadOnly's scaffold-only precedent.

Advances #5563 (governor_reputation_history of 5 affected stores;
claim-ledger.js landed in #5576, portfolio-queue.js in #5583, run-state.js
in #5585; deny-hook-synthesis.js remains).
JSONbored added a commit that referenced this pull request Jul 13, 2026
…re repoFullName (#5595)

deny_rule_proposals' PRIMARY KEY (repo_full_name, id) let two forge hosts
(github.com vs. a GitHub Enterprise host, #4784) serving a same-named
owner/repo share one proposal row (and its maintainer approval decision).
Rebuild the constraint to PRIMARY KEY (api_base_url, repo_full_name, id).

This file has no schema-version framework of its own (unlike the
package's other local stores) -- it uses a raw DatabaseSync connection, no
applySchemaMigrations. Follows governor-state.js's idempotent
column-presence-gated rebuild convention instead of introducing a new
framework dependency here for the first time. Uses INSERT OR IGNORE for
the copy step, matching the fix already applied to every other #5563
migration in this epic: a legacy row with an already-invalid status value
(this store's own CHECK-constrained schema already rejects those) is
dropped, not a migration-aborting crash.

Threads an optional apiBaseUrl through refreshProposals/listProposals/
setProposalStatus/resolveEffectiveRules. initDenyHookSynthesisStore has no
real callers yet (feeds the consumption surface #2343 will eventually wire
into evaluateDenyHooks; this store owns derivation + audit, not live hook
interception), so there is no CLI surface or call site to thread through --
purely the storage-layer fix, mirroring governor_reputation_history's
scaffold-only precedent.

Closes #5563 (5th and final store: claim-ledger.js in #5576,
portfolio-queue.js in #5583, run-state.js in #5585, governor-state.js in
#5591, plus the claimNextBatch/migration hardening follow-up in #5594).
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.

Scope local ledger keys by forge host, not bare repoFullName

1 participant