Skip to content

fix(state): stop logging shutdown read failures as errors - #381

Merged
CameronBrooks11 merged 3 commits into
mainfrom
fix/shutdown-read-noise
Oct 15, 2026
Merged

CameronBrooks11 merged 3 commits into
mainfrom
fix/shutdown-read-noise

Conversation

@CameronBrooks11

Copy link
Copy Markdown
Member

On a stop, systemd's default KillMode=control-group signals the
provider processes together with the runtime. The poll loop's next
reads go to providers that are already exiting, and each one logged
[ERROR] [StateCache] ReadSignals failed for <device>: 4-5 lines on
every clean stop.

StateCache::poll_device now checks
SignalHandler::is_shutdown_requested() when a read fails. Once
shutdown is requested, the failure logs at DEBUG (tagged "during
shutdown") and does not report a device loss to the reachability
sink. The cached snapshot is still invalidated, as for any failed
read. A read failure before shutdown still logs at ERROR and still
reports the loss edge.

The poll loop runs on its own thread, so the check sits where the
failure is seen rather than in the runtime main loop.
signal_handler.cpp moves out of anolis_runtime into a small
anolis_signal library that anolis_state links; anolis_runtime
still gets it through anolis_state.

Tests, in tests/unit/state_cache_test.cpp:

  • StateCacheShutdownTest.ReadFailureAfterShutdownIsNotAnErrorOrALoss:
    an in-band read failure after SIGTERM produces no [ERROR] line and
    no sink event. Before the fix it fails on both assertions: the
    captured log held
    [ERROR] [StateCache] ReadSignals failed for dev1: read failed,
    and the sink fired.
  • StateCacheShutdownTest.ReadFailureBeforeShutdownLogsErrorAndReportsLoss:
    the same failure with no shutdown pending still logs at ERROR and
    fires the sink.

Mutations of the fix, each applied and confirmed by file hash:

  • dropping the shutdown check from the sink condition fails the
    after-shutdown test on its sink assertion only;
  • an extra ERROR log in the shutdown path fails it on its log
    assertion only;
  • shutting_down = false fails it on both;
  • shutting_down = true fails the before-shutdown test and four
    existing reachability tests.

Gate: just test-cpp (481/481 passed), just check-py,
clang-format 18.1.8 --dry-run --Werror and run-clang-tidy over the
tracked C++ sources (no diagnostics), and the integration and
scenario suites against anolis-provider-sim v0.1.6 (73 passed).

Setting KillMode=mixed in the installed unit would also avoid the
race: SIGTERM would then go to the runtime alone, which stops its
providers itself. This change leaves the unit file alone and keeps a
stop clean however the providers are signalled.

Closes #350

On a stop, systemd's default KillMode=control-group signals the
providers along with the runtime, and the poll loop's next reads fail
against providers that are already exiting. Each logged
"[ERROR] [StateCache] ReadSignals failed" on every clean stop.

Once SignalHandler reports a shutdown request, a failed read now logs
at DEBUG and does not report a device loss to the reachability sink.
The cached snapshot is still invalidated. Before shutdown, a failed
read still logs at ERROR and still reports the loss edge.

signal_handler.cpp moves into a small anolis_signal library that
anolis_state links, so the poll loop can read the latch.

Closes #350
@CameronBrooks11 CameronBrooks11 changed the title fix(state): stop logging provider reads at error during shutdown fix(state): stop logging shutdown read failures as errors Oct 15, 2026
@CameronBrooks11
CameronBrooks11 enabled auto-merge (squash) October 15, 2026 23:45
@CameronBrooks11
CameronBrooks11 merged commit 0116e61 into main Oct 15, 2026
26 checks passed
@CameronBrooks11
CameronBrooks11 deleted the fix/shutdown-read-noise branch October 15, 2026 23:59
CameronBrooks11 added a commit that referenced this pull request Oct 16, 2026
Bumps `project(VERSION)` and `vcpkg.json` to 0.1.45 and rolls the
CHANGELOG. Ships, among others:
- `safety.on_startup`, default `safe_state`: the declared safe state
  runs once at every runtime start (#392, closes #362);
- Grafana and InfluxDB bound to loopback under `--with-observability`,
  with `--with-grafana-network` to open Grafana to the LAN (#359,
  closes #351);
- `install.sh` refuses a downgrade unless `--allow-downgrade` (#382,
  closes #366);
- the zero rung no longer sends a guessed boolean (#367), e-stop
  `safe_state_achieved` (#368), dispatchable coverage counts (#369),
  and startup warnings for fault-hook gaps (#370) and disarmed
  watchdogs (#371);
- `health.excluded_signals` (#377), signal unit and description in
  capabilities (#365);
- a half-open probe of an open provider circuit every 60 s, a restart
  that stops the old process first, and a restart clock that starts
  after it stops (#376, #391);
- automation status: `idle` outside AUTO, and `failed` cleared by a
  load or a new AUTO run (#373, #386);
- `install.sh`: provider liveness in the health phase (#355, #383),
  `manifest.json` restored on `--rollback` (#354), Grafana restarted
  on every observability run (#343), the datasource debug lines
  filtered from the journal (#360), and the uninstall prefix guard
  (#342);
- no ERROR lines for reads that fail during shutdown (#381).

The CHANGELOG opens 0.1.45 with upgrade notes: Grafana is on loopback
by default, `safety.on_startup` drives outputs at boot by default, and
downgrades need `--allow-downgrade`. The 0.1.44 note about restarting
grafana-server by hand is not repeated, since #343 restarts it on
every run.

The OpenAPI changes are additive: `SignalSpec.unit` and
`.description`, `EstopResponse.safe_state_achieved`,
`ParameterDefinition.source` and the runtime status
`startup_safe_state`. No provider-protocol change. anolis-workbench
vendors the OpenAPI file and needs a repin to this release.

Every commit in `git log v0.1.44..main` is in the CHANGELOG except
CI, test-only and docs-lint commits (#380, #384, #389).

After merge, tag `v0.1.45`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Runtime stop logs ReadSignals failures at ERROR as providers exit with it

1 participant