0
Fork 0
mirror of https://github.com/mastra-ai/mastra.git synced 2026-11-17 08:44:46 +00:00

Compare commits

...

11 commits

Author SHA1 Message Date
Arthur Fiorette
c5adb511e8
test(core): force the order in the re-suspended foreach item restart rows
The rows for an item that used the resume and suspended again now run on the shared foreach scenario builder and approval step. The item asks again only after the foreach's first running write has landed, and the write that stores its new request waits until a sibling has ended before it reaches the store, so the crash point is the same in every run: the new request is stored, the sibling's result is not, and the stored run still lists the foreach as active. New rows: a foreach whose items are nested workflows, and a second crash while the item runs with the answer to its new request. Every restart also checks its watch events, the stored run and the run that owns the foreach for running-record metadata.

The progress write's comment now says that the store reads the copied active steps when it writes, on both storage versions.
2026-11-17 01:04:32 -03:00
Arthur Fiorette
309b797346
fix(core): keep a foreach item that used the resume at its new request on a restart
A running foreach record keeps the suspend state from before the resume and checkpoints only finished items, so an item that took the stored resume data and suspended again looked, after a restart, like an item that never got it: the restart handed it the same resume data again, running the approved work a second time and answering the item's new request with the old answer.

Such an item's new suspension (payload, time, metadata, resume labels) is now checkpointed as a progress entry on the running record. A restart restores it and leaves the item suspended at that request. On storage v1 the progress write also stores the run's active steps as they were when the write started: an item ending while the write was in flight removed the foreach from them, so a restart could not reuse the resume data at all, and inside a nested workflow the nested run was then resumed again from its first suspension.
2026-11-17 00:11:08 -03:00
Arthur Fiorette
acea401b78
fix(core): pass a recorded nested resume target on a restart without resume data
The previous commit made the whole restart marker depend on reused resume data, so a resume that named its target but carried no data lost that target on a restart: the nested run was then resumed without a step and every suspended step there continued. A recorded target is now always passed; only the unknown-target marker depends on reused resume data.
2026-11-16 20:23:08 -03:00
Arthur Fiorette
01593d127a
fix(core): keep plain nested restarts on the normal resume path
The branch that leaves a nested run suspended when a restarted resume recorded no target also caught restarts of nested steps that were started normally and never resumed. Those have no resume payload to misapply, but on storage v2 parking them dropped the state the nested run had changed before it suspended. The unknown-target marker is now sent only when the stored record carries a resume payload; a plain restart resumes the nested run as before this PR.

The test for the unknown-target hand-back now also has a sibling that changes the state while the nested run works on its copy, so it fails if the hand-back ignores the parent's stored base.
2026-11-16 20:14:20 -03:00
Arthur Fiorette
b61e55aeb5
fix(core): hand back a parked nested run's unreceived state on a restart without a target
When a restart finds a resumed nested step with no recorded target, it leaves the nested run suspended. The nested run may have changed the state and parked again before the parent stored that suspension. Those changes were never handed back, and the later resume rebases from the nested run's own stored state, so they were lost from the parent. On storage v1 the parent now takes them in at the restart, against the state it last received from the nested run (the startState on its stored record), or whole when the record has none.
2026-11-16 19:42:37 -03:00
Arthur Fiorette
9295312536
refactor(core): trim comments on the foreach restart resume targets
Drops comments that restated the code or repeated the JSDoc of the target types. No code change.
2026-11-16 18:51:01 -03:00
Arthur Fiorette
f8132b8e8e
test(core): table the foreach resume restart cases
The cases now share one scenario builder: each row names its shape, how the resume picks its target, the instance, the crash window and what every restarted item must receive, and every restart asserts that the resume targets never reach results or the stored run. The two sibling-race cases are rows of these tables instead of hand-built stores, and a gate cut restarts from the first write that stored the resumed record with its step active. The durable delegation case scripts its supervisor and sub-agents on the aimock server the direct-tool case already uses.
2026-11-16 18:50:58 -03:00
Arthur Fiorette
41965d2a6c
Merge remote-tracking branch 'origin/main' into arthur/foreach-resume-restart 2026-11-16 17:48:32 -03:00
Arthur Fiorette
23df37d100
fix(core): decide a foreach item's nested resume from its stored record
A foreach item that is a nested workflow decided whether to resume its nested
run from the shared foreach record after its input validation. When a sibling
item suspended in that window, the record read as suspended, the item resumed
its nested run with no label, and every suspended item inside it received the
stored resume data on a restart. The item now uses the record read on entry,
as the rest of executeStep does.
2026-11-14 12:22:43 -03:00
Arthur Fiorette
e63d59f36d
fix(core): read a foreach item's stored record before its input validation
Foreach items share the foreach's record in memory, and a sibling that ends
replaces it with its own result. An item that read the record after its
validation awaits could lose its stored resume data on a restart and read the
sibling's suspend payload instead. executeStep now reads the record once, on
entry.

The durable approval restart tests also assert that the recovered execution
did not fail.
2026-11-14 03:21:33 -03:00
Arthur Fiorette
9a54e57971
fix(core): give a restarted foreach's resume data only to the resumed item
Before, a restart handed the stored payload to every item, so suspended siblings
ran with another item's approval.

The running foreach record now stores which item its resumePayload belongs to
(an index, 'all' for a resume without an index, 'none' otherwise). A restart
copies it through, hands the payload only to that item, and keeps the other
suspended items suspended. Records without a target hand the payload to no item.

A resumed foreach now stores its running record even when the same instance
suspended the run. A resumed nested workflow step, and a foreach whose items are
nested workflows, store what the resume targeted inside the nested run, so a
restart that has to resume the nested run again resumes only that. When that
target is missing (records from earlier versions), the nested run stays
suspended. A resume of a foreach item inside a nested workflow by index now
reaches only that item.
2026-11-14 02:56:01 -03:00
11 changed files with 1596 additions and 84 deletions