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.
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.lstOn 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).
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.
- 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.
- Link
laststate::latchor the smaller modules you need. - Pass identity and a monotonic timestamp to
ls_init(). - Register retained or flash-backed storage and one or more transports.
- Call
ls_boot()early, after the backend needed to recover the previous boot is ready. - Add breadcrumbs and metrics around paths that are expensive to reproduce.
- Call
ls_flush()from normal runtime when delivery is allowed. - 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.
| 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.
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.
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.
Start with production readiness, commercial AUV integration readiness, and the AUV observability runtime guide for safety- or mission-critical work.
- Core: architecture, concurrency contract, LEP v1 wire format, security and storage, threat model and key rotation
- Integrate: integration overview, ports, platform support, native integrations, registries
- Qualify: HIL qualification, hardware compatibility, footprint, Linux signal capture, implementation status
- Operate: production readiness, LTS policy, release procedure, automation, security audit invitation
- Project: roadmap, changelog, AI-assisted development, reference designs
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.
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 --verifyRelease 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.
Apache-2.0. See LICENSE.