From 23f4f26d8d1b0f12bff96aeff821341fff88659e Mon Sep 17 00:00:00 2001 From: Mani Japra Date: Thu, 1 Oct 2026 23:21:57 +0000 Subject: [PATCH] fix(docker): flush config.json to the KSM record on shutdown The background config monitor only uploads config.json back to the KSM record on its 30s interval tick, so stopping the container between ticks dropped any change written since the last tick -- notably the clone_code Commander rotates on each login -- and the next start served a stale config. Perform one final upload via the existing upload_config_to_ksm helper from stop_config_monitor before killing the monitor PID, guarded so it only runs when KSM mode is active and config.json exists and so a failed upload is logged but does not block shutdown. --- docker-entrypoint.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index fddda979d..bc32a1466 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -296,6 +296,15 @@ start_config_monitor() { # Stop config.json monitoring stop_config_monitor() { if [[ -f "${MONITOR_PID_FILE}" ]]; then + # Flush the latest config.json back to the KSM record before killing + # the monitor: the monitor only uploads on its MONITOR_INTERVAL tick, + # so a shutdown between ticks would otherwise lose any change written + # since the last tick (notably the clone_code refreshed on each login). + if [[ -n "${KSM_CONFIG:-}" || -n "${KSM_TOKEN:-}" ]] \ + && [[ -n "${RECORD:-}" ]] && [[ -f "${CONFIG_FILE}" ]]; then + upload_config_to_ksm "${KSM_CONFIG:-}" "${KSM_TOKEN:-}" "${RECORD}" || true + fi + local monitor_pid monitor_pid=$(cat "${MONITOR_PID_FILE}") if kill -0 "${monitor_pid}" 2>/dev/null; then