open-autonomy
open-autonomy copied to clipboard
Agent crashes when a cross_period_persisted_keys is not set.
Is your feature request related to a problem? Please describe. If an FSM App defines a cross_period_persisted_keys but for whatever reason the FSM App has not set it on the first iteration of the "happy path", then the agent crashes upon reaching ResetAndPause. This forces to take "ugly" solutions like the one implemented on this PR: https://github.com/valory-xyz/market-creator/pull/75
This behaviour is especially confusing, because the framework allows this design pattern in the SynchronizedData:
@property
def approved_markets_count(self) -> int:
"""Get the approved_markets_count."""
return cast(int, self.db.get("approved_markets_count", 0))
which (seems to) handles non-initialized variables with a default value,,, but surprisingly it does not handle non-initialized variables when copying the data from period-to-period.
Describe the solution you'd like Should be possible to define a default value for these keys. Three alternatives come to mind (from more preferred to less preferred):
-
When copying the SynchronizedData from period-to-period, if a key is not defined, it should take the default value provided in the SynchronizedData @property. If there is no such default value, then launch the exception.
-
Deprecate this pattern:
return cast(int, self.db.get("approved_markets_count", 0))
It is confusing to have a pattern that handles non-defined values, but then crashes on some other part of the code. -
Somehow define the default values on the AbciApp close to this line:
cross_period_persisted_keys: Set[str] = {
get_name(SynchronizedData.proposed_markets_count),
get_name(SynchronizedData.proposed_markets_data),
get_name(SynchronizedData.approved_markets_count),
} # type: ignore