Skip to content

fix(staking): don't fail page load when publisher caps request fails - #4102

Open
debojyoti10CC wants to merge 1 commit into
pyth-network:mainfrom
debojyoti10CC:fix/staking-publisher-caps-404
Open

debojyoti10CC wants to merge 1 commit into
pyth-network:mainfrom
debojyoti10CC:fix/staking-publisher-caps-404

Conversation

@debojyoti10CC

@debojyoti10CC debojyoti10CC commented Nov 24, 2026 •

Copy link
Copy Markdown

Summary

loadPublisherData in apps/staking/src/api.ts fetched publisher caps from Hermes inside a Promise.all. When that request fails (the endpoint currently returns 404, which browsers report as an opaque Failed to fetch because the error response has no CORS headers), the rejection takes down the whole page and users see the error boundary.

Publisher caps are optional data, so I wrapped just that call: on any error it logs a warning and the caps are treated as absent. poolCapacity then falls back to 0n, which is what the code already did when a publisher had no entry. The rest of the page loads normally.

I catch every error rather than only 404, since the browser never exposes the status code in the CORS-failure case described in the issue.

Testing

Added apps/staking/src/api.test.ts with two cases: caps returned by Hermes are used, and a rejected caps request still yields publisher data with zero caps.

I could not run the tests, typecheck or lint locally: the pnpm workspace install did not finish on my Windows machine. Please rely on CI. Manual check: make the Hermes publisher_stake_caps request fail (e.g. block it in devtools) and confirm the staking page still renders.

Note: this issue was opened before #4029 and #4041 changed how publisher caps are loaded, so the 404 itself may no longer happen in production. The current loadData still awaits the caps request inside Promise.all, though, so any caps failure would still take down the whole page. If you'd rather not handle that case, feel free to close this.

Fixes #4027


Devin Review

@debojyoti10CC
debojyoti10CC requested a review from a team as a code owner November 24, 2026 04:27
@vercel

vercel Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

4 Skipped Deployments
Project Deployment Actions Updated
api-reference Skipped Skipped Nov 24, 2026 4:27am UTC
component-library Skipped Skipped Nov 24, 2026 4:27am UTC
entropy-explorer Skipped Skipped Nov 24, 2026 4:27am UTC
proposals Skipped Skipped Nov 24, 2026 4:27am UTC

Request Review

@vercel
vercel Bot temporarily deployed to Preview – entropy-explorer November 24, 2026 04:27 Inactive
@vercel

vercel Bot commented Nov 24, 2026

Copy link
Copy Markdown

@debojyoti10CC is attempting to deploy a commit to the Pyth Network Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
vercel Bot temporarily deployed to Preview – api-reference November 24, 2026 04:27 Inactive
@vercel
vercel Bot temporarily deployed to Preview – proposals November 24, 2026 04:27 Inactive
@vercel
vercel Bot temporarily deployed to Preview – component-library November 24, 2026 04:27 Inactive
@dourolabs-greenlight

dourolabs-greenlight Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Greenlight — 🟢 Ready to authorize

Authorize in Greenlight to merge.

Details

Open in Greenlight →

@devin-ai-integration devin-ai-integration 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.

Devin Review found 3 potential issues.

Devin Review

