Skip to content

fix: filter temp: state keys from sub-agent delta in AgentTool#271

Open
nuthalapativarun wants to merge 7 commits into
google:mainfrom
nuthalapativarun:fix/agent-tool-temp-state-leak
Open

fix: filter temp: state keys from sub-agent delta in AgentTool#271
nuthalapativarun wants to merge 7 commits into
google:mainfrom
nuthalapativarun:fix/agent-tool-temp-state-leak

Conversation

@nuthalapativarun
Copy link
Copy Markdown
Contributor

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

Problem:
AgentTool.runAsync() propagates every key from a sub-agent's stateDelta to the parent context via toolContext.state.update(event.actions.stateDelta). Keys prefixed with State.TEMP_PREFIX (temp:) are explicitly designed to be ephemeral, per-invocation state that must not be persisted or cross agent boundaries. Because no filtering was applied, any temp: key written by the sub-agent leaked into the parent session state, overwriting or polluting it.

Solution:
Before calling toolContext.state.update(), filter out all keys that start with State.TEMP_PREFIX. If the resulting delta is empty (all keys were temp:), skip the update entirely.

This aligns with the same filtering applied in BaseSessionService.trimTempDeltaState() at session-persistence time, and matches the behaviour of the Python ADK.

Testing Plan

Unit Tests:

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

Summary of passed npm test results:

✓ |unit:core| core/test/tools/agent_tool_test.ts (3 tests)
✓ |integration| tests/integration/tools/agent_tool_test.ts (1 test)

Test Files  2 passed (2)
     Tests  4 passed (4)

Full suite: 1120 passed | 21 skipped (1141)

Manual End-to-End (E2E) Tests:
The filtering is applied only to keys that start with temp:. Non-temp state delta propagation is unchanged and verified by the existing integration test.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • 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.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

When AgentTool propagates a sub-agent's stateDelta to the parent
context, keys prefixed with State.TEMP_PREFIX (temp:) were leaked
into the parent session state. These keys are explicitly designed
to be ephemeral per-invocation and must not cross agent boundaries.

Filter them out before calling toolContext.state.update(), and skip
the update entirely when all delta keys are temp:.
@nuthalapativarun nuthalapativarun force-pushed the fix/agent-tool-temp-state-leak branch from 88ad5af to 09d644c Compare April 18, 2026 03:25
@nuthalapativarun
Copy link
Copy Markdown
Contributor Author

Hi team, gentle ping on this one — happy to address any feedback or make adjustments if needed. Thanks for reviewing!

@nuthalapativarun
Copy link
Copy Markdown
Contributor Author

Hi team, gentle ping on this one — happy to address any feedback or make adjustments if needed. Thanks for reviewing!

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