fix(orb): order enrollment lookup so relay forwarding targets the current container - #1789
Conversation
…rent container forwardOrbEvent loaded the brokered self-host relay target with a .first() query on orb_enrollments that has no ORDER BY. issueOrbEnrollment inserts a new 'enrolled' row on every enrollment without revoking the prior rows for the same installation_id, so D1/SQLite could return an arbitrary enrolled row: after a maintainer re-enrolls and registers a new push relay URL, forwardOrbEvent might read an older row (stale relay URL, or none registered) and skip or POST to the wrong container. Order the lookup by relay_registered_at DESC, then enrolled_at DESC, so the most recently registered enrollment wins and re-enrollment always targets the current self-host container. Adds an integration test: double-enroll one installation, register a relay on the second secret only, and assert forwardOrbEvent forwards to the new URL instead of skipping on the stale row.
|
Warning 🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨 ⏸️ Gittensory review result - manual review recommendedReview updated: 2026-06-30 09:05:32 UTC
⏸️ Suggested Action - Manual Review Review summary Nits — 3 non-blocking
Review context
Contributor next steps
Signal definitions
🟩 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.
|
JSONbored
left a comment
There was a problem hiding this comment.
merge conflicts, closing.
This branch has conflicts that must be resolved
Use the [web editor](https://github.com/JSONbored/gittensory/pull/1789/conflicts) or the command line to resolve conflicts before continuing.
src/orb/relay.ts
test/integration/orb-relay.test.ts
Closes #1783.
The bug
forwardOrbEvent(src/orb/relay.ts) loads the brokered self-host relay target with a.first()query onorb_enrollmentsthat has no ORDER BY.issueOrbEnrollmentinserts a newenrolledrow on every enrollment without revoking the prior rows for the sameinstallation_id, so D1/SQLite can return an arbitrary enrolled row. After a maintainer re-enrolls and registers a new push relay URL,forwardOrbEventmay read an older row (stale relay URL, or none registered) andskipthe event or POST the HMAC-signed payload to the wrong container.The fix
Order the lookup by
relay_registered_at DESC, enrolled_at DESC— the order the issue specifies — so the most recently registered enrollment wins and re-enrollment always targets the current self-host container. (A re-registered relay setsrelay_registered_at = CURRENT_TIMESTAMP;enrolled_atbreaks ties.)Tests
Integration test per the issue's Validation spec: double-enroll one installation (row A stays enrolled with no relay), register a relay on the second secret only, then assert
forwardOrbEventforwards to the new URL instead of skipping on the stale row. All 63 orb-relay tests green; the changed query line is covered; OpenAPI unchanged.