fix(agent): deduplicate parallel fetchSubnetKeys requests#1278
fix(agent): deduplicate parallel fetchSubnetKeys requests#1278nikosxenakis merged 3 commits intodfinity:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR reduces redundant /read_state traffic by deduplicating concurrent HttpAgent.fetchSubnetKeys calls for the same canister, so parallel queries can share a single subnet-keys fetch.
Changes:
- Add an in-flight promise map to deduplicate parallel
fetchSubnetKeyscalls per canister. - Refactor
fetchSubnetKeysinto a public wrapper plus a private#doFetchSubnetKeysimplementation. - Add an e2e test validating only one
read_stateoccurs under parallel calls, and document the fix in the changelog.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/core/src/agent/agent/http/index.ts | Adds in-flight deduplication for subnet key fetching and extracts the core fetch logic. |
| e2e/node/basic/fetchSubnetKeys.test.ts | Adds a regression test ensuring parallel calls only produce one read_state request. |
| CHANGELOG.md | Notes the behavioral fix under Unreleased. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
nikosxenakis
left a comment
There was a problem hiding this comment.
Minor comment, the changes look good to me. Please rebase to latest main before approving.
When multiple query calls are issued in parallel for the same canister, each call triggers its own read_state round-trip to fetch subnet keys before the first response can populate the cache. This PR introduces an inflight deduplication map (#subnetKeysFetching) so that concurrent fetchSubnetKeys calls for the same canister share a single read_state round-trip instead of each issuing their own. Fixes dfinity#1179 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
fetchSubnetKeys now returns the cached SubnetNodeKeys immediately when a valid entry exists within the TTL, avoiding a redundant read_state round-trip on sequential calls. Also adds an e2e test to verify that two sequential fetchSubnetKeys calls within the cache TTL produce only one read_state request. Addresses Copilot review feedback.
fe983ea to
5213a3c
Compare
|
@yasumorishima Please ensure |
5213a3c to
6c175f7
Compare
|
Thanks for the review @nikosxenakis!
|
nikosxenakis
left a comment
There was a problem hiding this comment.
@yasumorishima Thank you for the contribution! All changes look good, merging now.
Description
When multiple query calls are issued in parallel for the same canister, each call triggers its own
read_stateround-trip to fetch subnet keys before the first response can populate the cache.This PR introduces an inflight deduplication map (
#subnetKeysFetching) so that concurrentfetchSubnetKeyscalls for the same canister share a singleread_stateround-trip instead of each issuing their own.Fixes #1179
Changes
packages/core/src/agent/agent/http/index.ts: add#subnetKeysFetchingmap and splitfetchSubnetKeysinto public wrapper +#doFetchSubnetKeyse2e/node/basic/fetchSubnetKeys.test.ts: add parallel deduplication testCHANGELOG.md: add entry