Skip to content

fix(db): add the orb_reuse_counters conflict key to the self-host Postgres dialect translator - #8930

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
kai392:fix/critical-issue-pg-dialect-orb-reuse
Jul 26, 2026
Merged

fix(db): add the orb_reuse_counters conflict key to the self-host Postgres dialect translator#8930
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
kai392:fix/critical-issue-pg-dialect-orb-reuse

Conversation

@kai392

@kai392 kai392 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Summary

REPLACE_CONFLICT_KEYS in src/selfhost/pg-dialect.ts requires an entry for every table used with
INSERT OR REPLACE, or translateInsertOr throws pg_dialect: INSERT OR REPLACE into '<table>' has no known conflict key. Migration 0177_orb_reuse_counters.sql added orb_reuse_counters with a real
INSERT OR REPLACE writer in src/orb/ingest.ts, but the matching map entry was never added — so a
self-hosted Postgres instance's hourly ORB export threw on its first orb_reuse_counters write.

Adds orb_reuse_counters: ["instance_id", "day"], matching the table's PRIMARY KEY (instance_id, day).

Test plan

  • New regression test: translateInsertOr on the verbatim orb/ingest.ts statement succeeds and produces ON CONFLICT (instance_id, day) DO UPDATE SET with key columns excluded from the SET list
  • Non-vacuity verified: removing the map entry makes translateInsertOr throw "no known conflict key" and the test fails
  • npx vitest run test/unit/selfhost-pg-dialect.test.ts — 24/24 pass; tsc --noEmit clean

Closes #8893

@kai392
kai392 requested a review from JSONbored as a code owner July 26, 2026 13:42
@superagent-security

Copy link
Copy Markdown
Contributor

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

…tgres dialect translator

REPLACE_CONFLICT_KEYS requires an entry for every table used with INSERT OR REPLACE, or
translateInsertOr throws "no known conflict key". Migration 0177 added orb_reuse_counters with a real
INSERT OR REPLACE writer in src/orb/ingest.ts, but the map entry was missing, so a self-hosted
Postgres instance's hourly ORB export threw on its first orb_reuse_counters write. Add
`orb_reuse_counters: ["instance_id", "day"]`, matching the table's PRIMARY KEY.

Closes JSONbored#8893

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.57%. Comparing base (8a3d2c9) to head (72a373b).
⚠️ Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8930      +/-   ##
==========================================
- Coverage   93.84%   90.57%   -3.28%     
==========================================
  Files         803       97     -706     
  Lines       80084    22531   -57553     
  Branches    24277     3890   -20387     
==========================================
- Hits        75157    20408   -54749     
+ Misses       3562     1945    -1617     
+ Partials     1365      178    -1187     
Flag Coverage Δ
backend 100.00% <ø> (+4.86%) ⬆️

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

Files with missing lines Coverage Δ
src/selfhost/pg-dialect.ts 100.00% <ø> (ø)

... and 706 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 26, 2026
@loopover-orb

loopover-orb Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-26 13:55:31 UTC

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

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This is a small, correctly-scoped fix: it adds the missing `orb_reuse_counters: ["instance_id", "day"]` entry to `REPLACE_CONFLICT_KEYS` in `src/selfhost/pg-dialect.ts`, matching the table's actual `PRIMARY KEY (instance_id, day)` from migration 0177, and follows the exact pattern already used for `ams_signals`/`orb_signals`. The new regression test uses the verbatim `INSERT OR REPLACE` statement from `src/orb/ingest.ts` and asserts both that the correct conflict target is generated and that key columns are excluded from the SET list while non-key columns are included — this is a real, non-fabricated test since the throw path was genuinely reachable before this change (confirmed by the described non-vacuity check of removing the entry). The change closes #8893 and is narrowly targeted with no scope creep.

Nits — 2 non-blocking
  • The PR doesn't verify the column list order in the test statement matches `src/orb/ingest.ts` exactly beyond what's shown — worth double-checking `hits, misses, received_at` are the full non-key column set and nothing was added/renamed there since.
  • Consider adding a real-Postgres integration test entry (in `test/integration/selfhost-pg.test.ts`, alongside the `system_flags` and other upsert checks) for `orb_reuse_counters` to catch any constraint-name mismatch that the unit-level `translateInsertOr` test can't verify against an actual Postgres engine.

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 #8893
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: 133 registered-repo PR(s), 66 merged, 6 issue(s).
Contributor context ✅ Confirmed Gittensor contributor kai392; Gittensor profile; 133 PR(s), 6 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
The PR adds the required orb_reuse_counters: ["instance_id", "day"] entry to REPLACE_CONFLICT_KEYS and includes a regression test in selfhost-pg-dialect.test.ts that translates the verbatim orb/ingest.ts statement, asserting it succeeds and produces the correct ON CONFLICT clause with key columns excluded from SET.

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: Python, Cuda, JavaScript, Kotlin, Perl, TypeScript, Vue
  • Official Gittensor activity: 133 PR(s), 6 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 4aaa4ef into JSONbored:main Jul 26, 2026
8 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

Development

Successfully merging this pull request may close these issues.

fix(db): self-host Postgres dialect translator has no conflict-key entry for orb_reuse_counters

2 participants