fix(orb): index orb_relay_pending.created_at to stop full table scans#7510
Merged
Conversation
…#7430) pruneRelayPending's SELECT and DELETE filter only by created_at, but both existing indexes on orb_relay_pending lead with installation_id -- neither could serve that predicate, so both fell back to a full table scan, run fleet-wide on every 30s orb-relay-drain pull, occasionally exceeding the pull request's own 30s timeout budget (Sentry: orb_relay_drain TimeoutError, recurring since 2026-07-15). Adds the missing created_at index (migration 0167, mirrored in the Drizzle schema) so both queries become index range scans.
Contributor
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7510 +/- ##
=======================================
Coverage 91.35% 91.35%
=======================================
Files 716 716
Lines 72990 72990
Branches 21628 21627 -1
=======================================
Hits 66678 66678
Misses 5272 5272
Partials 1040 1040
Flags with carried forward coverage won't be shown. Click here to find out more.
|
This was referenced Jul 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
orb-relay-drain's periodic pull-mode drain has been timing out since 2026-07-15 and is still recurring (Sentryorb_relay_drain/TimeoutError, 13+ occurrences, most recent within hours). Its handler unconditionally runspruneRelayPendingfirst on every 30s pull. That function issues a SELECT and a DELETE againstorb_relay_pendingfiltered only bycreated_at— but both existing indexes on that table lead withinstallation_id, so neither query could use an index. Both fell back to a full table scan, fleet-wide, every 30 seconds, occasionally exceeding the pull request's own 30s timeout budget.This adds the missing
created_atindex (migration0167, mirrored insrc/db/schema.ts) so both queries become index range scans instead.Scope
type(scope): short summaryConventional Commit format, for examplefix(api): restore profile access checks.CONTRIBUTING.mdand does not reintroduce GitHub Pages, VitePress,site/, orCNAME.Closes #123) — a linked open issue is required for every contributor PR.Closes #7430
Validation
git diff --checknpm run actionlintnpm run typechecknpm run test:coveragelocally — new regression test (test/unit/orb-relay-pending-created-at-index.test.ts) assertsEXPLAIN QUERY PLANuses the new index (SEARCH, notSCAN) for both queriespruneRelayPendingruns;npm run db:migrations:checkandnpm run db:schema-drift:checkboth clean (0167 confirmed as the next free migration number)npm run test:workersnpm run build:mcpnpm run test:mcp-packnpm run ui:openapi:checknpm run ui:lintnpm run ui:typechecknpm run ui:buildnpm audit --audit-level=moderateIf any required check was skipped, explain why:
apps/loopover-ui'sui:test(vitest/jsdom) fails locally withwindow.localStorageundefined, on this sandbox's Node v26.5.0 (the repo pins Node 22 via.nvmrc, unavailable vianvmin this environment). Verified this reproduces identically on a clean, unmodifiedorigin/maincheckout with a freshnpm ci— it is a pre-existing local Node-version artifact unrelated to this change (which touches noapps/loopover-uifiles), not a regression. Confirmed real GitHub Actions CI (validate-testsshards 1–6 + merge) is green on the exactmaincommit this branches from.Safety
UI Evidencesection below with screenshots. (N/A — no visible UI change; this is a DB index + migration only.)Notes
orb_relay_drain) triage:pruneRelayPending's SELECT was added by a same-day commit on 2026-07-15, doubling the pre-existing unindexed DELETE's scan work — matching the exact day this Sentry issue started firing.