Skip to content
laststatePublic

About

Heap-free post-crash diagnostics for embedded firmware. Preserve fault evidence across resets and deliver it after reboot.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

2 watching

Forks

Latest commit

 

History

73 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Latch

Latch pipeline: a hard fault becomes a retained snapshot, survives reboot in a spool, then ships as a LEP envelope.

CI workflow status on prod Code coverage from Codecov Licensed under Apache-2.0 Written in C11 Rust no_std bindings GitHub stars for laststate/latch Contributors to laststate/latch

Latch records the last useful state of an embedded device across reset, then delivers it as a verifiable Latch Envelope Protocol (LEP) v1 envelope when the link is back. The runtime is heap-free C11 with bounded buffers; you provide storage, transport, and reset policy.

Initialize Latch, register storage and a transport, and let ls_boot() finish. The common case then takes three calls:

ls_breadcrumb("sensor:read");
ls_metric_u32("battery_mv", 3264);
ls_capture_message("sensor timeout", LS_SEVERITY_ERROR);

Verified host quickstart — see the pipeline in ~4 minutes, no board. On real hardware, the per-board golden path (ESP32 / STM32 / RP2040 / nRF) is host-verified and CI-green but awaiting physical qualification; new adapters are not hardware-tested. Submit physical evidence: docs/hil-community-validation.md. Only the ESP32 fixture (2026-07-29, older path) is physically qualified today.

See it in 4 minutes without a board (host-first): laststate mock (mock Trace/Relay) + laststate init --target host (build the CLI from github.com/laststate/cli; the npm package is not published yet), or the examples/host demo; then laststate verify for the guided inject->capture->spool->decode->delivered self-test. Integrate in 10 minutes per board: docs/integrate-in-10-minutes.md; ready-made storage/transports/fault/linker via include/laststate/board.h, fault_handler.h, recipes.h, linkers/. Footprint per LS_PROFILE_*: docs/footprint.md. Arduino/PlatformIO one-click: examples/arduino-one-click, examples/platformio-one-click.

Architecture ports capture fault state automatically. On the next boot, ls_boot() promotes the retained snapshot into a transactional spool, and normal runtime calls ls_flush() to deliver it.

Run the host demo

You need CMake 3.20+, Ninja, and a C/C++ compiler. The demo uses the same public in-memory storage, transport, capture, and decoding APIs as an embedded integration.

git clone https://github.com/laststate/latch.git
cd latch
cmake --preset host-debug
cmake --build --preset host-debug
ctest --preset host-debug
cd build/host-debug
./latch-host-example
./latch-dump latch-demo.lst

On Windows, use latch-host-example.exe and latch-dump.exe. latch-dump validates the header and walks every length-checked type-length-value (TLV) record:

Captured 291-byte LEP envelope in latch-demo.lst
LEP v1 type=2 (error) arch=0 (unknown) flags=0x00 sequence=1 event=b63f7832 payload=263
  tlv type=1 (identity) length=71 value_hex=...

See the complete host example for initialization, storage, and transport registration. With an ESP32, follow the first crash tutorial to trigger a real panic, recover the flash-backed event, and store a durable acknowledgement (ACK).

Inspect a LEP vector

latch-dump reads binary files and bounded hexadecimal input with --hex. ASCII whitespace between hexadecimal digits is allowed; odd-length, non-hexadecimal, and oversized inputs fail before envelope validation.

build/host-debug/latch-dump --hex tests/vectors/lep-v1-basic.hex
build/host-debug/latch-dump --json --hex tests/vectors/lep-v1-basic.hex
cat report.lep | build/host-debug/latch-dump --json -

Documented JSON keys and TLV order are stable from the 1.0 line; consumers ignore additional keys. value_hex is lowercase, two characters per byte. Encrypted envelopes appear as validated structural metadata only.

What survives a reset

  • CPU context and fault status on supported Cortex-M, RV32, and Xtensa integrations
  • Reset reason, boot counters, previous uptime, boot-loop and over-the-air (OTA) state
  • Fixed-capacity breadcrumbs, metrics, logs, power, health, and performance samples
  • Selected stack or memory regions with exclude, zero, or hash redaction
  • Firmware identity and a reproducible build ID
  • Retry and ACK state in a CRC-protected persistent spool

The core hides no allocator, scheduler, network stack, or hardware register map. Integrators supply memory, timestamps, reset normalization, storage, and transports.

Add Latch to firmware

  1. Link laststate::latch or the smaller modules you need.
  2. Pass identity and a monotonic timestamp to ls_init().
  3. Register retained or flash-backed storage and one or more transports.
  4. Call ls_boot() early, after the backend needed to recover the previous boot is ready.
  5. Add breadcrumbs and metrics around paths that are expensive to reproduce.
  6. Call ls_flush() from normal runtime when delivery is allowed.
  7. Install the architecture fault/trap integration and qualify it on your board and toolchain.

For a vendored checkout:

add_subdirectory(third_party/latch)
target_link_libraries(firmware PRIVATE laststate::latch)

Or pin a release with CMake FetchContent:

include(FetchContent)
FetchContent_Declare(
  latch
  GIT_REPOSITORY https://github.com/laststate/latch.git
  GIT_TAG v1.0.0-rc.2
)
FetchContent_MakeAvailable(latch)
target_link_libraries(firmware PRIVATE laststate::latch)

Both paths have standalone, CI-tested examples under add-subdirectory and fetch-content. Start with the integration overview, then pick a port or a native integration. Rust firmware uses the #![no_std] SDK.

Compared with UART or flash logs

Failure mode Ordinary logging Latch
Fault occurs while the scheduler or heap is damaged May allocate or depend on a task Bounded, heap-free capture path
Device resets before upload Last lines are often lost Retained snapshot and persistent spool
Link is unavailable during the incident Delivery fails in the fault path Retry after boot through another transport
Firmware changed before reproduction Logs may lack exact identity Build ID travels with the envelope
Captured memory contains secrets Ad hoc filtering Registered regions and explicit redaction policies

Latch is not a hosted observability backend. It produces a portable, verifiable envelope and hands it to infrastructure you control.

Supported targets

The portable runtime splits into core, capture, envelope, spool, storage, transport, metrics, and security libraries; laststate::latch links them all.

Architecture and platform entries include Cortex-M, RV32/RV64, Xtensa/ESP-IDF, Linux signal capture (including AArch64), STM32/RP and Nordic/NXP/Microchip/TI/Silicon Labs reset-port boundaries, FreeRTOS, Zephyr, acknowledged streams, mbedTLS, BLE GATT, CAN/CAN-FD, LoRaWAN, cellular socket offload, and a CryptoAuthLib secure-element adapter. Each entry has an evidence tier in platform support; source-level integration is not board qualification. Check the hardware compatibility matrix before selecting hardware.

Feature switches and buffer sizes live in config.h. Production profiles remove stored strings, disable features, and shrink buffers the firmware does not need.

Status and assurance

The 1.0 portable runtime and wire format are extensively host-tested. One physical configuration, ESP32 with ESP-IDF 5.5.0, was verified on 2026-07-29 for flash, panic, reboot, UART, and durable ACK against the production LastState Relay collector. Relay is private, was not publicly released on that date, and is not a dependency; the ESP32 hardware-in-the-loop (HIL) fixture documents the public framing contract and decoded evidence. The latest tagged pre-release is v1.0.0-rc.2.

Important

Hardware fault entry, linker placement, flash geometry, reset registers, vendor networking, TrustZone boundaries, and secure elements must be qualified on each board and toolchain. Host tests are not hardware certification. Latch claims no independent cryptographic audit or MISRA compliance. Read assurance, production readiness, and the security policy before enabling encryption or dumps in production.

Caution

The power-fail seal (LEP TLV 23, brownout-proof commit) is implemented and host-tested, but has no physical brownout-HIL evidence yet. Treat it as experimental and check known limitations.

For production and autonomous underwater vehicle (AUV) deployments, enable LS_COMMERCIAL_PROFILE=ON. The runtime then fails closed unless an externally audited crypto provider is installed and passes provider known-answer tests; the built-in backend reports builtin-unqualified. See crypto assurance and mutation assurance.

Documentation

Start with production readiness, commercial AUV integration readiness, and the AUV observability runtime guide for safety- or mission-critical work.

Contributing

Start with a good first issue. Integration reports, documentation fixes, test vectors, board evidence, and small tooling improvements are welcome.

Read CONTRIBUTING.md, CODE_OF_CONDUCT.md, and the tool-neutral agent guide. Ask integration questions in GitHub Discussions; report vulnerabilities privately through SECURITY.md. The maintainer target is to acknowledge issues and pull requests within 72 hours. That is a target, not an SLA.

Build and package

The host demo above covers the default CMake build and tests. For Rust bindings and a compact source distribution:

cargo check --manifest-path rust/latch/Cargo.toml
python tools/minify_sources.py --output ../latch-production --verify

Release automation validates the compact distribution and generates archives, checksums, an SPDX software bill of materials (SBOM), and build provenance. Registry publication remains a separate maintainer action in the release procedure.

License

Apache-2.0. See LICENSE.

About

Heap-free post-crash diagnostics for embedded firmware. Preserve fault evidence across resets and deliver it after reboot.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages