Environment simulation: a seeded fault injection is not reproducible per eval case; adding an unrelated case or changing parallelism changes which runs fail
メンテナーはふだん 3 日以内に返信
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 30/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- python
調査の方向性
Start with EnvironmentSimulationEngine.init and its _seeded_generators and _draw helpers, which hold one shared seeded sequence per plugin. Run the repro script with case_a alone and with case_a plus case_b at parallelism 1 and 4 to confirm the outcomes differ. Done means each eval case sees the same injection decisions regardless of other cases, order or parallelism, with a regression test covering those three variants; the key choice is still undecided, so maintainer input is needed first.
索引モデルが issue の本文から書いたものです。
説明
🔴 Required Information
Describe the Bug:
InjectionConfig.random_seed is meant to make probabilistic fault injection (injection_probability < 1) repeatable. Today the seeded generator is created once per plugin/engine (EnvironmentSimulationEngine.__init__, self._seeded_generators) and every session the plugin serves draws from the same sequence (_draw). The docstring says so: "one plugin's sequence is shared by every session it serves".
In an eval, one plugin serves every eval case and every num_runs repetition. So whether a given case/run gets the injected error depends on how many draws other cases made before it, which depends on:
- which other eval cases are in the eval set (or selected with
eval_case_ids), - the order of the cases,
parallelism, because concurrent runs interleave their draws.
The seed therefore makes the whole eval invocation repeatable only when nothing else changes, but it does not make an eval case's result repeatable. Adding one unrelated case to the eval set flips results of existing cases, which is exactly the kind of noise a seed is supposed to remove from a regression gate.
Steps to Reproduce:
Offline, no API key: a fake agent model calls charge_card once and replies OK or FAILED depending on whether the tool returned an injected 503. The injection has injection_probability=0.5, random_seed=42. case_a is run with num_runs=3 alone, with an unrelated case_b, in the other order, and with parallelism=4.
$ python repro.py
case_a alone, parallelism=1: case_a runs 0..2 -> ['OK', 'FAILED', 'FAILED']
case_a alone, parallelism=1 (again): case_a runs 0..2 -> ['OK', 'FAILED', 'FAILED']
case_a + case_b, parallelism=1: case_a runs 0..2 -> ['FAILED', 'OK', 'OK']
case_b + case_a order, parallelism=1: case_a runs 0..2 -> ['FAILED', 'FAILED', 'OK']
case_a + case_b, parallelism=4: case_a runs 0..2 -> ['OK', 'OK', 'OK']
Same seed, same case_a, four different outcomes. With parallelism > 1 the outcome also depends on scheduling.
Expected Behavior:
With a fixed random_seed, the injection decisions an eval case's run sees should be the same no matter which other cases run with it, in what order, or with what parallelism.
Observed Behavior:
They depend on the other cases and on scheduling (output above).
Environment Details:
- ADK:
mainat2b90353(2.15.0) - Python 3.12.16, Linux
Model Information: fake BaseLlm registered in the script; no external model.
🟡 Optional Information
Proposed fix (open to discussion):
This is the same root cause as #8040 (fixed for the simulated state store in #8041): per-session data lives on the engine. The natural fix is to give each session its own seeded generator, derived from the seed plus a stable key, e.g. random.Random(hash((seed, tool_name, config_index, key))) or a random.Random(seed) per key.
The open question is the key:
- Session key
(app_name, user_id, session_id), as in #8041. Isolates sessions, but eval session ids are random UUIDs, so the sequence a run sees is still not repeatable across eval invocations unless every session simply restarts the same sequence fromseed. - Restart the sequence per session (every session draws
Random(seed)from the start). Fully repeatable and simple, but everynum_runsrepetition of a case then sees identical injections, so repetitions no longer sample different fault patterns. - Eval case id + repetition index. Repeatable and varies across repetitions, but the plugin does not know them today.
LocalEvalServicecould expose them to the run (for example through the eval client labels it already sets, or a reserved session state key).
I lean towards (3) with (2) as the fallback outside of eval, but would like maintainers' view before implementing. I'd also update the random_seed docstring and add a regression test like the repro (alone vs. with another case vs. parallelism).
Willingness to contribute: Yes, after agreeing on the key. I'd base it on #8041 if that lands first, since both change the same per-session bookkeeping in the engine.
Minimal Reproduction Code:
"""A seeded fault injection is not reproducible per eval case (offline)."""
import argparse, asyncio, logging
from typing import ClassVar
from google.adk.agents.llm_agent import LlmAgent
from google.adk.apps.app import App
from google.adk.evaluation import eval_case as ec
from google.adk.evaluation.base_eval_service import InferenceConfig, InferenceRequest
from google.adk.evaluation.in_memory_eval_sets_manager import InMemoryEvalSetsManager
from google.adk.evaluation.local_eval_service import LocalEvalService
from google.adk.models.base_llm import BaseLlm
from google.adk.models.llm_response import LlmResponse
from google.adk.models.registry import LLMRegistry
from google.adk.tools.environment_simulation import EnvironmentSimulationFactory
from google.adk.tools.environment_simulation.environment_simulation_config import (
EnvironmentSimulationConfig, InjectedError, InjectionConfig, ToolSimulationConfig)
from google.genai import types
logging.disable(logging.CRITICAL)
class FakeAgentModel(BaseLlm):
"""Calls charge_card once, then replies with what the tool returned."""
@classmethod
def supported_models(cls): return [r"^fake-agent$"]
async def generate_content_async(self, llm_request, stream=False):
last = llm_request.contents[-1].parts[0]
if last.function_response:
r = last.function_response.response
text = "FAILED" if "error_code" in r else "OK"
yield LlmResponse(content=types.ModelContent(text))
else:
yield LlmResponse(content=types.ModelContent(
[types.Part.from_function_call(name="charge_card", args={})]))
LLMRegistry.register(FakeAgentModel)
def charge_card() -> dict:
"""Charges the card."""
return {"status": "charged"}
async def run(case_ids, parallelism, num_runs):
plugin = EnvironmentSimulationFactory.create_plugin(EnvironmentSimulationConfig(
tool_simulation_configs=[ToolSimulationConfig(
tool_name="charge_card",
injection_configs=[InjectionConfig(
injection_probability=0.5, random_seed=42,
injected_error=InjectedError(injected_http_error_code=503,
error_message="unavailable"))])]))
agent = LlmAgent(name="agent", model="fake-agent", tools=[charge_card])
app = App(name="app", root_agent=agent, plugins=[plugin])
manager = InMemoryEvalSetsManager()
manager.create_eval_set("app", "set")
for cid in case_ids:
manager.add_eval_case("app", "set", ec.EvalCase(eval_id=cid, conversation=[
ec.Invocation(user_content=types.UserContent("Pay my bill."))]))
service = LocalEvalService(root_agent=agent, eval_sets_manager=manager, app=app)
out = {}
async for r in service.perform_inference(InferenceRequest(
app_name="app", eval_set_id="set", eval_case_ids=case_ids,
inference_config=InferenceConfig(parallelism=parallelism, num_runs=num_runs))):
out[(r.eval_case_id, r.repetition_index)] = r.inferences[-1].final_response.parts[0].text
return out
async def main():
for label, ids, par in [
("case_a alone, parallelism=1", ["case_a"], 1),
("case_a alone, parallelism=1 (again)", ["case_a"], 1),
("case_a + case_b, parallelism=1", ["case_a", "case_b"], 1),
("case_b + case_a order, parallelism=1", ["case_b", "case_a"], 1),
("case_a + case_b, parallelism=4", ["case_a", "case_b"], 4),
]:
out = await run(ids, par, num_runs=3)
a = [out[("case_a", i)] for i in range(3)]
print(f"{label}: case_a runs 0..2 -> {a}")
asyncio.run(main())
Additional context: I used Grok Bot to help find the issue and draft this report; I reproduced the bug and checked the output locally.
- 主要言語
- 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 ·