Skip to content

fix(agent): deduplicate parallel fetchSubnetKeys requests#1278

Merged
nikosxenakis merged 3 commits intodfinity:mainfrom
yasumorishima:fix/deduplicate-fetchSubnetKeys
Mar 10, 2026
Merged

fix(agent): deduplicate parallel fetchSubnetKeys requests#1278
nikosxenakis merged 3 commits intodfinity:mainfrom
yasumorishima:fix/deduplicate-fetchSubnetKeys

Conversation

@yasumorishima
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 fetchSubnetKeys calls per canister.
  • Refactor fetchSubnetKeys into a public wrapper plus a private #doFetchSubnetKeys implementation.
  • Add an e2e test validating only one read_state occurs 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.

Copy link
Copy Markdown
Contributor

@nikosxenakis nikosxenakis left a comment

Choose a reason for hiding this comment

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

Minor comment, the changes look good to me. Please rebase to latest main before approving.

yasumorishima and others added 2 commits March 10, 2026 17:50
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.
@yasumorishima yasumorishima force-pushed the fix/deduplicate-fetchSubnetKeys branch from fe983ea to 5213a3c Compare March 10, 2026 08:51
@nikosxenakis
Copy link
Copy Markdown
Contributor

@yasumorishima Please ensure afterEach is imported

@yasumorishima yasumorishima force-pushed the fix/deduplicate-fetchSubnetKeys branch from 5213a3c to 6c175f7 Compare March 10, 2026 09:34
@yasumorishima
Copy link
Copy Markdown
Contributor Author

Thanks for the review @nikosxenakis!

  • Added afterEach to the vitest import statement — good catch, it was missing from the import line.
  • Rebased onto latest main.

Copy link
Copy Markdown
Contributor

@nikosxenakis nikosxenakis left a comment

Choose a reason for hiding this comment

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

@yasumorishima Thank you for the contribution! All changes look good, merging now.

@nikosxenakis nikosxenakis merged commit 8acb47b into dfinity:main Mar 10, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Share subnet key across parallel query calls

3 participants