Portfolio legs degrade per-fetch instead of losing whole layers#58
Conversation
… 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.
|
Warning Review limit reached
Next review available in: 1 minute Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Greptile SummaryThis PR makes portfolio layers degrade smaller pieces instead of dropping whole sections. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (4): Last reviewed commit: "review: skipped over-cap wallets surface..." | Re-trigger Greptile |
There was a problem hiding this comment.
💡 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".
| 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"); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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).
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.
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.
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
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.FetchEngineTokensWithBalanceis 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