Skip to content

renameRepositoryIdentity omits 7 raw-SQL identity tables, including two structurally identical to already-fixed siblings review_audit/contributor_gate_history #8380

Description

@JSONbored

Context

src/db/repo-identity-rename.ts's renameRepositoryIdentity(env, oldFullName, newFullName) moves a repo's identity-bearing rows forward when GitHub delivers a repository-rename webhook, so history isn't orphaned under the stale old owner/repo name. Three raw-SQL-only tables (deliberately not in Drizzle's src/db/schema.ts, per each table's own migration header) already get this treatment inside the module: review_audit, contributor_gate_history, submitter_stats — each has a project column that is the repo full name (verified live at each table's writer), and the module rewrites project plus any id/target_id value that embeds it as a substring.

A companion audit (see the sibling Drizzle-schema issue for that half of the gap) found seven more raw-SQL tables with the identical repo-identity shape, all with live writers, none touched by renameRepositoryIdentity:

Table Column(s) Live writer Correct fold strategy
orb_pr_outcomes PRIMARY KEY (repository_full_name, pr_number) src/orb/outcomes.ts (recordOrbPrOutcome, ON CONFLICT(repository_full_name, pr_number) DO UPDATE), read by src/services/public-accuracy-trend.ts Fold-then-rename on colliding pr_number, same shape as pullRequests/gateOutcomes in the Drizzle half of this module.
orb_webhook_events repository_full_name nullable, no unique constraint on it (PK is delivery_id) src/orb/webhook.ts Plain rename (UPDATE ... WHERE repository_full_name = oldFullName), same shape as productUsageEvents/signalSnapshots.
override_audit project TEXT NOT NULL, id is a random non-project-derived string (ova_<timestamp36>_<random>, see newAuditId() in src/review/auto-apply.ts) src/review/auto-apply.ts (recordOverrideAudit) Plain rename — id needs no rewrite (unlike review_audit's id, it never embeds project).
tunables_overrides project TEXT PRIMARY KEY src/review/auto-apply.ts (writeLiveOverride/deleteLiveOverride) Fold-then-rename anchor shape, same as repositories/burdenForecasts.
tunables_overrides_shadow project TEXT PRIMARY KEY src/review/auto-apply.ts Same fold-then-rename anchor shape.
predicted_gate_calibration_ledger project TEXT NOT NULL; id = `calibration:${login}:${project}:${pullNumber}@${headSha}`, target_id = `${project}#${pullNumber}`the exact same id-embeds-project shape review_audit and contributor_gate_history already get fixed for src/review/predicted-gate-calibration-ledger.ts Rewrite project, id, and target_id via substring replace, same pattern already used in this module for review_audit/contributor_gate_history.
predicted_gate_calls project TEXT NOT NULL; id = `predicted:${login}:${project}:${timestamp}:${random}` — same shape again src/review/predicted-gate-calls.ts Rewrite project and id via substring replace, same pattern.

The last two are the sharpest instance of this repo's own dominant bug shape: review_audit and contributor_gate_history are structurally identical tables (project column, an id that embeds project as a substring) that already received the exact fix this issue asks for — predicted_gate_calibration_ledger and predicted_gate_calls are newer tables with the identical shape that never got it.

All seven have confirmed live writers (verified via grep across src/) — this is not the "orphaned, no live writer" case the module deliberately excludes for review_targets. A repo rename today silently leaves a repo's Orb PR-outcome ledger, Orb webhook-delivery log, self-improve tunable overrides (live + shadow), override-audit trail, and predicted-gate calibration history pinned to the stale old name.

Requirements

  • Extend renameRepositoryIdentity in src/db/repo-identity-rename.ts to cover all seven raw-SQL tables above, using env.DB.prepare(...) directly (matching how the module's existing review_audit/contributor_gate_history/submitter_stats blocks already access raw-SQL tables — these three are deliberately NOT added to the Drizzle schema per their own migration headers, and neither are the seven above).
  • Use each table's noted fold strategy exactly; for the two id-embeds-project tables, follow the identical substring-replace pattern the module already uses for review_audit/contributor_gate_history (rewrite id via replace(id, ?, ?), project directly, and target_id via replace(target_id, ?, ?) where present).
  • Preserve the function's existing invariants: idempotent, collision-safe (pre-existing oldFullName row wins any fold), no-op when oldFullName === newFullName.

Deliverables

  • orb_pr_outcomes fold-then-rename (on pr_number) added.
  • orb_webhook_events plain rename added.
  • override_audit plain rename added.
  • tunables_overrides fold-then-rename added.
  • tunables_overrides_shadow fold-then-rename added.
  • predicted_gate_calibration_ledger id/target_id/project rewrite added.
  • predicted_gate_calls id/project rewrite added.

Test Coverage Requirements

src/db/repo-identity-rename.ts is under src/**, Codecov patch-gated at 99%, branch-counted. Extend test/unit/repo-identity-rename.test.ts with one block per new table (following the file's existing pattern for the raw-SQL review_audit/contributor_gate_history/submitter_stats blocks specifically, since these seven share that access pattern):

  • Clean rename with no collision.
  • Fold behavior when a colliding row already exists under newFullName (for the fold-shaped tables) — pre-existing oldFullName data wins.
  • For predicted_gate_calibration_ledger/predicted_gate_calls: assert id and target_id (where present) are rewritten, not just project.
  • No-op / idempotent re-run.

Expected Outcome

A GitHub repository rename correctly carries a repo's Orb PR-outcome ledger, Orb webhook-delivery log, self-improve tunable overrides (live + shadow) and their audit trail, and predicted-gate calibration/call history forward to the new name.

Links & Resources

Metadata

Metadata

Assignees

No one assigned

    Labels

    gittensor:bugGittensor-scored bug fix — scores a 0.05x multiplier.help wantedExtra attention is needed

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions