Why is State Final not "final"?

There’s some related discussion here:

The problem is that update() is a kind of content: it doesn’t modify the state directly, but inserts a command to do it into the document. I alluded to this by saying that “update()s are inserted into the document”.

So since your outer update wants to return a dict, it struggles with combining that with the inner update (and even if it could, the inner update command would not be part of the document but somehow embedded in a state, which would mean it can’t act).

A workaround – that probably brings you back to your old problem – would be to move the inner update out, where you’d have to use context get() to access the current state.

The proper workaround would be to combine the two states. Instead of test_state having a dict and counter having a number, combine them into one state, e.g. combined_state with an initial value like (test_state: (..), counter: 0). Then you can still access context get().test_state and don’t need an inner update to modify the counter.