Skip to content

fix(orb): catch stream-read errors in readOrbIngestBody (#8330)#8432

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
philluiz2323:fix/orb-ingest-body-read-error-8330
Jul 24, 2026
Merged

fix(orb): catch stream-read errors in readOrbIngestBody (#8330)#8432
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
philluiz2323:fix/orb-ingest-body-read-error-8330

Conversation

@philluiz2323

Copy link
Copy Markdown
Contributor

Summary

  • readOrbRelayRegisterBody (src/orb/relay.ts) wraps its stream-read loop in try/catch specifically because reader.read() can reject on a dropped connection / network reset mid-read, and every caller already treats a null return identically to "reject this request" — a documented, deliberate fix for a real production 500 (GITTENSORY-J).
  • readOrbIngestBody (src/orb/ingest.ts) is the same read-loop pattern, reused as-is by both /v1/orb/ingest and /v1/ams/ingest, but had no try/catch: a dropped connection mid-upload threw an uncaught rejection out of the route handler instead of the clean 413/400 JSON response the route otherwise returns for an oversized or malformed body.
  • Wraps readOrbIngestBody's read loop in the identical try/catch → return null pattern, with no change to the byte-cap or declared-length-check behavior.
  • Adds a regression test mirroring orb-relay.test.ts's dropped-connection case at both levels: the function returns null directly, and the /v1/orb/ingest route returns its normal clean 413 payload_too_large response rather than a framework 500.

Closes #8330

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
  • npm run typecheck
  • npm run test:coverage locally; codecov/patch requires ≥99% coverage of the lines AND branches you changed (aim for 100% on your diff so CI variance does not fail near the threshold). Global coverage is a non-blocking trend with a loose 90% backstop, not the gate.
  • npm run test:workers
  • npm run build:mcp
  • npm run test:mcp-pack
  • npm run ui:openapi:check
  • 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:

  • This change touches only src/orb/ingest.ts (pure backend logic, no UI/MCP/workers/OpenAPI surface) plus its test file. Verified via npx vitest run test/integration/orb-ingest.test.ts test/integration/orb-relay.test.ts: 127/128 tests pass, including both new regression tests (function-level and route-level). The single failure (handleOrbIngest() > skips events with bad repo_hash / pr_hash / outcome) is an unrelated, pre-existing local-environment timeout — confirmed by reproducing it identically on a clean stash of this branch's base commit before any of this PR's changes existed; it exercises handleOrbIngest, a function this PR does not touch. Coverage on the changed lines (verified directly against coverage/lcov.info): every branch inside readOrbIngestBody, including the new try/catch, shows both arms hit (e.g. BRDA:45,6,0,7 / BRDA:45,6,1,9 for the loop's done check; the catch body's return null at line 55 shows 2 hits, one per new regression test).

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. (N/A — no auth/session/CORS changes; the affected routes' existing optional-bearer-token tests are untouched and still pass.)
  • API/OpenAPI/MCP behavior is updated and tested where needed. (N/A — no new/changed API surface, only an existing error path's robustness.)
  • UI changes use live API data or real empty/error/loading states, not production mock/demo fallbacks. (N/A — no UI changes.)
  • Visible UI changes include a UI Evidence section below with JPG/JPEG or PNG screenshots. (N/A — no visible UI changes.)
  • Public docs/changelogs are updated where needed; changelogs are only edited for release-prep PRs. (N/A.)

Notes

  • Byte-cap and declared-length-check behavior is unchanged — only the read loop's error handling was added, per the issue's explicit requirement.

A dropped connection or network reset mid-upload rejected reader.read()
uncaught, so /v1/orb/ingest and /v1/ams/ingest surfaced a bare framework
500 instead of the clean 413/400 JSON error every other rejected-body
case already returns. Wraps the read loop in the same try/catch pattern
readOrbRelayRegisterBody already uses for the identical failure mode,
returning null (every caller's existing "reject this request" contract)
instead of letting the rejection propagate. Adds regression tests
mirroring orb-relay.test.ts's dropped-connection case at both the
function and route level.
@philluiz2323
philluiz2323 requested a review from JSONbored as a code owner July 24, 2026 12:54
@superagent-security

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.61%. Comparing base (ca066b2) to head (cc36268).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8432      +/-   ##
==========================================
- Coverage   92.42%   89.61%   -2.81%     
==========================================
  Files         791       98     -693     
  Lines       79290    22773   -56517     
  Branches    23950     3896   -20054     
==========================================
- Hits        73283    20408   -52875     
+ Misses       4868     2187    -2681     
+ Partials     1139      178     -961     
Flag Coverage Δ
shard-1 35.82% <0.00%> (-17.50%) ⬇️
shard-2 100.00% <100.00%> (+47.53%) ⬆️
shard-3 37.31% <90.90%> (-18.84%) ⬇️

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

Files with missing lines Coverage Δ
src/orb/ingest.ts 100.00% <100.00%> (ø)

... and 693 files with indirect coverage changes

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

loopover-orb Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-24 13:12:37 UTC

2 files · 1 AI reviewer · no blockers · readiness 93/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This wraps readOrbIngestBody's read loop in the same try/catch → null pattern already used by readOrbRelayRegisterBody, closing a real gap where a dropped connection mid-upload would throw an uncaught rejection instead of the clean 413/400 the route otherwise returns. The fix is minimal, correctly scoped to the read loop (doesn't touch the byte-cap or declared-length logic), and is backed by regression tests at both the function level and the /v1/orb/ingest route level mirroring the existing orb-relay.ts pattern. The change is narrow, closes issue #8330, and CI is fully green.

Nits — 3 non-blocking
  • src/orb/ingest.ts: the catch block swallows all errors including the byte-cap cancellation path's own potential AbortError from reader.cancel(), though this is the same tradeoff already accepted in readOrbRelayRegisterBody so it's consistent, not new risk.
  • test/integration/orb-ingest.test.ts: the two new regression tests are near-duplicates (function-level and route-level) of the same dropped-connection scenario already established in orb-relay.test.ts — fine for coverage but worth noting as intentional mirroring, not new test design.
  • src/orb/ingest.ts: consider extracting the try/catch → null read-loop pattern shared with readOrbRelayRegisterBody into one helper if a third caller ever needs it, to avoid a third copy-paste drift point (not necessary now with just two).

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #8330
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: 1039 registered-repo PR(s), 613 merged, 126 issue(s).
Contributor context ✅ Confirmed Gittensor contributor philluiz2323; Gittensor profile; 1039 PR(s), 126 issue(s).
Improvement ✅ Minor risk: clean · value: minor
Linked issue satisfaction

Addressed
The diff wraps readOrbIngestBody's read loop in try/catch returning null on error, exactly mirroring readOrbRelayRegisterBody, and adds regression tests at both the function level and the /v1/orb/ingest route level asserting a clean 413 instead of an uncaught rejection.

Review context
  • Author: philluiz2323
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, JavaScript, MDX, TypeScript, CSS, Cuda, HTML, Kotlin
  • Official Gittensor activity: 1039 PR(s), 126 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Triage stale or unlinked PRs.
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.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

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

  • Re-run LoopOver review

@loopover-orb loopover-orb Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoopOver approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit af3340f into JSONbored:main Jul 24, 2026
12 checks passed
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

None yet

Development

Successfully merging this pull request may close these issues.

readOrbIngestBody can throw uncaught on a dropped connection, unlike its documented twin readOrbRelayRegisterBody

1 participant