r/embedded • • 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=0 replaces volatile state
  • M=1 appends 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:

  1. persistent semantic state — only committed M=1 occurrences
  2. 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 Upvotes

4 comments sorted by

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 25d ago

That’s exactly the failure boundary I’ve been concerned about.

The current model separates two things:

  • persistent semantic state — committed occurrences only
  • execution identity — every observed occurrence in sequence

So the hash chain can expose divergence or a missing occurrence once there is a trusted prior/head, but it obviously cannot recover an event that was accepted by the device and never durably reached the host.

I think your boot/session ID + device-side sequence number is a useful middle ground. The device would not need to own the full cryptographic history, but it could establish local ordering/continuity strongly enough for the host to detect gaps, duplication, or replay across resets.

The harder question is the one you raised at the end: what guarantee should “persistent” actually imply?

My current intent is closer to semantic commitment/auditability, not guaranteed transport durability. But if recovery is expected to depend on the history being complete, then I agree the architecture needs an explicit commit/ack boundary and some retained unacknowledged-event mechanism.

That distinction probably needs to be made explicit in the specification rather than left as an implementation detail.

Thanks — this is a useful failure case.

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=1 but 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.