Skip to content

fix: persist sequence counters for data-driven mocks through wrapper - #90

Open
hippi345 wants to merge 4 commits into
intuit:mainfrom
hippi345:bugfix/81-sequence-counter-persist
Open

hippi345 wants to merge 4 commits into
intuit:mainfrom
hippi345:bugfix/81-sequence-counter-persist

Conversation

@hippi345

@hippi345 hippi345 commented Oct 29, 2026 •

Copy link
Copy Markdown

Store sequence counter state on each DataDrivenMockFactory for the lifetime of its registry registration so repeated resolve() calls from create_mockable_tool_wrapper advance {{sequence('X')}} instead of restarting at 001.

Fixes #81

Checklist

🚨 Please review this repository's contribution guidelines.

  • I've read and agree to the project's contribution guidelines.
  • I'm requesting to pull a topic/feature/bugfix branch.
  • I checked that my code additions will pass code linting checks and unit tests.
  • I updated unit and integration tests (if applicable).
  • I added an [Unreleased] changelog entry for a user-visible change, or confirmed the change is exempt.
  • I'm ready to notify the team of this contribution.

Description

What does this change do and why?

Fixes #(issue number)

Thank you!

Store sequence counter state on each DataDrivenMockFactory for the
lifetime of its registry registration so repeated resolve() calls from
create_mockable_tool_wrapper advance {{sequence('X')}} instead of
restarting at 001.

Fixes intuit#81
@Bbenchaya

Copy link
Copy Markdown
Collaborator

Thanks for tackling this! The wrapper regression tests are useful, but the counter needs to be scoped to a run rather than the lifetime of the registered factory.

With one registry and two concurrent invocations using different thread_ids, I reproduced:

The change to test_each_run_starts_fresh also masks a regression: it now creates a separate factory instead of checking that a fresh run on the same factory starts at 001.

Please preserve the original direct-call reset test, add a wrapper test with one shared registry and two different thread_ids, and scope the counters to the run/episode with appropriate concurrency and lifecycle handling. The current tests pass, but they don’t cover isolation between runs.

Restore direct-call coverage for separate thread_ids on one
DataDrivenMockFactory, add resolve-style rebinding and reset_sequences tests.

Co-authored-by: Joel Shearon  <hippi345@users.noreply.github.com>
@hippi345

Copy link
Copy Markdown
Author

Thanks for catching this. Factory-lifetime counters let interleaved thread_ids bleed into each other. Sequence state is now keyed per run on the registered DataDrivenMockFactory (configurable.thread_id + checkpoint_ns, falling back to run_id), with a lock for concurrent runs on one registry, and reset_sequences() clears one run or all of them. test_each_run_starts_fresh now uses two thread_ids on the same factory, so it actually proves run isolation, and new tests cover concurrent runs on a shared registry and counters persisting across resolve() rebinding. Tracked runs are LRU-capped at 1024 keys; let me know if you'd rather have explicit teardown when a thread completes.

@Bbenchaya

Copy link
Copy Markdown
Collaborator

@hippi345 could you please update this branch with the latest main and resolve the conflict in src/stuntdouble/scenario_mocking.py? #95 has now merged.

Please preserve its seeded RNG and fixed-clock changes, and align sequence counters with the stable thread_id / optional invocation_id run identity. checkpoint_ns changes on every tools step and would restart the counters.

Please rerun the tests after resolving the conflict, including a real multi-step graph test confirming INV-001, INV-002, INV-003 across successive tool steps. Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: {{sequence('X')}} still restarts at 001 on every tool call through create_mockable_tool_wrapper (follow-up to #56 / #73)

3 participants