Skip to content

fix(selfhost): widen GitHub-native id columns to bigint on Postgres - #5060

Merged
JSONbored merged 2 commits into
mainfrom
fix/selfhost-github-id-bigint-overflow
Jul 11, 2026
Merged

fix(selfhost): widen GitHub-native id columns to bigint on Postgres#5060
JSONbored merged 2 commits into
mainfrom
fix/selfhost-github-id-bigint-overflow

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Summary

  • Every migrations/*.sql column storing a raw GitHub-native numeric id (installation, account/user, check-run, comment) is declared bare INTEGER -- correct on SQLite/D1 (a type-affinity hint, already stores any 64-bit value), but a real, enforced 4-byte column on the self-host Postgres backend.
  • GitHub's own ids are one global counter shared across all of GitHub (unlike issue/PR numbers, which are per-repo). Comment ids are already past 2^31 -- confirmed live on edge-nl-01 via value "4945217685" is out of range for type integer on a github_agent_command_answers insert from a real @gittensory chat dispatch.
  • widenGithubIdColumnsToBigint (src/selfhost/pg-adapter.ts) mirrors the existing tuneGithubRateLimitObservationsAutovacuum pattern exactly: a Postgres-only, idempotent ALTER COLUMN ... TYPE bigint batch across every affected table, run unconditionally after migrations on every boot. Never touches the original migration files (correct as written for SQLite/D1) -- purely additive.
  • All 18 statements were dry-run validated against the live production schema (BEGIN; ...; ROLLBACK;) before being written into code. One originally-planned table, orb_installations, turned out to have been dropped by a later migration (fix(ci): isolate GitHub write token to release job #60, retiring that pipeline) -- caught this way rather than shipping a statement that would have silently sunk the whole batch (Postgres runs a multi-statement simple-query string as one implicit transaction, so a single unknown-relation error would have rolled back every other ALTER too).

Closes #5059

Test plan

  • npm run typecheck -- clean
  • New unit tests (test/unit/selfhost-pg-adapter-github-id-widening.test.ts) mirroring the sibling autovacuum-tuning test file's exact shape -- mocked D1Database.exec(), no real Postgres needed
  • npm run test:coverage (full, unsharded) -- 719 files / 14210 tests passed, 0 failures
  • npm run test:ci (full gate) -- green
  • npm audit --audit-level=moderate -- 0 vulnerabilities
  • All 18 ALTER statements dry-run validated against the live edge-nl-01 Postgres schema before merge
  • src/selfhost/pg-adapter.ts and src/server.ts are both in codecov.yml's ignore list (Postgres runtime adapter / self-host process entry) -- patch-coverage gate does not block on this PR

…ranch

#5036's codecov/patch flagged one partial branch in processors.ts:
matchedCommand === "ask" || matchedCommand === "chat" ? command.unrecognizedText
: undefined. The 3 existing #4596 integration tests only ever reroute to
"blockers", so the true side (rerouting to ask/chat specifically) was never
exercised -- meaning the one behavior that actually matters here (does the
contributor's original free text survive the reroute into the command's own
question field, instead of silently dropping it) was untested.
Every migrations/*.sql column storing a raw GitHub-native numeric id
(installation, account/user, check-run, comment) is declared bare
INTEGER -- fine on SQLite/D1 (a type-affinity hint that already stores
any 64-bit value), but a real 4-byte column on the self-host Postgres
backend. GitHub's comment ids are already past 2^31, confirmed live on
edge-nl-01 via a "value out of range for type integer" insert failure
on github_agent_command_answers.

widenGithubIdColumnsToBigint mirrors the existing
tuneGithubRateLimitObservationsAutovacuum pattern: a Postgres-only,
idempotent ALTER batch run unconditionally after migrations on every
boot, never touching the original (SQLite/D1-correct) migration files.

Closes #5059
@superagent-security

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.13%. Comparing base (dc81d72) to head (2d84295).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5060   +/-   ##
=======================================
  Coverage   94.13%   94.13%           
=======================================
  Files         465      465           
  Lines       39542    39542           
  Branches    14431    14431           
=======================================
+ Hits        37222    37223    +1     
  Misses       1664     1664           
+ Partials      656      655    -1     
Flag Coverage Δ
shard-1 46.49% <ø> (-0.02%) ⬇️
shard-2 33.45% <ø> (-0.05%) ⬇️
shard-3 31.59% <ø> (+0.25%) ⬆️
shard-4 32.67% <ø> (-0.01%) ⬇️
shard-5 33.20% <ø> (-0.24%) ⬇️
shard-6 45.15% <ø> (+0.19%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

loopover-orb Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Warning

🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨

⏸️ Gittensory review result - manual review recommended

Review updated: 2026-07-11 11:52:09 UTC

4 files · no blockers · readiness 100/100 · CI green · clean

⏸️ Suggested Action - Manual Review

  • AI review already in progress for this PR head: Another Gittensory pass is already running the AI review for this exact PR head. This pass is skipping to avoid a duplicate LLM call.

Review summary
AI review is already running for this PR head in another Gittensory pass. Gittensory is holding this PR for manual review until that pass completes.

Nits — 2 non-blocking
  • PR author also opened the linked issue — Link an issue that was opened by a different contributor, or provide a rationale for why this self-authored issue represents genuine discovery work.
  • AI review already in progress for this PR head — The gate is held for a human reviewer rather than passed automatically; it re-evaluates once the in-flight review completes or on the next update.
Signal Result Evidence
Code review ✅ No blockers No AI review summary
Linked issue ✅ Linked #5059
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: 47 registered-repo PR(s), 39 merged, 423 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 47 PR(s), 423 issue(s).
Gate result ⚠️ Not blocking Advisory; not blocking this PR.
Improvement ✅ Minor risk: clean · value: minor — Code changes are accompanied by test evidence.
Review context
  • Author: JSONbored
  • Role context: owner (maintainer lane)
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, TypeScript, Ruby, Go, JavaScript, MDX, Shell, Solidity
  • Official Gittensor activity: 47 PR(s), 423 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Treat this as maintainer-lane context rather than normal contributor-lane activity.
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.

🟩 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 Gittensory, a quiet PR intelligence layer for OSS maintainers.

  • Re-run Gittensory review

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. manual-review Gittensor contributor context

Development

Successfully merging this pull request may close these issues.

Self-host Postgres: GitHub-native id columns declared INTEGER silently overflow (comment ids already do)

1 participant