fix(adk): prevent session event duplication in KAgentSessionService#1500
Merged
EItanya merged 2 commits intokagent-dev:mainfrom Mar 13, 2026
Merged
Conversation
Signed-off-by: Brian Fox <878612+onematchfox@users.noreply.github.com>
Signed-off-by: Brian Fox <878612+onematchfox@users.noreply.github.com>
67fc1af to
7c62ef3
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes duplicated session events in KAgentSessionService.get_session by avoiding pre-populating Session.events before re-appending via BaseSessionService.append_event.
Changes:
- Initialize
Sessionwith an emptyeventslist inget_sessionto prevent double-appends. - Add unit tests covering 404/empty responses, event ID preservation, non-duplication, and state-delta expectations.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| python/packages/kagent-adk/src/kagent/adk/_session_service.py | Stops event duplication by constructing Session with events=[] before appending events via the base service. |
| python/packages/kagent-adk/tests/unittests/test_session_service.py | Adds regression tests to ensure events aren’t duplicated and basic session loading behavior is correct. |
Comments suppressed due to low confidence (1)
python/packages/kagent-adk/tests/unittests/test_session_service.py:1
- These assertions won’t actually fail if the same
state_deltais applied twice viadict.update(...)(applying{'counter': 7}twice still results in7, and settingkey_a/key_btwice is also indistinguishable). To make this a real regression test, consider asserting the number of baseappend_event/_update_session_stateinvocations (e.g., by spying/patching) equalslen(events), or use a non-idempotent delta format if the ADK supports one.
"""Tests for KAgentSessionService."""
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+50
to
+51
| mock_response.raise_for_status = MagicMock() | ||
|
|
supreme-gg-gg
approved these changes
Mar 13, 2026
EItanya
approved these changes
Mar 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a session event duplication bug in
KAgentSessionService.get_sessionwhere every event loaded from the database was appended twice tosession.events.get_sessionconstructed theSessionwithevents=events(pre-populating the list), then immediately calledsuper().append_event()for each event.BaseSessionService.append_eventunconditionally callssession.events.append(event), so every event ended up in the list twice.The bug was latent for normal usage because the LLM tolerates redundant history in simple Q&A flows. It was discovered while testing #1491 locally, where the duplicated context caused incorrect agent behaviour. However, it does cause context bloat since, ultimately, every conversation turn currently sends 2× the necessary history to the model. 😬