Skip to content

Fix "MapStates replays stale sub-state on repeated invocations when parent has a cascading state_initializer"#762

Open
hippalectryon-0 wants to merge 1 commit into
apache:mainfrom
hippalectryon-0:issue-mapstates
Open

Fix "MapStates replays stale sub-state on repeated invocations when parent has a cascading state_initializer"#762
hippalectryon-0 wants to merge 1 commit into
apache:mainfrom
hippalectryon-0:issue-mapstates

Conversation

@hippalectryon-0
Copy link
Copy Markdown

@hippalectryon-0 hippalectryon-0 commented May 8, 2026

Fixes #761

Changes

Added sequence ID in the tasks keys

How I tested this

Tested against the MWE of the issue

Checklist

  • PR has an informative and human-readable title (this will be pulled into the release notes)
  • Changes are limited to a single goal (no scope creep)
  • Code passed the pre-commit check & code is left cleaner/nicer than when first encountered.
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future TODOs are captured in comments
  • Project documentation has been updated if adding/changing functionality.

@github-actions github-actions Bot added area/core Application, State, Graph, Actions area/streaming Streaming actions, parallel streams labels May 8, 2026
@hippalectryon-0 hippalectryon-0 marked this pull request as ready for review May 8, 2026 06:29
Copy link
Copy Markdown
Contributor

@skrawcz skrawcz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch and clean fix! The root cause analysis in #761 is thorough and the fix is correct — including sequence_id in the sub-app key ensures repeated invocations with initialize_from get distinct sub-application IDs.

Backwards compatibility is fine here: if old persisted sub-app state exists, initialize_from simply falls back to default_state and the sub-apps run fresh, which is correct.

One ask before merge: please add a regression test in tests/core/test_parallelism.py. The MWE in #761 is a great template — something like:

  • Create a MapStates action with cascade persistence (initialize_from on the parent)
  • Run the parent app through the MapStates action twice (two steps)
  • Assert the second invocation produces fresh results, not a replay of the first

Without an automated test, a future refactor could easily reintroduce this.

@hippalectryon-0
Copy link
Copy Markdown
Author

I checked that the test passes with this PR and fails with the main branch.

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

Labels

area/core Application, State, Graph, Actions area/streaming Streaming actions, parallel streams

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MapStates replays stale sub-state on repeated invocations when parent has a cascading state_initializer

2 participants