fix(settings): stale env vars survived bridge restart, reverting saved changes

_restart_bridge() cleared a hardcoded, manually-maintained list of env
keys before restarting — every setting added since (vibration_compensation,
host_ip, poll_interval, verbose_http_log) was missing from it. The old
process's env var therefore survived into the new process and silently
overrode the freshly written config.ini value, making toggles appear to
revert right after saving.

Fixed at the root: config_loader.CONFIG_ENV_MAPPING is now the single
source of truth for which env keys back which config.ini options, and
_restart_bridge() derives its cleanup list from it. A newly added
setting can't be forgotten here again.
This commit is contained in:
2026-07-07 01:23:01 +02:00
parent b541aafc74
commit d2c92c2deb
2 changed files with 37 additions and 27 deletions

View File

@ -4644,12 +4644,15 @@ class KobraXBridge:
log.info("Restarting bridge...")
# config_loader caches config.ini values in os.environ ("only if not set").
# On restart, environ must be cleaned, otherwise the new process reads
# the old values instead of the modified config.ini.
for _k in ("PRINTER_IP", "MQTT_PORT", "MQTT_USERNAME", "MQTT_PASSWORD",
"MODE_ID", "DEVICE_ID", "DEFAULT_AMS_SLOT", "AUTO_LEVELING",
"CAMERA_ON_PRINT", "WEB_UPLOAD_WARNING", "PRINT_START_DIALOG",
"FILE_READY_DIALOG", "BRIDGE_PRINTER_NAME",
"SPOOLMAN_SERVER", "SPOOLMAN_SYNC_RATE"):
# the old values instead of the modified config.ini. Keys are derived
# from config_loader.CONFIG_ENV_MAPPING (single source of truth) so a
# newly added setting can never be forgotten here again.
try:
import config_loader as _cl
_restart_env_keys = set(_cl.CONFIG_ENV_MAPPING.keys()) | {"FILE_READY_DIALOG"}
except Exception:
_restart_env_keys = ()
for _k in _restart_env_keys:
os.environ.pop(_k, None)
in_docker = os.path.exists("/.dockerenv") or os.environ.get("KX_IN_DOCKER")