Skip to content

fix(config): write only strict JSON configs; add a stored-config check - #323

Merged
georgevigelette merged 1 commit into
nextfrom
fix/config-strict-json
Oct 15, 2026
Merged

georgevigelette merged 1 commit into
nextfrom
fix/config-strict-json

Conversation

@georgevigelette

Copy link
Copy Markdown
Contributor

Console firmware with the strict-config check (console-fw fix/jsmn-strict, CFW-12/CFW-15) stores a user config only when it is a strict JSON object that fits its page, and parses the stored config in jsmn strict mode at boot.

  • MotionConfig.to_wire_bytes raises ValueError, naming the key path, for NaN or infinite values (json.dumps used to write NaN / Infinity, which the console now refuses), and for JSON longer than MOTION_CFG_JSON_MAX_LEN (2019 bytes: the 2036-byte page minus the 16-byte header and the NUL). json.dumps runs with allow_nan=False.
  • strict_json_problem(text) explains why a config text would not pass: NaN / Infinity / -Infinity, out-of-range numbers, malformed JSON, a non-object root, or too long. Python's json.loads accepts NaN and Infinity, so it is not enough on its own.
  • MotionConsole.write_config logs that the console refused the write and kept the stored config when the reply is OW_ERROR.
  • scripts/check_console_config.py reads the raw stored config (read-only) and fails when it is not strict JSON or has no positive TEC_TRIP. Run it on each console, on its current firmware, before updating it to the strict firmware.

Tests: tests/test_motion_config_strict.py (no hardware). Software suite: no new failures.

Bench:

  • strict firmware: the check passes on the stored config, fails (exit 1) on a config without TEC_TRIP, and passes again after restoring it;
  • next firmware (5c0dc46): a config with EE_GAIN NaN was stored (RESP), and the check reported "non-JSON constant NaN" (exit 1); config restored.

Summary

Licensing layer

  • Apache-2.0 extension (3D Slicer, wellness/veterinary module, partner SDK, language binding)
  • AGPL-3.0 core (firmware, sensing/beamforming/reconstruction/signal-processing/calibration algorithms, hardware reference design)
  • Docs / data / tooling only
  • This PR moves a file between the AGPL core and the Apache layer — if checked, this is NOT an ordinary PR: it requires the license-manifest change process (and board approval for anything leaving the core). Link the approval.

Checklist

  • Commits are signed off (DCO): git commit -s
  • New files carry the correct SPDX-License-Identifier for their layer
  • Tests and docs updated
  • No incompatible third-party code introduced
  • CI is green and CODEOWNERS review requested

Notes for reviewers

Console firmware with the strict-config check (console-fw fix/jsmn-strict,
CFW-12/CFW-15) stores a user config only when it is a strict JSON object
that fits its page, and parses the stored config in jsmn strict mode at
boot.

- MotionConfig.to_wire_bytes raises ValueError, naming the key path, for
  NaN or infinite values (json.dumps used to write NaN / Infinity, which the
  console now refuses), and for JSON longer than MOTION_CFG_JSON_MAX_LEN
  (2019 bytes: the 2036-byte page minus the 16-byte header and the NUL).
  json.dumps runs with allow_nan=False.
- strict_json_problem(text) explains why a config text would not pass: NaN /
  Infinity / -Infinity, out-of-range numbers, malformed JSON, a non-object
  root, or too long. Python's json.loads accepts NaN and Infinity, so it is
  not enough on its own.
- MotionConsole.write_config logs that the console refused the write and
  kept the stored config when the reply is OW_ERROR.
- scripts/check_console_config.py reads the raw stored config (read-only)
  and fails when it is not strict JSON or has no positive TEC_TRIP. Run it on
  each console, on its current firmware, before updating it to the strict
  firmware.

Tests: tests/test_motion_config_strict.py (no hardware). Software suite: no
new failures.

Bench:
- strict firmware: the check passes on the stored config, fails (exit 1) on
  a config without TEC_TRIP, and passes again after restoring it;
- next firmware (5c0dc46): a config with EE_GAIN NaN was stored (RESP), and
  the check reported "non-JSON constant NaN" (exit 1); config restored.

Signed-off-by: George Vigelette <george@openwater.cc>
@georgevigelette
georgevigelette merged commit 30f70af into next Oct 15, 2026
2 checks passed
@georgevigelette
georgevigelette deleted the fix/config-strict-json branch October 15, 2026 03:51
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.

1 participant