Skip to content

Portfolio legs degrade per-fetch instead of losing whole layers#58

Merged
feruzm merged 4 commits into
mainfrom
fix/portfolio-leg-partial-degrade
Jul 17, 2026
Merged

Portfolio legs degrade per-fetch instead of losing whole layers#58
feruzm merged 4 commits into
mainfrom
fix/portfolio-leg-partial-degrade

Conversation

@feruzm

@feruzm feruzm commented Jul 17, 2026

Copy link
Copy Markdown
Member

Users intermittently saw external chain balances (and occasionally engine tokens) missing from portfolioV2 responses. The layers are computed under a fail-fast leg timeout, but the fetches inside had far larger budgets: chain balance providers allow 10s per attempt and the unclaimed-rewards upstream 30s. One cold or slow provider pushed the whole leg past its budget and the entire layer silently disappeared — while every individual balance probe answered in well under a second (the balance cache is short, so portfolio requests routinely hit cold providers).

Changes

  • Chain layer: each wallet's balance fetch is capped at 2s inside BuildChainLayer. A capped wallet degrades to an error item (same as an upstream failure today) instead of sinking every other wallet; two concurrency batches still fit inside the leg budget.
  • Engine layer: the unclaimed-rewards fetch inside FetchEngineTokensWithBalance is capped at 2s and degrades to no pending-reward badges. Token balances, metadata, and prices are unaffected — rewards are decoration and shouldn't be able to blank the token list.

No route/response shape changes; both caps reuse the existing degrade paths.

Testing

  • Full suite passes (55).
  • Local run against real upstreams: 10/10 consecutive portfolioV2 calls for a wallet-heavy account returned the complete chain layer (previously intermittent), with engine and hive layers unchanged.

… layer

portfolioV2 runs its chain and engine layers under a single leg timeout.
Chain balance providers allow 10s per attempt and the rewards upstream
30s, so one cold or slow provider blew the leg budget and the entire
layer silently vanished from the response — observed intermittently in
production while every individual balance endpoint answered fast.

- Chain: each wallet's balance fetch is capped at 2s; a capped wallet
  becomes an error item instead of sinking its siblings. Two concurrency
  batches still fit the leg budget.
- Engine: the unclaimed-rewards fetch is capped at 2s and degrades to
  no pending-reward badges instead of blanking the token list.
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@feruzm, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 1 minute

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f2a14d3a-708c-41b3-acc3-325d507651fe

📥 Commits

Reviewing files that changed from the base of the PR and between f34ef6a and d4b0ded.

📒 Files selected for processing (2)
  • dotnet/EcencyApi/Handlers/WalletApi.Engine.cs
  • dotnet/EcencyApi/Handlers/WalletApi.Layers.cs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/portfolio-leg-partial-degrade

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 17, 2026

Copy link
Copy Markdown

Greptile Summary

This PR makes portfolio layers degrade smaller pieces instead of dropping whole sections. The main changes are:

  • Adds a short rewards timeout inside the engine token fetch.
  • Adds per-wallet chain balance timeouts.
  • Caps fetched chain wallets and returns error items for over-limit wallets.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.
  • The latest chain wallet cap now returns explicit error items for configured wallets past the fetch limit.
  • The engine rewards fallback keeps token balances and metadata on the normal path.

Important Files Changed

Filename Overview
dotnet/EcencyApi/Handlers/WalletApi.Engine.cs Adds a bounded rewards fetch fallback so engine token balances can still return when reward badges are slow.
dotnet/EcencyApi/Handlers/WalletApi.Layers.cs Adds bounded chain balance fetches, wider concurrency, and explicit over-limit wallet error items.

Reviews (4): Last reviewed commit: "review: skipped over-cap wallets surface..." | Re-trigger Greptile

Comment thread dotnet/EcencyApi/Handlers/WalletApi.Layers.cs
Comment thread dotnet/EcencyApi/Handlers/WalletApi.Layers.cs
Comment thread dotnet/EcencyApi/Handlers/WalletApi.Engine.cs

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 627871db18

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +684 to +686
var fetchTask = PrivateApi.FetchChainBalance(chain, wallet.Address);
var completed = await Task.WhenAny(fetchTask, Task.Delay(ChainBalanceTimeoutMs));
if (completed != fetchTask) throw new Exception("Chain balance request timed out");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep timed-out chain requests inside the concurrency cap

When a wallet fetch takes longer than 2s, this returns an error item but does not cancel or await the PrivateApi.FetchChainBalance task, whose providers can keep running for their own 10s timeouts. For accounts with several slow external wallets, ProcessWithConcurrencyLimit releases its semaphore as soon as this timeout path returns, so the next batch starts while the previous provider calls are still consuming sockets and upstream capacity; the intended limit of 3 active chain balance requests is no longer enforced under the exact slow-provider case this change is handling.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fair observation on the semaphore accounting. Two bounds keep it tame: in-flight dedup in FetchChainBalance means at most one live fetch per (chain, address) regardless of how many requests or batches overlap, and the width bump in the latest commit makes realistic pools single-batch so the overlap window mostly disappears. True cancellation would need plumbing through the provider stack; not worth it for a deduplicated background call that also warms the balance cache.

At width 3 a 7+ wallet account needed a third 2s batch and still blew
the 4.5s leg. Width 8 covers 16 wallets in two worst-case batches (4s).
Comment thread dotnet/EcencyApi/Handlers/WalletApi.Layers.cs
Guarantees at most two fetch waves inside the leg budget regardless of
how many addresses a profile lists; oversized profiles keep their first
16 wallets instead of risking the whole layer.
Comment thread dotnet/EcencyApi/Handlers/WalletApi.Layers.cs Outdated
The response now acknowledges every configured wallet: entries past the
16-wallet fetch cap appear with a 'Wallet limit reached' error instead
of being silently omitted.
@feruzm
feruzm merged commit fa60d97 into main Jul 17, 2026
5 checks passed
@feruzm
feruzm deleted the fix/portfolio-leg-partial-degrade branch July 17, 2026 06:28
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.

1 participant