YongGoose opened a new issue, #1058:
URL: https://github.com/apache/burr/issues/1058
# Current behavior
When a saved app is resumed with `resume_at_next_action=True` and the action
it last completed no longer exists in the graph (for example, it was renamed in
a new version of the code), `build()` succeeds, `get_next_action()` returns
`None`, and `run()` executes nothing. The only output is the generic "the state
machine had nowhere to go" warning, which doesn't mention the saved action.
A long-running app (a chat, or a run waiting for human input) that is
resumed after a deploy that renamed an action just stops, with no error.
## Steps to replicate behavior
```python
from burr.core import ApplicationBuilder, State, action, default
from burr.core.persistence import InMemoryPersister
@action(reads=["count"], writes=["count"])
def count(state: State) -> State:
return state.update(count=state["count"] + 1)
def build(actions, transitions, persister):
return (
ApplicationBuilder()
.with_actions(**actions)
.with_transitions(*transitions)
.initialize_from(
persister,
resume_at_next_action=True,
default_state={"count": 0},
default_entrypoint=next(iter(actions)),
)
.with_state_persister(persister)
.with_identifiers(app_id="app-1")
.build()
)
persister = InMemoryPersister()
# v1 of the code runs two steps
app = build({"count": count}, [("count", "count", default)], persister)
app.step()
app.step()
# v2 renames the action, and the same app is resumed
app = build({"increment": count}, [("increment", "increment", default)],
persister)
print("next action:", app.get_next_action())
print("run() returned:", app.run(halt_after=["increment"]))
```
Output (main, Python 3.12):
```
next action: None
run() returned: (None, None, {'count': 2, '__SEQUENCE_ID': 1,
'__PRIOR_STEP': 'count'})
This is trying to return without having computed a single action -- we'll
end up just returning some Nones. This means that nothing was executed (E.G.
that the state machine had nowhere to go). ...
```
I got the same result with `SQLitePersister` across two processes.
When the last saved step **failed** instead, the same rename makes `build()`
raise `ValueError: Entrypoint: count not found in actions. Please add using
with_actions(count=...)`. That is at least loud, but it reads as a mistake in
the builder call rather than in the saved data.
## Why
For a completed step, `_init_state_from_persister` stores the saved position
as the prior step (`burr/core/application.py`, line 2765).
`Graph.get_next_node` then looks it up in `_adjacency_map`, a
`defaultdict(list)` (`burr/core/graph.py`, line 181). An unknown name gives no
transitions, so there is no next action.
## Expected behavior
`build()` raises a clear error when the saved position is not an action in
the graph, for both completed and failed steps. The error would name the saved
action, the app's actions, and the partition_key/app_id/sequence_id it loaded.
Something like:
```
ValueError: The state loaded for app_id='app-1' (sequence_id=1) was saved
after action 'count', which is not in this application's actions:
['increment']. ...
```
Related: #95 lists "schema versioning patterns and guidance for upgrades" as
an open item, and #67 asks for graph validation. This is a narrower check that
can land on its own. Happy to send a PR if this sounds right.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]