Skip to content

fix(orb): prefer the newest relay enrollment when forwarding events - #1785

Merged
JSONbored merged 3 commits into
JSONbored:mainfrom
galuis116:fix/orb-relay-enrollment-ordering
Jun 30, 2026
Merged

fix(orb): prefer the newest relay enrollment when forwarding events#1785
JSONbored merged 3 commits into
JSONbored:mainfrom
galuis116:fix/orb-relay-enrollment-ordering

Conversation

@galuis116

Copy link
Copy Markdown
Contributor

Summary

Fixes #1783. forwardOrbEvent loaded the brokered self-host relay target with a .first() query on orb_enrollments that had no ORDER BY. Because issueOrbEnrollment inserts a new enrolled row on every enrollment without revoking prior rows for the same installation_id, re-enrollment left multiple active rows. The lookup could return a stale enrollment (no relay URL → skipped, or an old push URL → mis-delivered HMAC-signed payload).

The enrollment lookup now orders by registered-relay presence, then relay_registered_at DESC, then enrolled_at DESC, so the current self-host container wins after re-enrollment.

Scope

  • The PR title follows type(scope): short summary Conventional Commit format, for example fix(api): restore profile access checks.
  • This PR is focused and does not mix unrelated backend, UI, MCP, docs, dependency, and deploy changes.
  • This follows CONTRIBUTING.md and does not reintroduce GitHub Pages, VitePress, site/, or CNAME.
  • I linked an issue, or this is small enough that the summary explains why an issue is not needed.

Validation

  • git diff --check
  • npm run actionlint (no workflow changes)
  • npm run typecheck
  • npm run test:coverage locally for changed integration tests; full suite spot-checked via npx vitest run test/integration/orb-relay.test.ts (63/63 pass).
  • npm run test:workers (no worker changes)
  • npm run build:mcp (no MCP changes)
  • npm run test:mcp-pack (no MCP changes)
  • npm run ui:openapi:check (no API schema changes)
  • npm run ui:lint (no UI changes)
  • npm run ui:typecheck (no UI changes)
  • npm run ui:build (no UI changes)
  • npm audit --audit-level=moderate
  • New or changed behavior has unit/integration tests for new branches, fallback paths, and sanitizer boundaries

If any required check was skipped, explain why:

Skipped UI/MCP/workers/actionlint — orb relay-only change. Full test:ci on Windows hits environment-only failures (spawn claude/codex ENOENT); Linux CI is authoritative.

Safety

  • No secrets, wallet details, hotkeys, coldkeys, user PATs, private keys, raw trust scores, private rankings, or private maintainer evidence are exposed.
  • Public GitHub text stays sanitized, low-noise, and does not imply compensation guarantees or optimization tactics.
  • Auth, cookie, CORS, GitHub App, Cloudflare, or session changes include negative-path tests.
  • API/OpenAPI/MCP behavior is updated and tested where needed.
  • UI changes use live API data or real empty/error/loading states, not production mock/demo fallbacks.
  • Visible UI changes include a UI Evidence section below with JPG/JPEG or PNG screenshots arranged as organized, captioned, clickable thumbnails. SVG screenshots are not used as review evidence. Review-only screenshots or recordings are not committed to the repository.
  • Public docs/changelogs are updated where needed; changelogs are only edited for release-prep PRs.

UI Evidence

N/A — orb relay backend only.

Notes

Regression test: FORWARDS via the newest enrollment when multiple enrolled rows exist for one installation (regression for #1783) in test/integration/orb-relay.test.ts.

@galuis116
galuis116 requested a review from JSONbored as a code owner June 29, 2026 22:58
@dosubot dosubot Bot added the size:XS label Jun 29, 2026
@loopover-orb

loopover-orb Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Tip

🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩

✅ Gittensory review result - approve/merge recommended

Review updated: 2026-06-30 06:40:15 UTC

2 files · 1 AI reviewer · no blockers · readiness 73/100 · CI green · unknown

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
The change fixes the stale relay lookup by making `forwardOrbEvent` choose a deterministic active enrollment instead of relying on `.first()` without ordering. The ordering matches the described production failure: registered relays win over unregistered rows, then the most recent registration/enrollment wins, with `rowid` as a final insertion-order tie-breaker. The added integration tests cover the stale-unregistered row and equal-registration timestamp regression paths, and the visible diff is safe to proceed.

Nits — 5 non-blocking
  • nit: `src/orb/relay.ts:299` relies on implicit `rowid`; if `orb_enrollments` is ever rebuilt as `WITHOUT ROWID`, this query will break, so document that schema dependency near the table definition or use an explicit monotonic column in a follow-up.
  • nit: `test/integration/orb-relay.test.ts` forces equal `relay_registered_at` values but does not force equal `enrolled_at`, so the test name overstates the final `rowid` tie-break coverage unless both timestamps are pinned.
  • In `test/integration/orb-relay.test.ts`, update the second regression test to set both `relay_registered_at` and `enrolled_at` to the same value so it proves the `rowid DESC` branch, not just the `enrolled_at DESC` fallback.
  • In `src/orb/relay.ts`, consider extracting the enrollment-selection SQL into a small named constant so retry and forward-path reviews have one obvious place to audit the precedence rules.
  • Readiness score is below the configured threshold — Use the readiness panel as advisory maintainer context; the score does not block this PR.
Signal Result Evidence
Code review ✅ No blockers 1 reviewer
Linked issue ✅ Linked #1783
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 (size label size:S; 1 linked issue).
Validation posture ❌ 5/25 Preflight is holding this PR; address the blocker before review.
Contributor workload ✅ 10/10 Author activity: 1709 registered-repo PR(s), 1133 merged, 156 issue(s).
Contributor context ✅ Confirmed Gittensor contributor galuis116; Gittensor profile; 1709 PR(s), 156 issue(s).
Gate result ✅ Passing No configured blocker found.
Review context
  • Author: galuis116
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository registration is not available in the local Gittensory cache.
  • Public profile languages: not available
  • Official Gittensor activity: 1709 PR(s), 156 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Fix the blocker.
  • Triage stale or unlinked PRs.
  • Refresh registry data or choose a registered active repo.
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

@loopover-orb loopover-orb Bot added gittensor gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. labels Jun 29, 2026
…SONbored#1783)

enroll_id is a random opaque token and CURRENT_TIMESTAMP ties at second resolution, so the prior created_at/enroll_id tie-breakers were non-deterministic when multiple enrolled rows shared a relay_registered_at. Order by the implicit rowid (monotonic insertion order) so the most-recently-inserted enrollment wins deterministically.
@galuis116
galuis116 force-pushed the fix/orb-relay-enrollment-ordering branch from 1ad8030 to 92d9f7b Compare June 29, 2026 23:28
@dosubot dosubot Bot added size:S and removed size:XS labels Jun 29, 2026
@dosubot dosubot Bot added the lgtm label Jun 30, 2026
@JSONbored
JSONbored merged commit 42534b2 into JSONbored:main Jun 30, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in gittensory - v1 roadmap Jun 30, 2026
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

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: Orb relay forward picks an arbitrary enrollment when multiple enrolled rows exist

2 participants