Skip to content

feat(agentflow): implement deduplication for API client#6004

Merged
jocelynlin-wd merged 2 commits intomainfrom
feat/agentflow-dedup-api-calls
Mar 17, 2026
Merged

feat(agentflow): implement deduplication for API client#6004
jocelynlin-wd merged 2 commits intomainfrom
feat/agentflow-dedup-api-calls

Conversation

@jocelynlin-wd
Copy link
Copy Markdown
Contributor

@jocelynlin-wd jocelynlin-wd commented Mar 17, 2026

  • Updated bindApiClient to return a deduplicated client, enhancing request efficiency.
  • Introduced deduplicatedClient with caching and deduplication logic for GET and POST requests.
  • Added tests for deduplicatedClient to ensure correct behavior for various request scenarios.
  • Added request interceptor example usage in BasicExample to manage cookie handling based on token presence.

Before api dedup:

agentflow-sdk-api-calls-original.mov

After:

agentflow-sdk-api-calls-dedup.mov

- Updated bindApiClient to return a deduplicated client, enhancing request efficiency.
- Introduced deduplicatedClient with caching and deduplication logic for GET and POST requests.
- Added tests for deduplicatedClient to ensure correct behavior for various request scenarios.
- Added request interceptor example usage in BasicExample to manage cookie handling based on token presence.
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the efficiency of API interactions by introducing a robust deduplication and caching mechanism for the API client. By preventing redundant requests and reusing recent responses, it aims to reduce network traffic, decrease server load, and enhance the responsiveness of the application, particularly for frequently accessed, idempotent data.

Highlights

  • API Client Deduplication: Implemented a new deduplicatedClient wrapper for Axios instances to prevent redundant API calls, enhancing request efficiency and reducing server load.
  • Caching Mechanism: Introduced a caching layer within the deduplicatedClient for GET requests and specific POST requests (e.g., /node-load-method/*), storing responses for a configurable Time-To-Live (TTL).
  • In-flight Request Management: Added logic to deduplicate concurrent identical requests, ensuring that only one request is sent to the server while multiple callers await the same response.
  • API Client Integration: Updated bindApiClient to return the new DeduplicatedClient type, automatically applying the deduplication and caching logic to all API interactions.
  • Request Interceptor Example: Included an example in BasicExample.tsx demonstrating how to use a requestInterceptor to conditionally manage cookie handling based on the presence of an authentication token.
  • Comprehensive Testing: Added a dedicated test file (deduplicatedClient.test.ts) to thoroughly validate the deduplication, caching, and error handling behavior of the new client.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a request deduplication and caching layer for the API client, which is a great step towards improving performance and efficiency. The implementation in deduplicatedClient.ts is well-structured, using separate maps for in-flight requests and cached responses, and correctly identifies cacheable request types. The accompanying test suite is comprehensive and covers many important scenarios. I've made a couple of suggestions for improvement: one is a minor code style refinement, and the other addresses a potential race condition in the cache clearing logic which I've marked as high severity. Overall, this is a solid contribution.

Remove inFlight.clear() from clearCache() to prevent race condition
where concurrent in-flight requests could be duplicated. Simplify
nullish check to idiomatic != null.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@jocelynlin-wd jocelynlin-wd requested a review from j-sanaa March 17, 2026 23:43
@jocelynlin-wd jocelynlin-wd merged commit 52e1408 into main Mar 17, 2026
7 checks passed
@jocelynlin-wd jocelynlin-wd deleted the feat/agentflow-dedup-api-calls branch March 17, 2026 23:58
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.

2 participants