Repository navigation
Description
Follow-up to #56, which was auto-closed when #73 was squash-merged (the squash message concatenated the original commit body, which still contained Fixes #56, even though the PR description had been changed to "Partially addresses"). #73 fixed the direct-call path; this issue tracks the remaining wrapper path.
Problem
{{sequence('INV')}} is documented (README, quickstart, multi-tool tutorial, matchers-and-resolvers.md) as producing INV-001, INV-002, ... across calls. Through create_mockable_tool_wrapper, which is how agents reach data-driven mocks, every tool call still produces INV-001.
#73 made the counter dict live for the lifetime of one resolved mock_callable. That is correct when the caller holds onto the callable:
mock = DataDrivenMockFactory("create_invoice")(md)
[mock(amount=1)["id"] for _ in range(3)] # ['INV-001', 'INV-002', 'INV-003']But the wrapper calls registry.resolve() on every tool call, and resolve() has no caching, so DataDrivenMockFactory.__call__ runs per tool call and builds a fresh counter dict each time. Verified on main (94e379d):
# 3 tool calls for create_invoice in one run, same config, via create_mockable_tool_wrapper
['{"id": "INV-001"}', '{"id": "INV-001"}', '{"id": "INV-001"}']
# DataDrivenMockFactory.__call__ was invoked 3 timesCause
There is no run-scoped place to keep the counter. State lives in ResolverContext, which is per-call, or in the resolved callable, which is per-resolve(), and resolve() is per tool call.
Options
None is free; this is why #56 deferred it:
- Counters on the factory instance keyed by run id (
thread_id/scenario_idfrom config). Simple, but leaks across runs that reuse ids, needs eviction, and must be thread-safe since the registry is shared. - Counters stashed in the
scenario_metadatadict, which is the same object across calls within a run. Works without new plumbing, but mutates user-supplied data and depends on LangGraph not copying the nested dict. - Cache the resolved callable in
MockToolsRegistryper run. Changesresolve()semantics and needs the same eviction story as (1). - Episode-scoped state from [RFC] Stateful mocking: episode-scoped world state for multi-turn agent evaluation #53. The right long-term home;
sequence()becomes one consumer of it.
Recommendation: settle the episode/run identity question in #53 first, then implement sequence() on top of it rather than special-casing. If #53 stalls, option 1 keyed on thread_id with a bounded LRU is the least invasive interim.
Acceptance
- Three
create_invoicecalls in one graph invocation viacreate_mockable_tool_wrapperyieldINV-001,INV-002,INV-003. - Two concurrent invocations with different
thread_ids each start at001and do not interfere. - Existing
TestSequenceAcrossCalls(direct path) keeps passing. - The changelog bullet from fix: keep sequence() counters across calls of a data-driven mock #73 ("Through the tool wrapper each call still resolves a fresh callable, so the ids restart there") is removed or updated.
Files
src/stuntdouble/scenario_mocking.pysrc/stuntdouble/mock_registry.pyand/orsrc/stuntdouble/wrapper.pydepending on the optiontests/test_scenario_mocking.py,tests/test_wrapper.py
Filed with AI assistance (Cursor) during a maintainer issue audit.
Maintainer clarification — 2026-10-29
PR #90 (f4db0d5) fixes advancement through repeated wrapper calls but does not yet satisfy run isolation. With one shared registry and two concurrent invocations using different thread_ids, the reproduced results were:
| Invocation | Expected | Actual with #90 |
|---|---|---|
| A | INV-001, INV-002 |
INV-001, INV-003 |
| B | INV-001, INV-002 |
INV-002, INV-004 |
Factory-lifetime counters are therefore not sufficient. Keep this issue open until the wrapper path persists counters within the intended run/episode and isolates independent runs.
Additional acceptance details:
- Use one shared registry in isolation tests; separate registries do not exercise the requirement.
- Preserve the original direct-call
test_each_run_starts_fresh: resolve two callables from the same factory, advance the first, and verify the second begins at001. Do not replace it with a test that creates a second factory. - Define the state identity and lifetime explicitly, including repeated invocations with the same
thread_id, missing identifiers, reset, and cleanup. A conversation/thread identifier is not automatically a unique invocation identifier. - Cover concurrent access and ensure cleanup or eviction cannot reset an active run's counters.
- Coordinate these semantics with [RFC] Stateful mocking: episode-scoped world state for multi-turn agent evaluation #53. This clarification does not approve a specific implementation or change the existing direct-call contract.
Issue clarification assisted by Codex.
Activity
hippi345 commentedon Oct 29, 2026
The tool wrapper resolves mocks on every call and DataDrivenMockFactory.call was making a new sequence counter dict each time, so {{sequence('INV')}} reset to INV-001 on every wrapped call even after #73 fixed the direct path. This keeps the counter state on each registered DataDrivenMockFactory so repeated resolve() calls share it for that tool. Added wrapper tests that check three calls give INV-001 to INV-003 and that separate tools and separate registries keep their own counters, and the existing direct-call tests still pass.
Fixes #81
fix: persist sequence counters for data-driven mocks through wrapper