fix(agent): deduplicate parallel fetchSubnetKeys requests#1277
Closed
yasumorishima wants to merge 3 commits intodfinity:mainfrom
Closed
fix(agent): deduplicate parallel fetchSubnetKeys requests#1277yasumorishima wants to merge 3 commits intodfinity:mainfrom
yasumorishima wants to merge 3 commits intodfinity:mainfrom
Conversation
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
When multiple query calls are issued in parallel for the same canister, each would trigger its own read_state round-trip to fetch the subnet keys before the first response could populate the cache. Introduce a #subnetKeysFetching inflight map in HttpAgent that stores the in-progress Promise<SubnetNodeKeys> for each canister. Parallel callers reuse the same promise, resulting in exactly one read_state request per canister regardless of concurrency. Closes dfinity#1179
Contributor
Author
|
Closing to recreate from upstream/main. The previous PR accidentally included fork-only files (.coderabbit.yaml, .github/workflows/codeql.yml) because the feature branch was cut from the fork's main instead of upstream/main. Will reopen with a clean branch shortly. |
nikosxenakis
pushed a commit
that referenced
this pull request
Mar 10, 2026
# Description 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 #1179 ## Changes - `packages/core/src/agent/agent/http/index.ts`: add `#subnetKeysFetching` map and split `fetchSubnetKeys` into public wrapper + `#doFetchSubnetKeys` - `e2e/node/basic/fetchSubnetKeys.test.ts`: add parallel deduplication test - `CHANGELOG.md`: add entry > Note: this is a recreation of #1277, which was closed due to accidental inclusion of fork-only files. --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: yasumorishima <yasumplaystore@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 concurrent callers share a singleread_staterequest, resulting in exactly one round-trip per canister regardless of concurrency.Fixes #1179
Changes
packages/core/src/agent/agent/http/index.ts#subnetKeysFetching: Map<string, Promise<SubnetNodeKeys>>field toHttpAgentfetchSubnetKeysinto a new private method#doFetchSubnetKeysfetchSubnetKeysnow checks the inflight map before issuing a new request; parallel callers reuse the same promise and the map entry is cleaned up via.finally()e2e/node/basic/fetchSubnetKeys.test.tsfetchSubnetKeyscalls for the same canister result in exactly oneread_staterequest and identical node keysCHANGELOG.md[Unreleased]How Has This Been Tested?
pnpm test)fetchSubnetKeys (parallel calls deduplication)suiteChecklist: