State Machine

State Machine - Lifecycle States

Definition

State Machine describes the states and state transition rules of devices or tasks (such as OTA, device lifecycle). For example, device states: Inactive → Online → Offline → Disabled; OTA task states: Pending → Downloading → Upgrading → Success/Failure. Used to standardize state transitions and Connection Status management.

Modeling and transition rules

A state machine consists of a set of states, an initial state, transition conditions, and actions. Transition conditions can be based on events (such as device online, OTA completion), timeouts, or external triggers. In the Device Management Platform, Device Lifecycle device lifecycle, OTA tasks, work orders, and others can all be modeled using state machines. During implementation, it is necessary to define interception logic for illegal transitions to avoid state inconsistencies; support state persistence and recovery to facilitate auditing and troubleshooting.

Integration with DMP

The platform drives Connection Status connection status display, OTA task progress tracking, work order flow, etc., through the state machine. State changes can trigger Event Stream event streams, driving alerts, notifications, or downstream system interactions; Audit Log audit logs record the history of state transitions. Visual configuration of state machines can reduce development costs and allow business personnel to define and extend states and transition rules according to processes.

Use Cases

Applicable to full lifecycle management of devices including activation, network joining, upgrades, maintenance, and decommissioning; creation, issuance, execution, and rollback of OTA tasks; creation, assignment, processing, and closure of work orders. Standardized state machines can improve system predictability, facilitate dashboard monitoring, SLA statistics, and operation automation.

The state set, and blocking a transition that is not allowed

A state machine first lists the states that are allowed to exist, then lists, for each state, which event may move it to which next state. Device lifecycle, upgrade tasks, and work orders each have their own set. They cannot share one bin called "in progress." A value that is not in the set should be refused on write. An upgrade task, for example, cannot go from "waiting for download" straight to "confirmed." The evidence of write and start is missing in between. The block has to happen at write time, not only by hiding a button on the screen. If the API can still write the value, the screen restriction has no force.

Every transition should record the source state, the target state, the triggering event, and the operator or system component. An update with no source state means someone overwrote the value. It was not a transition. A terminal state, such as scrapped, confirmed, or closed, accepts no further business transition by default. Reopening needs its own reopen event and a new phase. Do not quietly change a terminal state back to in progress and overwrite the duration statistics.

A timeout transition needs a persisted clock

A state that moves automatically on timeout is usable only when the deadline is already written to durable storage and a single timer owns the expiry event. If the deadline lives only in one process's memory, a restart forgets that it was still waiting, and the task sits in an intermediate state forever. Or the restart starts the clock again and extends a task that has already waited a long time by another period. When several instances scan at once, the same task must be moved by only one instance, or it will emit two rollbacks or two closes.

Use the platform's common time base, and store the expiry instant rather than a relative phrase such as "wait another ten minutes." A relative phrase is added again on every retry. A timeout caused by a device being offline should be distinguishable from a timeout caused by the platform itself being down. Tasks must not all be judged failed during the outage. After recovery, catch up from the stored expiry instant. Do not start the count again from the recovery instant. This matters especially for an observation period tied to rollback. Resetting the observation period makes an unconfirmed new version look stable too early.

An external system writing status back and bypassing the state machine

When connecting a work-order or asset system, a common pattern is that the other side calls back a status field and the platform overwrites the local value directly. If the other side uses a different vocabulary, the overwrite creates a state that does not exist locally, and later transitions all fail to match. A callback should be translated into a local event first, then handed to the state machine to decide whether the move is allowed. A callback that cannot be translated goes to a pending queue. It is not written into the primary state.

Initial data bypasses the machine just as easily. A bulk import that marks historical devices online directly skips the credential check that an inactive device should have had. Import may place a record only into a state that is explicitly allowed as a starting point. Every other state has to be filled in by events. Concurrent clicks collide as well. Two people close and reassign at the same time, and the request that writes last, if it does not condition on the source state, opens an order that was already closed. Every transition carries the source state as a condition. If the condition does not match, return a conflict and let the caller refresh before deciding. Do not run a scheduled script that "corrects" an inconsistent state without leaving an event. That erases an illegal path that could otherwise have been traced.

After drawing the allowed entries and exits for each state, run real history through it. Look for jumps that are not on the diagram, and for states that stayed past the allowed time without producing a timeout event. If history does not match the diagram, change the diagram or add the missing events before building the next flow. A simulated clock is for testing timeout transitions. After the test, confirm that production has not been left with a timer that was set forward. Once an external system has stored a state name, do not reuse that old name for a new meaning. Give the new meaning a new name, and keep the old name until migration is finished. Otherwise a string cached on the other side writes the new flow into the old branch.

Related Terms

Return to Device Management Platform terminology