Comment thread apps/staking/src/api.ts
try {
return await hermesClient.getLatestPublisherCaps({ parsed: true });
} catch (error: unknown) {
console.warn("Failed to load publisher caps", error);

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.

🔍 Fallback warning fails lint

console.warn violates the repository’s noConsole rule. Staking already provides a logger through useLogger.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread apps/staking/src/api.ts
Comment on lines 276 to 280
BigInt(
publisherCaps.parsed?.[0]?.publisher_stake_caps.find(
publisherCaps?.parsed?.[0]?.publisher_stake_caps.find(
({ publisher: p }) => p === publisher.toBase58(),
)?.cap ?? 0,
);

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.

🔍 Unavailable caps look like inactive pools

When Hermes rejects, getPublisherCap makes missing caps indistinguishable from real zero caps. UtilizationMeter then labels every pool inactive, and calculateApy returns zero.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +54 to +65
it("still loads the page with zero caps if the caps request fails", async () => {
const warn = jest.spyOn(console, "warn").mockImplementation(() => {
/* silence expected warning */
});
const caps = jest.fn().mockRejectedValue(new TypeError("Failed to fetch"));
const data = await loadData(makeStakingClient(), makeHermesClient(caps));
expect(data.integrityStakingPublishers).toHaveLength(1);
expect(data.integrityStakingPublishers[0]?.poolCapacity).toBe(0n);
expect(data.yieldRate).toBe(7n);
expect(warn).toHaveBeenCalled();
warn.mockRestore();
});

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.

🔍 Unverified regression test

The loadData regression test has not been run. The testing standard requires observing it fail without the fix and pass with it.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@imbik-rectifier imbik-rectifier Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Rectifier review: Request changes

Round 1, at fd0b071. 3 findings, 1 blocking. Reviewed in 241s.

Priority Finding Where
High Failed caps request shows every pool as 0-capacity inactive apps/staking/src/api.ts:268
Medium Bare console.warn violates the repo's noConsole rule apps/staking/src/api.ts:267
Medium New test file is not biome-formatted, failing CI apps/staking/src/api.test.ts:47

Comment @imbik-rectifier review to review again after a push.

CI failures no finding explains: Vercel – staking.

Comment thread apps/staking/src/api.ts
return await hermesClient.getLatestPublisherCaps({ parsed: true });
} catch (error: unknown) {
console.warn("Failed to load publisher caps", error);
return undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[High] Failed caps request shows every pool as 0-capacity inactive

When the Hermes publisher-caps request fails, getLatestPublisherCaps swallows the error and every publisher's poolCapacity becomes 0n, which the rest of the app treats as an authoritative zero cap. Every row then renders "Inactive Pool" with a used / 0 label, and because calculateApy short-circuits to 0 on a zero capacity, all publishers read 0.00% estimated APY. The only trace of the degraded load is a console warning.

Impact: A transient caps failure makes the whole staking table read as inactive, zero-capacity pools with 0% APY, and users get no signal the data is missing.

Likelihood: Normal use (any transient Hermes or network failure during the 60s dashboard poll)

Unconfirmed: suspected: rests on SWR's background revalidation replaces the cached value with each newly resolved fetcher result (swr 2.3.3), so a degraded load overwrites good cached caps, not checked. Check it before you merge.

Message to fix with an agent
A code reviewer flagged a possible problem in this pull request. Check that it is real before you
change anything. If it is not real, or not worth fixing, say why and change nothing.

Repository: pyth-network/pyth-crosschain, PR #4102, reviewed at commit fd0b071e716cd1abb89728b721388ad70f58d921
Issue: Failed caps request shows every pool as 0-capacity inactive
Severity: High
Reviewer: suspected: rests on SWR's background revalidation replaces the cached value with each newly resolved fetcher result (swr 2.3.3), so a degraded load overwrites good cached caps, not checked
Where: getLatestPublisherCaps in apps/staking/src/api.ts (line 268 at that commit):
        console.warn("Failed to load publisher caps", error);
        return undefined;

Problem: getLatestPublisherCaps (apps/staking/src/api.ts:261-270) converts any caps failure into
`undefined`, and getPublisherCap (apps/staking/src/api.ts:272-280) maps `undefined` caps to `0n`, so
loadPublisherData publishes `poolCapacity: 0n` (apps/staking/src/api.ts:243) as if it were real cap
data. `0n` is an authoritative value downstream, so "caps unavailable" is indistinguishable from
"pool has no capacity".

Evidence:
- calculateApy returns 0 when `poolCapacity === 0n`
  (governance/pyth_staking_sdk/src/utils/apy.ts:25-27), which drives the "Estimated next APY" cell
  (apps/staking/src/components/OracleIntegrityStaking/index.tsx:1190-1200).
- UtilizationMeter computes NaN when poolCapacity is not > 0n and renders the literal "Inactive
  Pool" plus a `{poolUtilization} / {poolCapacity}` label
  (apps/staking/src/components/OracleIntegrityStaking/index.tsx:1354-1362, 1389-1403).
- comparePoolCapacity treats 0n as "no remaining pool" and sorts those rows last, so list order
  degrades too (apps/staking/src/components/OracleIntegrityStaking/index.tsx:1018-1044).
- useData only surfaces an error when the fetcher rejects
  (apps/staking/src/hooks/use-data.ts:19-28); the degraded load resolves, so Home renders it as
  Loaded and re-fetches it every 60s (apps/staking/src/components/Home/index.tsx:87-89), overwriting
  previously good cached caps.

Expected: the dashboard can tell "caps unavailable" from "cap is zero", and a failed background
refresh does not replace known caps with zeros.

Suggested fix: keep the page load non-fatal but propagate absence instead of zero: type poolCapacity
as `bigint | undefined` (apps/staking/src/api.ts:46) or add a `publisherCapsAvailable: boolean` to
the loaded Data, render "-"/an unknown state (plus a short notice) instead of "Inactive Pool" and
0.00% APY for that state, and skip overwriting the cached caps on a failed refresh.

The suggested fix is a starting point. If you find a better one, weigh the tradeoffs, make that fix
instead, and say why in your change description.

Keep the change to this issue.

Resolve this thread if it is not an issue, and later reviews of this change will not raise it again. Unresolve it to undo that.

Comment thread apps/staking/src/api.ts
try {
return await hermesClient.getLatestPublisherCaps({ parsed: true });
} catch (error: unknown) {
console.warn("Failed to load publisher caps", error);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Medium] Bare console.warn violates the repo's noConsole rule

The repo sets Biome's suspicious/noConsole to error with no allow-list, and every existing console.* in tracked code carries an explicit biome-ignore suppression. This new call has none, so the lint job that CI runs over changed files fails on it.

Impact: The repo's lint gate fails on this PR, blocking the merge until the call is suppressed or replaced.

Likelihood: Normal use (the repo lint job runs biome over this changed file on every PR)

Message to fix with an agent
A code reviewer flagged a possible problem in this pull request. Check that it is real before you
change anything. If it is not real, or not worth fixing, say why and change nothing.

Repository: pyth-network/pyth-crosschain, PR #4102, reviewed at commit fd0b071e716cd1abb89728b721388ad70f58d921
Issue: Bare console.warn violates the repo's noConsole rule
Severity: Medium
Reviewer: confirmed from the source
Where: getLatestPublisherCaps in apps/staking/src/api.ts (line 267 at that commit):
        console.warn("Failed to load publisher caps", error);

Problem: apps/staking/src/api.ts:267 calls `console.warn`, but biome.json:192 sets
`suspicious.noConsole` to `"error"` with no `options.allow`, and `files.includes` is `**` with
nothing excluding apps/staking (biome.json:19-33). CI runs `pnpm turbo test`
(.github/workflows/ci-turbo-test.yml:48), whose `test` task depends on `//#test:lint`
(turbo.json:113-121), and that script is ./scripts/biome-ci, which under CI runs `biome ci
--changed` (scripts/biome-ci:10) over exactly the changed file.

Evidence:
- Repo convention is an explicit suppression for every intentional console use, e.g. `/**
  biome-ignore-all lint/suspicious/noConsole: CLI script */` in contract_manager/scripts/*; grepping
  `console\.` under apps/staking returns only this new line.
- apps/staking/src/api.test.ts:63 asserts console.warn was called, so the warning channel is coupled
  to the test.

Suggested fix: add `// biome-ignore lint/suspicious/noConsole: optional publisher caps failed to
load` directly above the call (keeping the call so the test assertion still holds), or route the
warning through a module-level pino instance and assert on that instead.

The suggested fix is a starting point. If you find a better one, weigh the tradeoffs, make that fix
instead, and say why in your change description.

Keep the change to this issue.

Resolve this thread if it is not an issue, and later reviews of this change will not raise it again. Unresolve it to undo that.

it("uses the caps returned by hermes", async () => {
const caps = jest.fn().mockResolvedValue({
parsed: [
{ publisher_stake_caps: [{ cap: 42, publisher: PUBLISHER.toBase58() }] },

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Medium] New test file is not biome-formatted, failing CI

Several lines in the new test exceed the 80-column width Biome's formatter uses (the caps fixture above, the @pythnetwork/staking-sdk import, and the second it(...) header). The repo sets no lineWidth override, and biome ci fails on a changed file that still needs formatting, which matters here since the PR asks reviewers to rely on CI.

Impact: The repo's lint/format CI job fails on this PR until the new file is reformatted.

Likelihood: Normal use (CI format check runs biome over this new file on every PR)

Message to fix with an agent
A code reviewer flagged a possible problem in this pull request. Check that it is real before you
change anything. If it is not real, or not worth fixing, say why and change nothing.

Repository: pyth-network/pyth-crosschain, PR #4102, reviewed at commit fd0b071e716cd1abb89728b721388ad70f58d921
Issue: New test file is not biome-formatted, failing CI
Severity: Medium
Reviewer: confirmed from the source
Where: api.test.ts in apps/staking/src/api.test.ts (line 47 at that commit):
            { publisher_stake_caps: [{ cap: 42, publisher: PUBLISHER.toBase58() }] },

Problem: apps/staking/src/api.test.ts has lines longer than 80 columns, measured at 81 for line 3
(`import { extractPublisherData, getCurrentEpoch } from "@pythnetwork/staking-sdk";`), 81 for line
47 (the caps fixture) and 84 for line 54 (the `it("still loads the page with zero caps ...")`
header). biome.json's formatter section sets no `lineWidth`, so Biome's 80-column default applies,
and `biome ci --changed` (scripts/biome-ci:10, run by `//#test:lint` via `pnpm turbo test`) reports
a formatter difference for the new file.

Suggested fix: run `pnpm fix:lint` (or `biome check --write apps/staking/src/api.test.ts`) and
commit the reformatting, so Biome rewraps the import, the nested literal and the long test header.

The suggested fix is a starting point. If you find a better one, weigh the tradeoffs, make that fix
instead, and say why in your change description.

Keep the change to this issue.

Resolve this thread if it is not an issue, and later reviews of this change will not raise it again. Unresolve it to undo that.

This branch was previously deployed

4 inactive deployments
Preview – api-reference — fd0b071e Deployed Nov 24, 2026 by vercel[bot]
Preview – proposals — fd0b071e Deployed Nov 24, 2026 by vercel[bot]
Preview – component-library — fd0b071e Deployed Nov 24, 2026 by vercel[bot]
Preview – entropy-explorer — fd0b071e Deployed Nov 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

staking.pyth.network fails to render — hermes publisher_stake_caps endpoint returns 404

1 participant