Skip to content

fix: keep SEGV traces, seed variables.cfg keys via SAVE_VARIABLE, re-enable networking at boot - #360

Merged
gmmcosta15 merged 9 commits into
devfrom
fix/shutdown-vars-networking
Oct 21, 2026
Merged

gmmcosta15 merged 9 commits into
devfrom
fix/shutdown-vars-networking

Conversation

@gmmcosta15

@gmmcosta15 gmmcosta15 commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Description

  • Feature
  • Bug Fix
  • Code Refactor
  • Documentation

Three boot and shutdown problems seen on the RF50 boxes. A SEGV on stop left no trace, because the next run emptied the fault log. Repo variables.cfg keys never reached a box, because Klipper rewrites that file from memory. And a box with networking turned off stayed locked out until someone opened the Wi-Fi page. This PR keeps the fault log across runs, seeds missing variables.cfg keys through SAVE_VARIABLE, repairs a variables.cfg that Klipper cannot load (then restarts Klipper so it loads the fix), and turns networking back on at boot.

Changes

  • logger: the fault log is opened in append mode, marks each run with its start time and pid, and stays open through shutdown, so faulthandler can still record a teardown SEGV (a closed fd gets reused)
  • configurator: an existing variables.cfg is left to Klipper; variable_defaults() returns the repo keys that can be sent (skips mmu_*, '%', ';' and non-literals)
  • configurator: _repair_variables runs the same checks as Klipper's save_variables.loadVariables; an unloadable file is backed up and rewritten as one sorted [Variables] section (the later duplicate wins, values Klipper rejects are dropped, an escaped %% is kept), written with atomic_write_text
  • device_configurator: a repair sets boot_changed, so Klipper is restarted (service restart, works from the error state) once Moonraker is up and no job runs
  • BlocksScreen: _seed_variables sends SAVE_VARIABLE once for each repo key missing from printer.save_variables.variables, and sends again after any Klippy state change (a fast restart emits only "ready")
  • network worker: _async_initialize runs _ensure_networking_enabled(), so nmcli networking off is cleared at boot, not only in the Wi-Fi preflight

Motivation

  • SEGV on stop leaves no trace: the "w" open in the next process emptied blocksscreen_fault.log (0 bytes on .151)
  • Klipper's save_variables rewrites the whole file from memory on every save, so keys appended while it runs are lost (save_variables.py)
  • That loader is strict (duplicate keys or sections, a bare '%', non-literal values), and a file it rejects fails Klippy's config, so the printer does not start until the file is fixed by hand
  • The UI has no networking toggle and NM persists the off state, so a box with networking off was locked out until the Wi-Fi page ran

Tests

  • New: tests/widgets/test_seed_variables.py (includes the restart re-seed), tests/util/test_fault_log_unit.py, TestVariableDefaults, TestRepairVariables (escaped '%', failed write keeps the original), TestBootChanged.test_variables_cfg_repaired, networking assert in test_happy_path_full_init

Future work

  • Capture and fix the SEGV itself once the fault log holds a trace
  • Show BlocksScreen logs in Mainsail next to the Klipper logs

@gmmcosta15 gmmcosta15 self-assigned this Oct 21, 2026
@gmmcosta15 gmmcosta15 added the bug Something is broken, or a fix for it label Oct 21, 2026
@gmmcosta15
gmmcosta15 merged commit 17a07b7 into dev Oct 21, 2026
10 checks passed
@gmmcosta15
gmmcosta15 deleted the fix/shutdown-vars-networking branch October 21, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something is broken, or a fix for it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants