@@ -48,6 +48,38 @@ const runSequentialDiscard = <E, R>(
4848 ? effects [ 0 ] !
4949 : Effect . all ( effects , { discard : true } )
5050
51+ const acknowledgedPlan = (
52+ planned : {
53+ readonly next : unknown
54+ readonly commands : ReadonlyArray < unknown >
55+ readonly emittedEvents : ReadonlyArray < unknown >
56+ readonly microsteps : ReadonlyArray < {
57+ readonly next : unknown
58+ readonly event : unknown
59+ readonly transitions ?: ReadonlyArray < unknown >
60+ readonly commands : ReadonlyArray < unknown >
61+ readonly raisedEvents : ReadonlyArray < unknown >
62+ readonly emittedEvents : ReadonlyArray < unknown >
63+ readonly exitPaths : ReadonlyArray < string >
64+ readonly entryPaths : ReadonlyArray < string >
65+ readonly changed : boolean
66+ } >
67+ readonly done : boolean
68+ readonly output : unknown
69+ } ,
70+ snapshot : ( state : unknown ) => unknown
71+ ) : unknown => ( {
72+ next : snapshot ( planned . next ) ,
73+ commands : planned . commands ,
74+ emittedEvents : planned . emittedEvents ,
75+ microsteps : planned . microsteps . map ( ( microstep ) => {
76+ const { transitions : _ , ...evidence } = microstep
77+ return { ...evidence , next : snapshot ( microstep . next ) }
78+ } ) ,
79+ done : planned . done ,
80+ output : planned . output
81+ } )
82+
5183const invokeCapabilityCache = new WeakMap < Machine . Any , boolean > ( )
5284
5385const hasInvokeCapability = ( machine : Machine . Any ) : boolean => {
@@ -98,7 +130,8 @@ const makeChildlessCompiledDrain = (
98130 try {
99131 planned = executionPlan . plan (
100132 configuration ?? executionPlan . fromConfiguration ( Configuration . normalizeConfigurationSync ( machine , current ) ) ,
101- event
133+ event ,
134+ acknowledged
102135 )
103136 } catch ( error ) {
104137 return error instanceof InfiniteTransitionError || error instanceof MachineSchemaDecodeError
@@ -108,7 +141,9 @@ const makeChildlessCompiledDrain = (
108141 configuration = planned . next
109142 context . executionState = configuration
110143 if ( planned . microsteps . length === 0 ) {
111- if ( acknowledged ) context . completeMessage ( { before, plan : planned , after : current } )
144+ if ( acknowledged ) {
145+ context . completeMessage ( { before, plan : acknowledgedPlan ( planned , executionPlan . snapshot ) , after : current } )
146+ }
112147 return loop
113148 }
114149
@@ -129,7 +164,9 @@ const makeChildlessCompiledDrain = (
129164 }
130165 const continueAfterCommit = ( ) : Effect . Effect < Option . Option < any > , any , any > => {
131166 const continued = Effect . suspend ( ( ) => {
132- if ( acknowledged ) context . completeMessage ( { before, plan : planned , after : next } )
167+ if ( acknowledged ) {
168+ context . completeMessage ( { before, plan : acknowledgedPlan ( planned , executionPlan . snapshot ) , after : next } )
169+ }
133170 return planned . done ? Effect . succeed ( Option . some ( planned . output ) ) : loop
134171 } )
135172 return afterCommit === undefined ? continued : afterCommit . pipe ( Effect . andThen ( continued ) )
@@ -217,7 +254,8 @@ const makeInvokingCompiledDrain = (
217254 planned = executionPlan . plan (
218255 configuration ??
219256 executionPlan . fromConfiguration ( Configuration . normalizeConfigurationSync ( machine , current ) ) ,
220- event
257+ event ,
258+ acknowledged
221259 )
222260 } catch ( error ) {
223261 return error instanceof InfiniteTransitionError || error instanceof MachineSchemaDecodeError
@@ -226,7 +264,9 @@ const makeInvokingCompiledDrain = (
226264 }
227265 configuration = planned . next
228266 if ( planned . microsteps . length === 0 ) {
229- if ( acknowledged ) context . completeMessage ( { before, plan : planned , after : current } )
267+ if ( acknowledged ) {
268+ context . completeMessage ( { before, plan : acknowledgedPlan ( planned , executionPlan . snapshot ) , after : current } )
269+ }
230270 return loop
231271 }
232272
@@ -285,7 +325,9 @@ const makeInvokingCompiledDrain = (
285325 }
286326 const continueAfterCommit = ( ) : Effect . Effect < Option . Option < any > , any , any > => {
287327 const continued = Effect . suspend ( ( ) => {
288- if ( acknowledged ) context . completeMessage ( { before, plan : planned , after : next } )
328+ if ( acknowledged ) {
329+ context . completeMessage ( { before, plan : acknowledgedPlan ( planned , executionPlan . snapshot ) , after : next } )
330+ }
289331 return planned . done ? Effect . succeed ( Option . some ( planned . output ) ) : loop
290332 } )
291333 return afterCommit . length === 0
@@ -522,7 +564,17 @@ const makeProcessLogic: <
522564 }
523565 }
524566
525- if ( acknowledged ) completeMessage ( { before, plan : planned , after : current } )
567+ if ( acknowledged ) {
568+ completeMessage ( {
569+ before,
570+ plan : acknowledgedPlan (
571+ planned ,
572+ ( state ) =>
573+ Configuration . snapshotFromConfiguration ( machine , state as Configuration . ActiveConfiguration )
574+ ) ,
575+ after : current
576+ } )
577+ }
526578
527579 if ( terminal === undefined ) {
528580 pendingMessage = yield * pollMessage
@@ -638,7 +690,17 @@ const makeProcessLogic: <
638690 }
639691 }
640692
641- if ( acknowledged ) completeMessage ( { before, plan : planned , after : current } )
693+ if ( acknowledged ) {
694+ completeMessage ( {
695+ before,
696+ plan : acknowledgedPlan (
697+ planned ,
698+ ( state ) =>
699+ Configuration . snapshotFromConfiguration ( machine , state as Configuration . ActiveConfiguration )
700+ ) ,
701+ after : current
702+ } )
703+ }
642704
643705 if ( terminal === undefined ) {
644706 pendingMessage = yield * pollMessage
0 commit comments