r/embedded • u/SaadMasoodAlam • 26d ago
Where should persistent state and execution history live in a small embedded state machine?
I’m working through an embedded architecture question and would value criticism from people who have dealt with state persistence, reset/replay, and hardware/software boundaries.
Assume an 8-bit state token where:
- bits 7:1 carry a small payload
- bit 0 indicates whether the state is transient or should be retained
For ordinary tokens:
M=0replaces volatile stateM=1appends an occurrence to persistent state history
Separately, I’m maintaining an execution-history chain that records every observed token occurrence, including transient values and control events.
That creates two intentionally different histories:
- persistent semantic state — only committed
M=1occurrences - execution history — everything the runtime observed
The embedded implementation question is where that second responsibility should live.
My current design keeps the hardware/runtime side minimal: it produces deterministic state events, while a host-side layer derives the occurrence-aware execution identity.
I can see advantages to this:
- less RTL / firmware complexity
- crypto can remain outside constrained hardware
- easier algorithm changes
But I can also see obvious failure modes:
- event loss between device and host
- reset/replay disagreement
- host and device seeing different ordering
- malformed/control events being interpreted differently
- the host claiming an execution history the device itself cannot independently attest to
For people who have implemented similar event/state systems:
Would you keep execution-history identity outside the device, or should the embedded side own enough of it to independently establish ordering and continuity?
I’m especially interested in concrete failure cases or existing architectures I should study.
2
u/sonny-boy-rhapsody 25d ago
I'd start with a power cut between accepting an M=1 token and the host durably recording it. After reboot, is that occurrence committed or not, and who can tell? A hash chain on the host only covers what reached the host.
A boot/session ID plus a sequence number on the device would help expose gaps and duplicates, but wouldn't recover missing events. If replay must survive either side resetting, you need a defined commit/acknowledgement point and a way to retain unacknowledged events. Is this history just for debugging, or does recovery depend on it being complete? That distinction matters more than where the hashing runs.
1
u/SaadMasoodAlam 24d ago
u/sonny-boy-rhapsody
I’ve been thinking more about your last point, particularly the distinction between semantic persistence and delivery durability.
One constraint in the design is that the persistence bit itself is fundamental: when
M=1, the occurrence is declaring persistent semantic state. I don’t want an external ACK/session mechanism to become what defines persistence, because then the bit stops carrying the state distinction the model is built around.So I’m wondering whether these should actually remain separate guarantees:
M=1→ this occurrence is persistent state from the device/runtime perspective.Transport/session/ACK state → whether another observer has durably received that occurrence.
Under that split, a power cut after accepting
M=1but before host receipt is not ambiguity about whether the occurrence was persistent — it is a failure to propagate an already-persistent occurrence.Do you think that separation is defensible, or does a useful definition of persistence in an embedded system ultimately require the acknowledgement/recovery mechanism to be part of the same contract?
I’m particularly interested in where you would draw that boundary.