Skip to content

fix(api): clamp postgres extrinsics pagination#4846

Open
JSONbored wants to merge 1 commit into
mainfrom
codex/fix-unbounded-offset-in-postgres-routes
Open

fix(api): clamp postgres extrinsics pagination#4846
JSONbored wants to merge 1 commit into
mainfrom
codex/fix-unbounded-offset-in-postgres-routes

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Motivation

  • Prevent Postgres/Hyerdrive resource exhaustion by ensuring the Postgres-backed DATA_API routes honor the same block-explorer pagination bounds D1 uses, so oversized limit/offset params cannot trigger deep OFFSET scans.

Description

  • Change the DATA_API /api/v1/extrinsics handler in workers/data-api.mjs to use the block-explorer pagination profile by replacing clampLimit(...) with clampBlockLimit(...), preserving the shared offset clamp.
  • Add a regression test in tests/data-api.test.mjs that requests oversized limit and offset and asserts the SQL-bound values contain the clamped BLOCK_PAGINATION.maxLimit and MAX_OFFSET (and not the raw huge values).
  • Files modified: workers/data-api.mjs, tests/data-api.test.mjs.

Testing

  • Ran the focused unit tests: npm test -- tests/data-api.test.mjs, and all tests in that file passed.
  • Ran formatting check: npm run format:check -- tests/data-api.test.mjs workers/data-api.mjs, and Prettier reported no style issues.
  • The added regression test validates that oversized limit/offset are clamped before the Postgres query is composed.

Codex Task

@superagent-security

superagent-security Bot commented Jul 11, 2026

Copy link
Copy Markdown

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

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 11, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
metagraphed-data-api 139e0ed Commit Preview URL

Branch Preview URL
Jul 11 2026, 06:43 AM

@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 97.71%. Comparing base (5a40099) to head (139e0ed).
⚠️ Report is 41 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4846   +/-   ##
=======================================
  Coverage   97.71%   97.71%           
=======================================
  Files         162      162           
  Lines       18587    18587           
  Branches     6939     6939           
=======================================
  Hits        18162    18162           
  Misses         59       59           
  Partials      366      366           
Files with missing lines Coverage Δ
workers/data-api.mjs 98.38% <100.00%> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gittensory-orb gittensory-orb Bot added the gittensor:bug Gittensor-scored bug fix or unsolicited PR — scores a 0.05x multiplier. label Jul 11, 2026
@gittensory-orb

gittensory-orb Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Warning

🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨

⏸️ Gittensory review result - manual review recommended

Review updated: 2026-07-11 17:10:23 UTC

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

⏸️ Suggested Action - Manual Review

  • No linked issue detected — If this PR is intended to solve an issue, link it explicitly in the PR body.
  • Maintainer requires a linked issue — Link the relevant issue (for example Closes #123) before opening the PR.

Review summary
One-line fix in workers/data-api.mjs's /api/v1/extrinsics handler that swaps clampLimit for clampBlockLimit, tightening the Postgres-backed route's max page size from 1000 to BLOCK_PAGINATION.maxLimit (100) and bringing it into parity with the D1 loadExtrinsics path in src/extrinsics.mjs, which already uses the same BLOCK_PAGINATION profile for this same logical route. The change is minimal and correctly scoped to the stated Postgres-resource-exhaustion motivation, backed by a new regression test asserting the clamped bound values reach the SQL params instead of the raw oversized limit/offset, and CI (including the test job) is green on this commit.

Nits — 4 non-blocking
  • clampBlockLimit isn't visible in the provided request-params.mjs excerpt (only clampLimit + BLOCK_PAGINATION are shown there) — confirm it's an existing exported helper in workers/data-api.mjs rather than a silently-added new one; CI's passing test job makes a missing symbol unlikely but the definition itself is unverifiable from the given context.
  • PR description doesn't link an eligible open issue (only a Codex task URL) — per repo convention this should be tied to a maintainer-authorized issue before merge.
  • If other Postgres-backed handlers in workers/data-api.mjs still call the generic clampLimit for block-explorer-style routes, audit them for the same D1/Postgres profile mismatch this PR just fixed for extrinsics.
  • Consider also asserting the response body's extrinsics length is bounded by the clamped limit in the new test, not just the SQL-bound values, for a slightly stronger regression guarantee.

Concerns raised — review before merging

  • No linked issue detected — If this PR is intended to solve an issue, link it explicitly in the PR body.
  • Maintainer requires a linked issue — Link the relevant issue (for example Closes #123) before opening the PR.
Signal Result Evidence
Code review ❌ 2 blockers 1 reviewer
Linked issue ⚠️ Missing No linked issue or no-issue rationale found.
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 (no linked issue context).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 45 registered-repo PR(s), 37 merged, 414 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 45 PR(s), 414 issue(s).
Gate result ❌ Blocking Repo-configured hard blocker found.
Review context
  • Author: JSONbored
  • Role context: owner (maintainer lane)
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: not available
  • Official Gittensor activity: 45 PR(s), 414 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Treat this as maintainer-lane context rather than normal contributor-lane activity.
  • Explain no-issue PR.
  • Link the issue being solved, or explicitly explain why this is a no-issue PR.
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.
[BETA] Chat with Gittensory

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

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

Full command reference: https://gittensory.aethereal.dev/docs/gittensory-commands

🟩 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

@gittensory-orb gittensory-orb Bot added the manual-review Gittensor contributor context label Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aardvark codex gittensor:bug Gittensor-scored bug fix or unsolicited PR — scores a 0.05x multiplier. manual-review Gittensor contributor context

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant