- Home
- Skills
- Testing & Debugging
- State Machine Design for Firmware Protocols
More screenshots
Works with the AI Agents you already use
State Machine Design for Firmware Protocols
Design and audit firmware state machines that can't deadlock: four named exits for every pending state, earned timeouts, one central fault gate, recovery that reuses init.
$5
State Machine Design for Firmware Protocols
Example session with this skill installed
Review the state machine for our sensor node's OTA update before we ship. Current design: states idle, requested (asked the server for the manifest), downloading (blocks arrive, we ACK each block), verifying (checksum over the image), applying, done. Retries: the block request repeats until the ACK comes back. If the checksum fails we go back to downloading. Recovery after a fault runs a separate recovery-init that resets the radio and the buffer.
- Read your context and instructions
- Compiled the state machine design
Exit-completeness audit, pending states first:
requested — MISSING failure exit: a server reject (no update available, wrong device) is a negative response, and the design has no branch for it; the node waits forever. MISSING timeout: a lost response is indistinguishable from a slow one. Add both: reject → idle with the reason logged; timeout with 2 retries → terminal fail reported to the caller.
downloading — FAIL: "repeat until the ACK comes back" is retry-without-exit. A dead server or a wedged radio hangs the node permanently, and the watchdog becomes the real protocol. Replace with the ACK-timeout recipe: timeout evaluated only while a block is in flight, sent_at stamped per attempt, 3 retries, then clear in-flight and fail upward. Also add the late-ACK rule: an ACK arriving after a retry was sent must match the outstanding block index or be discarded as stale.
verifying — MISSING reset exit: a disconnect or power event mid-verify can leave the image flagged half-valid. Verification must restart from scratch on any interruption, and the valid flag may only be set at the end of one complete pass. Checksum-fail → downloading is a valid failure exit, but it needs a count, or a corrupt image loops forever.
applying — MISSING power-loss story: brown-out mid-apply is the bricking case. Persist intent before applying, keep the previous image bootable until the new one self-checks on first boot, and give the machine a rollback state instead of a hope.
Fault handling — FAIL: the separate recovery-init duplicates boot init (radio and buffer reset) and will drift from it. Delete it; recovery routes through the shared init sequence, then re-enters idle. Move the consecutive-failure counter out of the individual handlers into one gate after the dispatcher, so verifying and applying inherit the same fault policy as downloading.
Verdict: three missing exits, one unbounded retry, one duplicated recovery path — all found on paper, none left for the field to find.
Connects securely to your tools. The creator never sees your data.
About this skill
Most async firmware bugs aren't logic errors — they're missing exits. A state was entered on a promise ("the ACK will come") and has no branch for the promise breaking, so the device hangs until power-cycle. This skill is a design-and-audit protocol for event-driven firmware control flow. Its core is the exit-completeness audit: every pending state must name four exits — success, failure (the response came back negative), timeout (bounded retries, then a terminal exit), and reset — before the design is accepted. Around it: timeout discipline (a timeout is gated on real in-flight work, never free-running against idle; the ACK, not the send return, is what a pending state waits on), a sizing table for timeout/retry budgets by link type, one centralized fault gate after the dispatcher instead of error checks scattered across handlers, guarded transitions whose preconditions are re-checked at the gate, and recovery that routes through the same init sequence as power-on instead of a copy that will drift. You also get a fill-in state audit table template, the ACK-timeout recipe with the guard order that makes it correct, a symptom-to-cause decision table for field failures, an anti-pattern field guide (flag soup, idle timeouts, retry without exit, duplicated recovery, cooldown violations), a complete worked pass on a BLE pairing handshake, edge cases (late ACKs, events during recovery, clock wraparound, power loss mid-transition, nested machines), and a pre-delivery quality gate. Scope is honest: this is for async protocols, retry logic, and pending-state machines in embedded firmware — not crash triage and not protocol semantics.
- It audits the state model and its exits; it does not find crash bugs — fault-register triage is a separate discipline.
- Timeout budgets in the sizing table are starting points from link behavior; safety-critical systems still need timing analysis against their own latency measurements.
- It cannot verify an implementation matches the audited design — that takes code review or testing against the audit table.
- Protocol semantics (which messages should exist) are out of scope; this covers how the machine survives messages failing.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before any payment.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 24 days ago
Permissions
No special permissions declared or detected