Skip to content

fix(data-api): wrap Postgres counterparty drilldowns#4959

Merged
JSONbored merged 2 commits into
mainfrom
codex/fix-postgres-counterparty-drilldown-response
Jul 12, 2026
Merged

fix(data-api): wrap Postgres counterparty drilldowns#4959
JSONbored merged 2 commits into
mainfrom
codex/fix-postgres-counterparty-drilldown-response

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Motivation

  • The Postgres branch for the account counterparty drilldown returned a top-level relationship object, while the public handler expects the D1 loader's envelope with a nested relationship property, causing a TypeError and a 500 for public unauthenticated requests when Postgres is enabled.

Description

  • Normalize the Postgres counterparty drilldown response in workers/data-api.mjs to the D1-compatible envelope including counterparties and the nested relationship object so data.relationship.last_seen_at is safe to dereference.
  • Preserve the existing behaviour for the non-drilldown (leaderboard) branch that returns buildCounterparties unchanged.
  • Update tests/data-api.test.mjs to assert the wrapped counterparty drilldown envelope shape and expected fields.
  • Add a regression test in tests/request-handlers-entities.test.mjs to verify the public handler accepts a Postgres-sourced relationship envelope and does not fall back to D1.

Testing

  • Ran the focused unit tests with npx vitest run tests/data-api.test.mjs tests/request-handlers-entities.test.mjs --testNamePattern "counterparties|handleAccountCounterparties", which completed successfully with the relevant tests passing.
  • Ran npm run format:check (prettier --check) which reported no style issues.
  • Verified git diff --check reported no whitespace errors.

Codex Task

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 12, 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 Updated (UTC)
✅ Deployment successful!
View logs
metagraphed-data-api bed0d1c Jul 12 2026, 03:30 PM

@superagent-security

Copy link
Copy Markdown

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

@codecov

codecov Bot commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.94%. Comparing base (98dc924) to head (bed0d1c).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4959   +/-   ##
=======================================
  Coverage   97.94%   97.94%           
=======================================
  Files         163      163           
  Lines       19431    19433    +2     
  Branches     7381     7382    +1     
=======================================
+ Hits        19031    19033    +2     
  Misses         53       53           
  Partials      347      347           
Files with missing lines Coverage Δ
workers/data-api.mjs 99.79% <100.00%> (+<0.01%) ⬆️
🚀 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 12, 2026
@gittensory-orb

gittensory-orb Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Caution

🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥

🛑 Gittensory review result - fixes required

Review updated: 2026-07-12 15:03:15 UTC

3 files · 2 AI reviewers · 3 blockers · readiness 93/100 · CI failing · 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.
  • AI reviewers agree on a likely critical defect: Pull request fix(data-api): wrap Postgres counterparty drilldowns #4959 links a Codex task but no eligible open issue in this repository, so it violates the repo's required issue-scope gate for contributor PRs. — Resolve the flagged defect, or override if the AI reviewers are mistaken, then re-run the gate.

Review summary
The PR fixes a real bug: the Postgres counterparty drilldown branch previously returned a bare relationship object while the D1 loader (loadCounterpartyRelationship, shown in src/counterparties.mjs) returns a wrapped envelope with nested `relationship`, causing the public handler's `data.relationship.last_seen_at` dereference to throw for Postgres-backed requests. The fix mirrors the exact envelope shape already produced by `loadCounterpartyRelationship` in src/counterparties.mjs (same counterparties-array construction from `relationship.transfer_count === 0`), so the two code paths are now consistent. Tests were updated/added to cover both the direct data-api response shape and the handler's acceptance of a Postgres-sourced envelope without falling back to D1.

Blockers

Nits — 5 non-blocking
  • The counterparties-array-from-relationship construction in workers/data-api.mjs is now duplicated from the identical logic in src/counterparties.mjs's loadCounterpartyRelationship — consider extracting a shared helper to avoid the two copies drifting.
  • codecov/patch is below target (66.66%) — some of the new branch logic in workers/data-api.mjs isn't exercised by the added tests.
  • Extract the relationship→counterparties envelope wrapping (workers/data-api.mjs and src/counterparties.mjs) into one shared function to prevent future divergence between the Postgres and D1 paths.
  • Add a test for the zero-transfer case (relationship.transfer_count === 0) to confirm counterparties stays an empty array on the Postgres path.
  • workers/data-api.mjs:2409 duplicates the D1 `loadCounterpartyRelationship` envelope construction shown in `src/counterparties.mjs`, which increases drift risk between the two branches.

Why this is blocked

  • Pull request fix(data-api): wrap Postgres counterparty drilldowns #4959 links a Codex task but no eligible open issue in this repository, so it violates the repo's required issue-scope gate for contributor PRs.
  • 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.

CI checks failing

  • codecov/patch — 66.66% of diff hit (target 99.00%)
Signal Result Evidence
Code review ❌ 3 blockers 2 reviewers, synthesized
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: 44 registered-repo PR(s), 36 merged, 476 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 44 PR(s), 476 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: 44 PR(s), 476 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

…ty wrap

codecov/patch flagged the transfer_count===0 branch of the new
counterparties-array wrapping as only partially covered (patch coverage
66.67%) -- the existing test only exercised a populated relationship.
@JSONbored JSONbored force-pushed the codex/fix-postgres-counterparty-drilldown-response branch from c74b273 to bed0d1c Compare July 12, 2026 15:29
@JSONbored JSONbored merged commit 381fd7f into main Jul 12, 2026
14 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Block-Explorer Completion Jul 12, 2026
@JSONbored JSONbored deleted the codex/fix-postgres-counterparty-drilldown-response branch July 12, 2026 15:34
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

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant