fulcro

michaelwhitford 2025-08-02T16:10:39.754259Z

I am not sure what I am doing wrong with fulcro statecharts. I am trying to invoke a future for a long running process. I used the example invocation as a starting point, but it does not seem to be doing what I expect. Details in thread.

michaelwhitford 2025-08-02T16:11:08.764219Z

(state {:id :running/ai
        :initial :ai/idle}
        (state {:id :ai/idle}
          (transition {:id :transisition/ai-idle->ai-processing
                       :event :chat-completion
                       :target :ai/processing}))
        (state {:id :ai/processing}
          (on-entry {:id :entry/ai-processing})
          (invoke {:id :invoke/chat-completion
                   :type :future
                   :src (fn [& args]
                          (tap> {:from :invoke/chat-completion :args args})
                          (Thread/sleep 5000)
                          {:future-result :DONE})})
          (transition {:id :transition/chat-results
                       :event :done.invoke.*
                       :target :ai/idle}
            (script {:id :script/chat-results
                     :expr (fn [env data]
                             (tap> {:from :script/chat-results :env env :data data}))}))))
Fixed code, this is now working.

michaelwhitford 2025-08-02T16:11:55.904559Z

This does not fire the tap from the invoke, or the tap from the from :done.invoke.* transition. It does transition back to the :ai/idle state though.

michaelwhitford 2025-08-02T16:18:24.708119Z

I'm using this to just try to see the data in the flow of states so I can figure out how to get the data from the event into the invocation. I expected all the taps to fire once I sent the :chat-completion event, the transitions seem to work, but the executable content does not seem to execute.

michaelwhitford 2025-08-02T17:08:00.516809Z

I originally tried to just have an invoke on a transition so the state would stay active, but invoke is not allowed on a transition. What I would like to have is the ability to run multiple long-running invocations that take the results and fire an event after they complete. My current setup just blocks while the long running process is happening and events just queue up until it completes. I would like to have multiple futures running while the statechart continues to process other events. I can't find any other examples of using invoke outside the examples provided in the statecharts repo.

tony.kay 2025-08-02T17:33:51.952799Z

first, are you using the latest version. There have been some invocation fixes in the past few versions

michaelwhitford 2025-08-02T17:44:15.734349Z

Yes running v1.2.22

tony.kay 2025-08-02T17:54:20.917509Z

I did some invocation work within the fulcro integration in the statecharts library itself

tony.kay 2025-08-02T17:54:46.939199Z

but it’s all invoking other charts. The “futures” implementation of invocations in the book may be incorrect or out of date? When I wrote what is there I’m sure I tested it

michaelwhitford 2025-08-02T17:56:41.744359Z

Yes that works actually, I'm sorry to give the impression it was your code that was not working. My code is not exactly the same, I meant that I had started with the example and tried to adapt it to my multiple futures setup.

tony.kay 2025-08-02T17:57:17.277859Z

oh

tony.kay 2025-08-02T17:59:22.065029Z

did you remember to install a tap handler?

michaelwhitford 2025-08-02T17:59:49.903309Z

Yes I see taps from other parts of the statechart, this is just one small parallel state

tony.kay 2025-08-02T18:00:12.675239Z

nothing stands out…it looks just like mine

tony.kay 2025-08-02T18:00:20.179459Z

which you say works

Eric Dvorsak 2025-08-02T18:50:59.600969Z

the transition :transisition/ai-idle->ai-processing doesn't have a target

michaelwhitford 2025-08-02T18:53:06.464139Z

Wow. I have been looking at this thing since last night and didn't see it. That fixed it, thank you very much.

👍 1