Skip to content

fix(sessions): skip state and timestamp updates for partial events in InMemorySessionService - #1990

Open
chjpooh2002 wants to merge 1 commit into
google:mainfrom
chjpooh2002:fix/in-memory-session-partial-event
Open

chjpooh2002 wants to merge 1 commit into
google:mainfrom
chjpooh2002:fix/in-memory-session-partial-event

Conversation

@chjpooh2002

Copy link
Copy Markdown

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

2. Summary of Change:

  • Problem: InMemorySessionService.appendEvent mutated appState, userState, session.state(), and session.lastUpdateTime (and re-stored the session) even when event.partial() was true, while BaseSessionService.super.appendEvent skipped appending the event itself.
  • Solution: Return Single.just(event) early immediately after the null checks when event.partial().orElse(false) is true, matching BaseSessionService.appendEvent (BaseSessionService.java:217-235) and adk-python's InMemorySessionService.append_event.

Testing Plan

Unit Tests:

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

Added InMemorySessionServiceTest#appendEvent_partialEvent_doesNotMutateStateOrTimestamp:

  • Verified failure before the fix (expected not to contain: sessionKey, but was: [app:appKey, sessionKey, user:userKey]; Tests run: 19, Failures: 1, Errors: 0, Skipped: 0).
  • Verified pass after the fix (./mvnw -pl core -Dtest=InMemorySessionServiceTest test-compile surefire:test@default-test -> Tests run: 19, Failures: 0, Errors: 0, Skipped: 0, BUILD SUCCESS).

Manual End-to-End (E2E) Tests:

N/A (pure in-memory session unit behavior covered by unit tests).

Checklist

  • I have read the CONTRIBUTING.md document.
  • My pull request contains a single commit.
  • 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.

@google-cla

google-cla Bot commented Dec 2, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Objects.requireNonNull(session.userId(), "session.userId cannot be null");
Objects.requireNonNull(session.id(), "session.id cannot be null");

if (event.partial().orElse(false)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

FYI: VertexAiSessionService.appendEvent and FirestoreSessionService.appendEvent have the same partial-event gap. VertexAiSessionService delegates to BaseSessionService.super.appendEvent (which returns Single.just(event) early), then still chains .flatMap(...) into client.appendEvent(...), and FirestoreSessionService writes stateDelta before checking partial(). Fine to keep this PR scoped to InMemorySessionService, just flagging the other two in case you want them consistent.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch, thanks for checking the other implementations! I'll keep this PR focused on InMemorySessionService to match #1987, and I've filed #1993 to track the follow-up fix for VertexAiSessionService and FirestoreSessionService.

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.

InMemorySessionService.appendEvent mutates state and lastUpdateTime for partial events

2 participants