Skip to content

fix(db): fold seven raw-SQL identity tables into renameRepositoryIdentity#8409

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
kai392:fix/critical-issue-rename-identity-raw-sql-tables
Jul 24, 2026
Merged

fix(db): fold seven raw-SQL identity tables into renameRepositoryIdentity#8409
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
kai392:fix/critical-issue-rename-identity-raw-sql-tables

Conversation

@kai392

@kai392 kai392 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

A repository-rename webhook left seven raw-SQL-only, identity-bearing tables — all with confirmed live writers — pinned to the stale owner/repo: the Orb PR-outcome ledger, the Orb webhook-delivery log, the live and shadow tunable overrides, the override-audit trail, and both predicted-gate history tables. renameRepositoryIdentity now covers them, using env.DB.prepare(...) directly like the module's existing review_audit/contributor_gate_history/submitter_stats blocks (none of these tables are in the Drizzle schema, per their own migration headers).

Each table uses the fold strategy its real constraint requires — verified against each migration, not inferred from column names:

Table Constraint Strategy
orb_pr_outcomes PRIMARY KEY (repository_full_name, pr_number) fold on the other half of the composite key (pr_number), same shape as submitter_stats
orb_webhook_events PK delivery_id; repo column nullable, no unique plain rename, same as signal_snapshots
override_audit PK id is random ova_<ts36>_<random>, project index non-unique plain rename — the id never embeds the project, so no substring rewrite
tunables_overrides / _shadow project TEXT PRIMARY KEY delete the new name's anchor row, then rename — same shape as repositories
predicted_gate_calibration_ledger PK id, id+target_id embed project substring rewrite of project/id/target_id + PK-collision fold, identical to review_audit
predicted_gate_calls PK id, id embeds project same, minus target_id (this table has none)

Closes #8380

Test plan

  • 12 new assertions across six describe blocks in test/unit/repo-identity-rename.test.ts, each mirroring the existing raw-SQL blocks' style: rows move to the new name; the collision fold keeps the old row's data (asserted on real column values, not just row counts); a different PR/submitter/other-repo row under the new name survives untouched; orb_webhook_events' NULL-repo rows stay NULL; override_audit ids are left verbatim; both predicted-gate tables get id/target_id rewrite and renamed-id-collision fold cases
  • Suite green (69/69, all pre-existing assertions unmodified)
  • Local coverage on src/db/repo-identity-rename.ts: 134/134 lines, 39/40 branches — the single partial branch is pre-existing at line 60, far outside this diff (lines 417-491), so every changed line and branch is covered
  • npm run typecheck clean
  • CI validate

@kai392
kai392 requested a review from JSONbored as a code owner July 24, 2026 11:49
@superagent-security

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.64%. Comparing base (fab2fce) to head (4f90078).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8409      +/-   ##
==========================================
- Coverage   92.17%   89.64%   -2.54%     
==========================================
  Files         791       98     -693     
  Lines       79249    22841   -56408     
  Branches    23945     3892   -20053     
==========================================
- Hits        73048    20475   -52573     
+ Misses       5062     2187    -2875     
+ Partials     1139      179     -960     
Flag Coverage Δ
shard-1 99.25% <100.00%> (+40.50%) ⬆️
shard-2 0.00% <0.00%> (-50.52%) ⬇️
shard-3 56.29% <52.00%> (+2.99%) ⬆️

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

Files with missing lines Coverage Δ
src/db/repo-identity-rename.ts 99.25% <100.00%> (+0.16%) ⬆️

... and 693 files with indirect coverage changes

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

loopover-orb Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-24 12:15:45 UTC

2 files · 1 AI reviewer · no blockers · readiness 95/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This PR extends renameRepositoryIdentity to cover seven previously-orphaned raw-SQL identity tables (orb_pr_outcomes, orb_webhook_events, override_audit, tunables_overrides/_shadow, predicted_gate_calibration_ledger, predicted_gate_calls), each using the fold strategy matching its actual constraint (composite-key fold, plain rename, or PK-anchor delete-then-rename). The strategies are correctly matched to the constraints described (e.g. orb_pr_outcomes folds on pr_number for its composite PK, tunables tables delete the anchor row for their single-column PK, predicted_gate tables do substring id rewrite + PK-collision fold mirroring the existing review_audit pattern), and each addition is covered by a dedicated collision/regression test asserting real column values, not just row counts. This closes #8380 and directly extends an existing, already-reviewed module using its own established conventions rather than introducing a new pattern.

Nits — 5 non-blocking
  • src/db/repo-identity-rename.ts is now ~494 lines in one function; per the size-smell flag this file has crossed the repo's stated 400-line threshold and could be worth splitting into per-table helper functions even while keeping the explicit-per-table style.
  • The seven new blocks repeat the same SELECT-ids -> map -> DELETE-if-any -> UPDATE pattern already used four times above (review_audit, contributor_gate_history, pullRequestReviews, collisionEdges) — consider factoring just the `oldIds -> renamedIds -> collision-delete` sequence into a small local helper to cut duplication, without breaking the deliberate per-table-query convention noted in the file's own header comment.
  • No migration diff is included here to confirm these seven tables and their exact constraints (PK shapes, nullability) match what's asserted in the description — worth double-checking against the actual `migrations/*.sql` files for each table before merge, since the whole strategy selection hinges on those constraints being exactly as described.
  • Consider extracting the repeated 'select ids under old name -> compute renamed ids -> delete colliding renamed ids -> UPDATE with replace()' sequence (used identically for review_audit, contributor_gate_history, predicted_gate_calibration_ledger, predicted_gate_calls) into one small helper taking table/id-column/extra-column params, reducing near-identical blocks.
  • Given the file is now ~494 lines, consider whether splitting REES/parity raw-SQL blocks into a separate co-located file (e.g. repo-identity-rename-raw-sql.ts) would keep each file under the repo's own size threshold while preserving the per-table explicit style.

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 #8380
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: 117 registered-repo PR(s), 62 merged, 4 issue(s).
Contributor context ✅ Confirmed Gittensor contributor kai392; Gittensor profile; 117 PR(s), 4 issue(s).
Improvement ✅ Minor risk: clean · value: minor
Linked issue satisfaction

Addressed
The diff adds all seven raw-SQL tables to renameRepositoryIdentity using the exact fold strategies specified per table (fold-then-rename for orb_pr_outcomes/tunables_overrides(_shadow), plain rename for orb_webhook_events/override_audit, and id/target_id/project substring rewrite with collision fold for predicted_gate_calibration_ledger/predicted_gate_calls), matching every deliverable checkbox in

Review context
  • Author: kai392
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: not available
  • Official Gittensor activity: 117 PR(s), 4 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Triage stale or unlinked PRs.
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 c02da85 into JSONbored:main Jul 24, 2026
12 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

2 participants