You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
renameRepositoryIdentity omits 7 raw-SQL identity tables, including two structurally identical to already-fixed siblings review_audit/contributor_gate_history #8380
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).
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.
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
src/db/repo-identity-rename.ts — the function to extend; see its existing review_audit/contributor_gate_history/submitter_stats blocks for the exact raw-SQL pattern to mirror.
src/orb/outcomes.ts, src/orb/webhook.ts, src/review/auto-apply.ts, src/review/predicted-gate-calibration-ledger.ts, src/review/predicted-gate-calls.ts — live writers to verify the exact write shape against.
test/unit/repo-identity-rename.test.ts — existing test file to extend.
Context
src/db/repo-identity-rename.ts'srenameRepositoryIdentity(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 oldowner/reponame. Three raw-SQL-only tables (deliberately not in Drizzle'ssrc/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 aprojectcolumn that is the repo full name (verified live at each table's writer), and the module rewritesprojectplus anyid/target_idvalue 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:orb_pr_outcomesPRIMARY KEY (repository_full_name, pr_number)src/orb/outcomes.ts(recordOrbPrOutcome,ON CONFLICT(repository_full_name, pr_number) DO UPDATE), read bysrc/services/public-accuracy-trend.tspr_number, same shape aspullRequests/gateOutcomesin the Drizzle half of this module.orb_webhook_eventsrepository_full_namenullable, no unique constraint on it (PK isdelivery_id)src/orb/webhook.tsUPDATE ... WHERE repository_full_name = oldFullName), same shape asproductUsageEvents/signalSnapshots.override_auditproject TEXT NOT NULL,idis a random non-project-derived string (ova_<timestamp36>_<random>, seenewAuditId()insrc/review/auto-apply.ts)src/review/auto-apply.ts(recordOverrideAudit)idneeds no rewrite (unlikereview_audit'sid, it never embedsproject).tunables_overridesproject TEXT PRIMARY KEYsrc/review/auto-apply.ts(writeLiveOverride/deleteLiveOverride)repositories/burdenForecasts.tunables_overrides_shadowproject TEXT PRIMARY KEYsrc/review/auto-apply.tspredicted_gate_calibration_ledgerproject TEXT NOT NULL;id=`calibration:${login}:${project}:${pullNumber}@${headSha}`,target_id=`${project}#${pullNumber}`— the exact same id-embeds-project shapereview_auditandcontributor_gate_historyalready get fixed forsrc/review/predicted-gate-calibration-ledger.tsproject,id, andtarget_idvia substring replace, same pattern already used in this module forreview_audit/contributor_gate_history.predicted_gate_callsproject TEXT NOT NULL;id=`predicted:${login}:${project}:${timestamp}:${random}`— same shape againsrc/review/predicted-gate-calls.tsprojectandidvia substring replace, same pattern.The last two are the sharpest instance of this repo's own dominant bug shape:
review_auditandcontributor_gate_historyare structurally identical tables (projectcolumn, anidthat embedsprojectas a substring) that already received the exact fix this issue asks for —predicted_gate_calibration_ledgerandpredicted_gate_callsare newer tables with the identical shape that never got it.All seven have confirmed live writers (verified via
grepacrosssrc/) — this is not the "orphaned, no live writer" case the module deliberately excludes forreview_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
renameRepositoryIdentityinsrc/db/repo-identity-rename.tsto cover all seven raw-SQL tables above, usingenv.DB.prepare(...)directly (matching how the module's existingreview_audit/contributor_gate_history/submitter_statsblocks 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).id-embeds-projecttables, follow the identical substring-replace pattern the module already uses forreview_audit/contributor_gate_history(rewriteidviareplace(id, ?, ?),projectdirectly, andtarget_idviareplace(target_id, ?, ?)where present).oldFullNamerow wins any fold), no-op whenoldFullName === newFullName.Deliverables
orb_pr_outcomesfold-then-rename (onpr_number) added.orb_webhook_eventsplain rename added.override_auditplain rename added.tunables_overridesfold-then-rename added.tunables_overrides_shadowfold-then-rename added.predicted_gate_calibration_ledgerid/target_id/project rewrite added.predicted_gate_callsid/project rewrite added.Test Coverage Requirements
src/db/repo-identity-rename.tsis undersrc/**, Codecovpatch-gated at 99%, branch-counted. Extendtest/unit/repo-identity-rename.test.tswith one block per new table (following the file's existing pattern for the raw-SQLreview_audit/contributor_gate_history/submitter_statsblocks specifically, since these seven share that access pattern):newFullName(for the fold-shaped tables) — pre-existingoldFullNamedata wins.predicted_gate_calibration_ledger/predicted_gate_calls: assertidandtarget_id(where present) are rewritten, not justproject.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
src/db/repo-identity-rename.ts— the function to extend; see its existingreview_audit/contributor_gate_history/submitter_statsblocks for the exact raw-SQL pattern to mirror.migrations/0067_orb_pr_outcomes.sql,migrations/0064_orb_webhook_events.sql,migrations/0047_self_improve_tunables.sql(override_audit,tunables_overrides,tunables_overrides_shadow),migrations/0138_predicted_gate_calibration_ledger.sql,migrations/0137_predicted_gate_calls.sql.src/orb/outcomes.ts,src/orb/webhook.ts,src/review/auto-apply.ts,src/review/predicted-gate-calibration-ledger.ts,src/review/predicted-gate-calls.ts— live writers to verify the exact write shape against.test/unit/repo-identity-rename.test.ts— existing test file to extend.src/db/schema.ts) identity tables this module also omits.