Skip to content

fix(orb): return 503 instead of a bare 500 from the relay register/pull routes - #5017

Merged
JSONbored merged 1 commit into
mainfrom
claude/gittensory-pr-mislabel-debug-c24720
Jul 11, 2026
Merged

fix(orb): return 503 instead of a bare 500 from the relay register/pull routes#5017
JSONbored merged 1 commit into
mainfrom
claude/gittensory-pr-mislabel-debug-c24720

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Summary

  • Fixes fix(orb): drainOrbRelay returns HTTP 500 repeatedly (872 Sentry events, escalating) #4995: drainOrbRelay returned HTTP 500 repeatedly (872 Sentry events, escalating).
  • Root cause was not what Sentry Seer suggested. Seer proposed adding an in-flight guard and fixing a timeout/poll-interval mismatch — both already exist and are already correct (drainInFlight guard in src/server.ts, and the 30s poll interval is explicitly matched to drainOrbRelay's own 30s AbortSignal.timeout, per that code's own comment). The real gap was entirely server-side: /v1/orb/relay/register and /v1/orb/relay/pull both call DB-touching functions (validateOrbRelayEnrollment, registerValidatedOrbRelay, pullRelayPending) with no error handling of their own. An unhandled D1/Postgres error inside either one escaped as a bare framework 500 — exactly the class of gap #orb-broker-500 already closed for /v1/orb/token's own DB-touching call, just never applied to these two sibling routes.
  • Fix: .catch(...) on just the two DB-touching calls per handler (not a big try/catch wrapping the whole handler), so pre-existing logic/branches keep their original indentation and coverage — genuine DB failures now return a clean 503 { error: "broker_error" }.

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 a currently open issue this PR resolves (Closes #4995).

Validation

  • git diff --check
  • npm run actionlint
  • npm run typecheck
  • npm run test:coverage locally
  • npm run test:workers
  • npm run build:mcp
  • npm run test:mcp-pack
  • npm run ui:openapi:check (confirms these internal broker routes aren't part of the public OpenAPI surface — no drift)
  • npm run ui:lint
  • npm run ui:typecheck
  • npm run ui:build
  • 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:

  • test:coverage (full unsharded): not run end-to-end — ran scoped vitest --coverage for test/integration/orb-relay.test.ts and confirmed via lcov that every line/branch in this diff (both the register and pull handlers' new .catch() paths, including the error instanceof Error vs String(error) branch) is covered — including a second regression test per handler after the first pass showed one call site's error path was untested. The one remaining zero-hit branch in the surrounding function is confirmed pre-existing (same branch was already 0% covered before this diff, verified via git stash) and structurally unreachable at this call site given RegisterResult's real producers — not introduced by this change.
  • test:workers / build:mcp / test:mcp-pack / ui:lint / ui:typecheck / ui:build: not run — this change touches only src/api/routes.ts and its integration test; no Worker-pool, MCP, or UI-component surface changed.

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. (These are broker-auth routes — negative paths (401/403/413/503) are all covered, including the two new 503 regression tests.)
  • API/OpenAPI/MCP behavior is updated and tested where needed. (Checked — not part of the public OpenAPI surface.)
  • UI changes use live API data or real empty/error/loading states. (N/A.)
  • Visible UI changes include a UI Evidence section. (N/A.)
  • Public docs/changelogs are updated where needed. (N/A — internal engine behavior; changelog is not edited in a normal PR.)

Notes

Part of a batch of 13 bug fixes filed from a Sentry-issue triage this session (#4994#5006). This is #2 by impact.

…ll routes

/v1/orb/relay/register and /v1/orb/relay/pull both call DB-touching functions
(validateOrbRelayEnrollment, registerValidatedOrbRelay, pullRelayPending) with
no error handling of their own -- an unhandled D1/Postgres error escaped as a
bare framework 500, the same class of gap #orb-broker-500 already closed for
/v1/orb/token's own DB-touching call. drainOrbRelay's client-side in-flight
guard and matched poll/request timeout (src/server.ts) were already correct;
the gap was entirely server-side. `.catch(...)` on just the two DB-touching
calls per handler, rather than wrapping the whole handler in try/catch, keeps
the diff minimal and leaves existing logic/branches untouched.

Closes #4995
@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.36%. Comparing base (445c9fc) to head (be7a825).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5017   +/-   ##
=======================================
  Coverage   94.35%   94.36%           
=======================================
  Files         457      457           
  Lines       39216    39228   +12     
  Branches    14300    14306    +6     
=======================================
+ Hits        37004    37016   +12     
  Misses       1558     1558           
  Partials      654      654           
Flag Coverage Δ
shard-1 46.49% <0.00%> (-0.29%) ⬇️
shard-2 33.66% <0.00%> (+0.25%) ⬆️
shard-3 31.38% <100.00%> (+0.34%) ⬆️
shard-4 32.60% <0.00%> (-0.57%) ⬇️
shard-5 34.48% <0.00%> (+0.99%) ⬆️
shard-6 45.34% <0.00%> (+0.18%) ⬆️

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

Files with missing lines Coverage Δ
src/api/routes.ts 94.28% <100.00%> (+0.03%) ⬆️
🚀 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

Important

🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪

🔍 Gittensory is reviewing…

AI analysis is in progress. This comment will update when the review is complete.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed · 🟪 Reviewing

@JSONbored JSONbored self-assigned this Jul 11, 2026
@JSONbored
JSONbored merged commit 19c8acb into main Jul 11, 2026
18 checks passed
@JSONbored
JSONbored deleted the claude/gittensory-pr-mislabel-debug-c24720 branch July 11, 2026 09:08
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.

Development

Successfully merging this pull request may close these issues.

fix(orb): drainOrbRelay returns HTTP 500 repeatedly (872 Sentry events, escalating)

1 participant