Repository navigation
feat(runtime): /v0/estop software safe-state with actuation latch - #229
Merged
Merged
Conversation
Parse a new top-level `safety:` section, independent of `automation`, so a pure-manual machine can declare a software safe-state. Carries the estop ladder inputs: declared safe-state hooks, per-actuator safe setpoints, and a `zero_is_safe` assertion. Validated unconditionally (device_handle + a function selector required). Factor the hook call-list parsing into a shared parse_call_list helper reused by mode-transition hooks and safety. Part of #219.
Add a first-class software safe-state that works regardless of automation.enabled. SafeStateController owns a thread-safe actuation latch and runs the declared safe-state ladder independent of the mode manager: run declared hooks; else drive per-actuator setpoints (only if they cover every actuating output); else zero all actuating outputs, but only if the profile asserts zero_is_safe; else honestly report no software safe-state. The latch checkpoint lives in CallRouter::execute_call, the single choke point covering HTTP /v0/call, autonomous BT actuation, and hook calls: while latched, actuating calls (fail-closed on unclassified functions, via #218's is_actuating) are refused with 409, except safe-state actions which carry a bypass flag. On an automation machine an e-stop also drives FAULT. Expose POST /v0/estop and POST /v0/estop/clear, and an estop{} block on GET /v0/runtime/status (latched, software_safe_state, latched_at, uncovered actuating functions). Auth is uniform with the rest of /v0. Part of #219.
- CallRouter latch tests: actuating call refused while latched, read-only allowed, safe_state bypasses the latch and IDLE gating. - SafeStateController ladder tests: none/hooks/setpoints-full-coverage/ partial-fail-closed/zero/zero-refuses-non-numeric/clear. - End-to-end estop integration suite: engage -> status latched -> actuating /v0/call 409 -> clear -> call succeeds, against a live runtime + sim. - OpenAPI: /v0/estop, /v0/estop/clear, and the estop block on /v0/runtime/status, with examples and manifest entries. - runtime-config contract fixtures for the safety section (valid + invalid). - Docs: http-api, safety, configuration-schema; CHANGELOG. Part of #219.
- Re-check the actuation latch after acquiring the per-provider lock, closing a TOCTOU window where an in-flight actuating call could land after the safe-state ladder had run (F1). - Narrow the ladder's execution set to explicitly-declared CATEGORY_ACTUATE functions and refuse to "zero" a function with no numeric required argument, so an e-stop never bare-invokes a no-arg command or wipes a CONFIG setting. The CallRouter latch keeps its broader fail-closed is_actuating scope (F2). - Read the latch flag and timestamp together under the mutex so the status snapshot is never torn against a concurrent clear (F4). - Require both selectors to agree in setpoint coverage matching, mirroring CallRouter resolution (F5). - Make the runtime-status estop block optional in the OpenAPI schema, matching its conditional emission (F6). - Document that trigger holds the mutex across the ladder (F3). Part of #219.
runtime.hpp only declares mode_manager_ when automation is enabled, so the set_mode_manager() call in init_http broke the no-automation build. Move it inside the automation guard: without automation there is no mode manager and the e-stop is latch + ladder only. The safe_state HTTP dependency stays wired unconditionally. Part of #219.
Merged
CameronBrooks11
added a commit
that referenced
this pull request
Jul 30, 2026
Ships the safety spine + health-staleness work that has accumulated on main since v0.1.38: - #228 surface FunctionPolicy category over /v0 capabilities (is_actuating) - #229 POST /v0/estop software safe-state + actuation latch - #230 install.sh --variant selection + verify-inert boot-inert - #231 refuse-hookless: veto MANUAL->AUTO without safe-state hooks - #234 cadence-derived device-liveness staleness (D7 phase 1) - #235 per-signal quality/freshness into health, new FAULT state (D7 phase 2) Bumps CMakeLists project VERSION + vcpkg.json, rolls CHANGELOG [Unreleased] into [0.1.39] (adds the missing phase-2 entry), and updates the runtime_version in the runtime-http contract examples.
This was referenced Oct 13, 2026
CameronBrooks11
added a commit
that referenced
this pull request
Oct 15, 2026
The zero rung of the safe-state ladder (`zero_is_safe: true`) built a
call for every required argument of every ACTUATE function, and
`zero_value(BOOL)` returned `false`. A boolean has no safe pole the
runtime can know: `false` disables an enable flag but releases a brake
flag. So rung 3 could release a brake as part of a stop.
`zero_value(BOOL)` now returns `nullopt`, like string and bytes. Rung 3
skips any function it could only call by guessing a boolean, and reports
it in the ladder's actions as not driven (`success: false`, error
"cannot zero required non-numeric argument '<name>'") instead of sending
it. Numeric arguments are zeroed as before. The `zero_is_safe` entry in
docs/configuration-schema.md now says so.
A skipped call never reaches the CallRouter, and `trigger()` logged only
an INFO summary, so the skip was silent. `trigger()` now logs one WARN
per failed or skipped action, as the re-assert path does:
[SafeState] E-stop did not drive <device>/<function>: <reason>
A correction to the issue description: rung 3 has run only
`CATEGORY_ACTUATE` functions since #229 (`actuating_functions_for` in
core/control/safe_state.cpp), so it does not zero PID gains or write
any CONFIG function. `ZeroRungSkipsNonActuateFunctions` already pins
that. The boolean pole was the remaining defect.
Tests (tests/unit/safe_state_test.cpp):
- `ZeroRungNeverSendsBoolArgument` registers an ACTUATE function whose
only required argument is a bool, triggers the e-stop with
`zero_is_safe`, and expects no provider call and one action reported
as not driven. On the unfixed code it fails: the StrictMock records
`call("heater", 1, "set_output", {pwm: bool_value: false})`.
- `TriggerWarnsForEachActionNotDriven` captures the log for the same
e-stop and expects the WARN line above. Before the logging change it
fails: the log holds only "E-stop engaged" and the INFO summary.
All 14 `SafeStateTest` cases pass.
Closes #255
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #219. Builds on #218 (
registry::is_actuating).Problem
A pure-manual deployment had no software safe-state command —
/v0/modereturnsUNAVAILABLEwhen automation is off, and a naïve "run hooks else zero" is unreachable on exactly that machine (mode-transition hooks register only onto the automation-gated mode manager). And a one-shot stop is defeated by the next/v0/call.Change
A first-class software safe-state that works regardless of
automation.enabled, with its own config-driven execution path independent of the mode manager.safety.safe_stateconfig (hooks,setpoints,zero_is_safe), parsed and validated independently ofautomation. Schema + valid/invalid contract fixtures included. Hook call-list parsing is factored into a sharedparse_call_list(reused by mode-transition hooks — behavior/error strings preserved).SafeStateControllerowns a thread-safe actuation latch and runs the locked D4 ladder: declared hooks → per-actuator setpoints (only with full coverage of every actuating output, fail-closed) → zero all actuating outputs (only ifzero_is_safe) → else honestsoftware_safe_state: "none"and latch anyway (never a false zero).CallRouter::execute_call— the single choke point for HTTP/v0/call, autonomous BT actuation, and hook calls. While latched, actuating calls are refused with 409 (fail-closed viais_actuating); read-only calls pass. Asafe_statebypass (never settable from HTTP) lets the ladder itself actuate.POST /v0/estop+POST /v0/estop/clear, and anestop{}block onGET /v0/runtime/status(latched,software_safe_state,latched_at_epoch_ms,uncovered_actuating_functions).clearreleases the latch but does not exit FAULT. Uniform auth. A software stop is not a substitute for the hardware backplane cut.Locked design decisions (maintainer)
Full-coverage-or-fail-closed setpoints; latch-anyway with honest
"none"; uniform auth; FAULT coupling on automation machines. Rung-3 zeroing drives numeric required args to 0 / bool to false and refuses non-numeric (and — post-review — no-arg / non-ACTUATEfunctions).Tests & verification (local)
SafeStateControllerladder (none / hooks / setpoint full-vs-partial coverage / zero / zero-refuses-non-numeric / zero-skips-CONFIG / zero-refuses-no-arg / clear)./v0/call409 → clear → call succeeds.estopstatus block, examples, and runtime-config safety fixtures; live conformance 19/19.Adversarial branch review
An independent reviewer's REVISE findings are all addressed in
fix(estop): …: the TOCTOU re-check under the provider lock (F1), narrowing rung-3 to declared actuators + refusing bare-invoke (F2), consistent latch snapshot (F4), setpoint both-selector agreement (F5), optionalestopin the status schema (F6), and documenting the trigger-holds-mutex trade-off (F3).