From 9e366fc536377e89e3f085b74562f107c3b9e4f2 Mon Sep 17 00:00:00 2001 From: Nody the lobster Date: Sun, 15 Mar 2026 11:03:40 -0400 Subject: [PATCH] fix: allow env overrides to create missing config keys (#2064) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, environment variable overrides (e.g. SYSTEM__INSTANCE_ID) were silently skipped if the target key didn't already exist in data/config.yaml. This caused SaaS pods running older LangBot images (whose config template lacked system.instance_id) to ignore the SYSTEM__INSTANCE_ID env var, falling back to a random UUID that didn't match the pod UUID — breaking idle timeout tracking. Now env overrides create missing keys (as strings) and missing intermediate dicts, so they work regardless of template version. Co-authored-by: rocksclawbot --- src/langbot/pkg/core/stages/load_config.py | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/langbot/pkg/core/stages/load_config.py b/src/langbot/pkg/core/stages/load_config.py index f8a86200..707b62f6 100644 --- a/src/langbot/pkg/core/stages/load_config.py +++ b/src/langbot/pkg/core/stages/load_config.py @@ -74,20 +74,26 @@ def _apply_env_overrides_to_config(cfg: dict) -> dict: current = cfg for i, key in enumerate(keys): - if not isinstance(current, dict) or key not in current: + if not isinstance(current, dict): break if i == len(keys) - 1: - # At the final key - check if it's a scalar value - if isinstance(current[key], (dict, list)): - # Skip dict and list types - pass + # At the final key + if key in current: + if isinstance(current[key], (dict, list)): + # Skip dict and list types + pass + else: + # Valid scalar value - convert and set it + converted_value = convert_value(env_value, current[key]) + current[key] = converted_value else: - # Valid scalar value - convert and set it - converted_value = convert_value(env_value, current[key]) - current[key] = converted_value + # Key doesn't exist yet - create it as string + current[key] = env_value else: - # Navigate deeper + # Navigate deeper - create intermediate dict if needed + if key not in current: + current[key] = {} current = current[key] return cfg