BufferedSessionService over DatabaseSessionService drops events from a Workflow with an LlmAgent node (StaleSessionError)
メンテナーはふだん 3 日以内に返信
@sanketpatil06 がすでに取り組んでいます。
2026年11月18日 から。
評価
この issue はまだ評価されていません。
説明
🔴 Required Information
Describe the Bug:
I wrapped DatabaseSessionService in the new BufferedSessionService (e1deb17f5) and ran a Workflow that has an LlmAgent node. The model's reply, and every event after it, never get stored. flush_session then raises SessionPersistenceError, caused by StaleSessionError. The runner still yields all the events to the caller, so nothing looks wrong until the flush, or until the session is read back.
The same run without the buffer stores all 4 events. SqliteSessionService and InMemorySessionService aren't affected, with or without the buffer.
What I think is happening:
- An
LlmAgentused as a workflow node runs insingle_turnmode._llm_agent_wrapper.pyadds a synthetic user event straight toctx.session.events(line 387), then removes it (_remove_event, line 503). Neither change goes throughappend_event. - The write buffer finds a live session's chain by
_version_of(session)(_session_write_buffer.py:548): the number of events, the last event id,last_update_timeand the storage marker. The in-place edit changes the first two, so_SessionWriter.store_session_formisses and falls back to_new_store_session. _new_store_sessioncopies the live session's storage marker. That marker is still the one from before the earlier buffered writes landed, soDatabaseSessionServicerejects the write as stale (database_session_service.py:1060).
With a tracer on store_session_for, the lookup misses as soon as the synthetic event is on the session while earlier writes are still pending:
store_session_for: events=1 last_author=user chain_hit=True pending=1
store_session_for: events=3 last_author=user chain_hit=False pending=2
store_session_for: events=3 last_author=llm chain_hit=False pending=3
The plain DatabaseSessionService writes the new marker onto the session object on every append, so there the in-place edit does no harm.
Steps to Reproduce:
- Check out main (b916291fc) with
aiosqliteinstalled - Run the script below
Expected Behavior:
The buffered service stores the same session the plain one does (['user', 'wf', 'llm', 'wf']), as the BufferedSessionService docs promise.
Observed Behavior:
DatabaseSessionService buffered=False yielded=3 stored_events=4 error=None
stored authors: ['user', 'wf', 'llm', 'wf']
DatabaseSessionService buffered=True yielded=3 stored_events=2 error=SessionPersistenceError cause=StaleSessionError
stored authors: ['user', 'wf']
SqliteSessionService buffered=False yielded=3 stored_events=4 error=None
SqliteSessionService buffered=True yielded=3 stored_events=4 error=None
If the first node is slower (I tried a 0.5 s sleep), the run itself raises SessionPersistenceError partway through, after yielding only 2 events.
Environment Details:
- ADK Library Version: main at b916291fc
- Desktop OS: macOS
- Python Version: 3.12.13
Model Information:
- Are you using LiteLLM: No
- Which model is being used: N/A (a scripted
BaseLlmreturning one text reply)
🟡 Optional Information
Regression:
No. BufferedSessionService is new in e1deb17f5.
Minimal Reproduction Code:
import asyncio, tempfile
from google.adk.agents.llm_agent import LlmAgent
from google.adk.events.event import Event
from google.adk.models.base_llm import BaseLlm
from google.adk.models.llm_response import LlmResponse
from google.adk.runners import Runner
from google.adk.sessions import BufferedSessionService
from google.adk.sessions.database_session_service import DatabaseSessionService
from google.adk.workflow import BaseNode, START
from google.adk.workflow._workflow import Workflow
from google.genai import types
class FakeModel(BaseLlm):
model: str = 'fake'
async def generate_content_async(self, llm_request, stream=False):
yield LlmResponse(content=types.Content(role='model', parts=[types.Part(text='hi')]))
class Out(BaseNode):
value: str = ''
async def _run_impl(self, *, ctx, node_input):
yield Event(output=self.value)
async def run(buffered: bool):
store = DatabaseSessionService(db_url=f'sqlite+aiosqlite:///{tempfile.mkdtemp()}/s.db')
sessions = BufferedSessionService(store) if buffered else store
wf = Workflow(name='wf', edges=[(
START, Out(name='a', value='A'), LlmAgent(name='llm', model=FakeModel()),
Out(name='c', value='C'),
)])
runner = Runner(app_name='app', agent=wf, session_service=sessions)
s = await sessions.create_session(app_name='app', user_id='u')
error = None
try:
async for _ in runner.run_async(
user_id='u', session_id=s.id,
new_message=types.Content(role='user', parts=[types.Part(text='go')])):
pass
if buffered:
await sessions.flush_session(app_name='app', user_id='u', session_id=s.id)
except Exception as e:
error = f'{type(e).__name__} (cause: {type(e.__cause__).__name__})'
stored = await store.get_session(app_name='app', user_id='u', session_id=s.id)
print(f'buffered={buffered}: error={error} stored authors={[e.author for e in stored.events]}')
async def main():
await run(False)
await run(True)
asyncio.run(main())
Additional Context:
Two ways I can see to fix it, but I'm not sure which you'd prefer:
- have the wrapper add and remove its synthetic event in a way the buffer can follow (or keep it off
session.events, if the LLM flow can take it some other way); - or make
_new_store_session(or the chain lookup) not depend on the live session's event list and marker being untouched between appends, for example by keying the chain on the session identity rather than its version.
User code that edits session.events between appends would hit the same miss, but _llm_agent_wrapper is the only place in ADK I found that does it. I'm happy to send a PR once you've picked a direction.
How often has this issue occurred?:
- Always (100%)
- 主要言語
- Python
- スター
- 22.3k
- フォーク
- 4.4k
- 平均マージ
- 1日 2時間
- マージ済み PR(30日)
- 6
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
google/adk-python のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
google/adk-python#8360 ·
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
google/adk-python#8359 ·
メンテナーはふだん 3 日以内に返信
-
Can pin to litellm version be changed?対応中かも @llalitkumarrr が 10 日前に担当しました。 オープンmodels
難易度 1/5 1時間未満 初心者へのやさしさ 65/100
google/adk-python#8129 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 3 日以内に返信
-
OpenAPI tools ignore operation- and path-level server overrides対応中かも @sanketpatil06 が 14 日前に担当しました。 オープンtools
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
google/adk-python#8064 · コメント 4 件 · 担当者 1 名 ·
メンテナーはふだん 3 日以内に返信
-
Two docstrings in openapi_tool document parameters the signatures do not accept対応中かも @surajksharma07 が 17 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
google/adk-python#8024 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 3 日以内に返信
google/adk-python の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
vllm-project/vllm#70030 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
TigreGotico/tugaphone#408 ·
メンテナーはふだん 1 日以内に返信
-
needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
gke-labs/kube-agents#7308 ·
メンテナーはふだん 1 日以内に返信
-
t: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 3 日以内に返信
-
chore
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
lugassawan/swe-workbench#841 ·