Repository navigation
fix(tools): derive seeded fault injection per eval case run - #8307
Open
Fruiterer333 wants to merge 3 commits into
Open
Fruiterer333 wants to merge 3 commits into
Fruiterer333 wants to merge 3 commits into
Conversation
6 of 9 tasks
Fruiterer333
pushed a commit
to Fruiterer333/adk-python
that referenced
this pull request
Nov 23, 2026
Exercise seeded environment simulation through LocalEvalService with a stateless offline model. Cover case selection, case order, parallelism, same-plugin reruns, multi-turn continuity and repetition diversity. Extend live and non-live context lifecycle coverage, including real task cancellation. Check nested context restoration and child-task isolation. Related: google#8288 Based on: google#8307
Contributor
Author
|
Thanks @paulraj for the regression tests. I merged them into this branch, and they pass locally (1440 tests across evaluation and environment simulation). Without the fix, the case-selection, case-order and plugin-reuse tests fail, as expected. The |
Fruiterer333
marked this pull request as ready for review
November 25, 2026 11:58
8 of 9 tasks
This was referenced Dec 1, 2026
EnvironmentSimulationEngine kept a single state store per engine, so every session served by one plugin, including every eval case and num_runs repetition, shared the same simulated state. Key the store by (app_name, user_id, session_id) so each session starts empty while turns of one session still share their state. Closes google#8040
A seeded InjectionConfig drew from one generator per plugin, so in an eval the draws a case saw depended on which other cases ran, their order and the parallelism. LocalEvalService now runs each eval case run inside a private, task-local eval run context, and the environment simulation engine seeds that run's generators from a SHA-256 key of (seed, app_name, eval_set_id, eval_case_id, repetition_index, tool_name, injection_config_index). Behavior outside an eval is unchanged. Fixes google#8288
Exercise seeded environment simulation through LocalEvalService with a stateless offline model. Cover case selection, case order, parallelism, same-plugin reruns, multi-turn continuity and repetition diversity. Extend live and non-live context lifecycle coverage, including real task cancellation. Check nested context restoration and child-task isolation. Related: google#8288 Based on: google#8307
Fruiterer333
force-pushed
the
fix/env-sim-seeded-injection-per-case
branch
from
December 2, 2026 01:58
fa7d05c to
de988f6
Compare
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
InjectionConfig.random_seedseeded one generator per injection config when the plugin was created, and every session the plugin served drew from it. In an eval, one plugin serves every eval case and everynum_runsrepetition, so whether a case's run got the injected fault depended on how many draws other runs made first: which cases were selected, their order, andparallelism. Same seed, same case, different outcomes (repro in #8288).Solution:
LocalEvalService._perform_inference_single_eval_itemruns inference inside a new private, task-local eval run context (utils/_eval_run_context.py, aContextVar), next to the existingclient_label_context. It carries(app_name, eval_set_id, eval_case_id, repetition_index). Child tasks and every turn of the run see it, and it is reset on exit, including on failure or cancellation. It stays in process: nothing is added to client headers or session state.EnvironmentSimulationEngine._drawuses a generator for that run, seeded from a SHA-256 digest of a JSON encoding of(seed, app_name, eval_set_id, eval_case_id, repetition_index, tool_name, injection_config_index), not Python's process-saltedhash(). The run's generators are kept in aWeakKeyDictionarykeyed by the run context object (identity-hashed), so concurrent runs never share a stream, a later eval invocation with the same plugin starts the case's stream from the beginning, and the generators go away with the run.random_seeddocstring now states the guarantee: within a case run, the same ordered matching calls get the same draws regardless of other cases, order, or parallelism; a run whose agent trajectory changes can still consume different draws. Repetitions of a case get different streams, sonum_runsstill samples different fault patterns.Testing Plan
Unit Tests:
Added focused tests for the core guarantee:
test_seeded_injection_in_eval_run_ignores_other_runs: one engine serving a case alone, again, after another case, and concurrently with other cases gives the case the same draws; other cases and repetitions get their own streams; the engine-wide sequence outside eval is untouched.test_eval_run_seed_is_a_stable_sha256_of_the_run_key: pins the derived seed to a fixed SHA-256 value.test_perform_inference_single_eval_item_sets_eval_run_context(success and failure): inference sees its run's context, and it is reset afterwards.Broader regression coverage (case selection/order, parallelism, repeated evaluation with the same plugin, multi-turn continuity, context cleanup on failure/cancellation) is being added by @paulraj, as discussed in #8288.
Manual End-to-End (E2E) Tests:
The offline script from #8288 (fake model, no API key), with
num_runs=6and an extra check that reuses one plugin for two evals:Before (
main+ #8041):After:
Checklist
Additional context
I used Grok Bot to help find the issue and draft the change; I reproduced the bug and verified the fix and tests locally.