Skip to content

feat: enable concurrent replacement with key deduplication#432

Open
AmaadMartin wants to merge 2 commits into
google:mainfrom
AmaadMartin:feat/concurrent-replacement-dedup
Open

feat: enable concurrent replacement with key deduplication#432
AmaadMartin wants to merge 2 commits into
google:mainfrom
AmaadMartin:feat/concurrent-replacement-dedup

Conversation

@AmaadMartin

@AmaadMartin AmaadMartin commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Link to Issue or Description of Change

Or, if no issue exists, describe the change:

Problem:
The injectSessionState function in adk-js resolved placeholders sequentially. If the same placeholder (especially artifacts) was used multiple times, it resulted in redundant and slow service calls. It also lacked concurrency for resolving different placeholders.

Solution:
Refactored injectSessionState to:

  1. Parse all placeholders in the template.
  2. Deduplicate them based on their normalized key and optionality.
  3. Resolve unique placeholders concurrently using Promise.all.
  4. Reconstruct the template with the resolved values.
  5. Extracted the resolution logic to a standalone function resolveKey at the module level.
  6. Support optional artifacts ({artifact.name?}) by resolving to "" if missing (closing parity gap with Python).
  7. Skip resolving invalid placeholders, leaving them as-is.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Summary of passed results:

  • Added a unit test loads artifact only once when duplicate placeholders are present to verify that duplicate artifact placeholders only trigger a single load call.
  • Added unit tests for optional artifacts (resolves missing optional artifact to empty string), mixed required/optional placeholders, and invalid placeholder passthrough.
  • Verified all unit tests pass.

Checklist

  • I have performed a self-review of my own code.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.

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.

1 participant