From ace8cc67f29aebd990aa08a314ca02356a3ed45f Mon Sep 17 00:00:00 2001 From: dadachann <185672915+dadachann@users.noreply.github.com> Date: Thu, 30 Jul 2026 14:26:41 +0000 Subject: [PATCH] fix(config): preserve typed list environment overrides --- deploy/prod/docker-compose.yml | 2 +- src/langbot/pkg/core/stages/load_config.py | 11 ++++++++--- tests/unit_tests/core/test_load_config.py | 13 +++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/deploy/prod/docker-compose.yml b/deploy/prod/docker-compose.yml index c003d645f..1adf5f1f2 100644 --- a/deploy/prod/docker-compose.yml +++ b/deploy/prod/docker-compose.yml @@ -55,7 +55,7 @@ services: LANGBOT_CLOUD_MIGRATION_DSN: postgresql://langbot_operator:${POSTGRES_OPERATOR_PASSWORD}@postgres:5432/langbot VDB__USE: pgvector VDB__PGVECTOR__USE_BUSINESS_DATABASE: "true" - VDB__PGVECTOR__ALLOWED_DIMENSIONS: "[384, 512, 768, 1024, 1536]" + VDB__PGVECTOR__ALLOWED_DIMENSIONS: "384,512,768,1024,1536" PLUGIN__ENABLE: "true" PLUGIN__RUNTIME_WS_URL: ws://plugin-runtime:5400/control/ws PLUGIN__DISPLAY_PLUGIN_DEBUG_URL: wss://cloud.langbot.app/plugin/debug/ws diff --git a/src/langbot/pkg/core/stages/load_config.py b/src/langbot/pkg/core/stages/load_config.py index a89cb0b48..49c439758 100644 --- a/src/langbot/pkg/core/stages/load_config.py +++ b/src/langbot/pkg/core/stages/load_config.py @@ -186,9 +186,14 @@ def _apply_env_overrides_to_config(cfg: dict) -> dict: # At the final key if key in current: if isinstance(current[key], list): - # Convert comma-separated string to list - # e.g., SYSTEM__DISABLED_ADAPTERS="aiocqhttp,dingtalk" - current[key] = [item.strip() for item in env_value.split(',') if item.strip()] + # Convert comma-separated values while preserving the + # element type declared by a non-empty config default. + items = [item.strip() for item in env_value.split(',') if item.strip()] + if current[key]: + exemplar = current[key][0] + current[key] = [convert_value(item, exemplar) for item in items] + else: + current[key] = items elif isinstance(current[key], dict): # Skip dict types pass diff --git a/tests/unit_tests/core/test_load_config.py b/tests/unit_tests/core/test_load_config.py index b95bc25ba..defbcee9d 100644 --- a/tests/unit_tests/core/test_load_config.py +++ b/tests/unit_tests/core/test_load_config.py @@ -152,6 +152,19 @@ class TestApplyEnvOverridesToConfig: assert result['system']['disabled_adapters'] == ['aiocqhttp', 'dingtalk', 'telegram'] + def test_override_integer_list_preserves_item_type(self): + """Comma-separated overrides inherit the existing list item type.""" + load_config = get_load_config_module() + + cfg = {'vdb': {'pgvector': {'allowed_dimensions': [384, 512]}}} + env = {'VDB__PGVECTOR__ALLOWED_DIMENSIONS': '384,512,768'} + + with patch.dict(os.environ, env, clear=True): + result = load_config._apply_env_overrides_to_config(cfg) + + assert result['vdb']['pgvector']['allowed_dimensions'] == [384, 512, 768] + assert all(isinstance(item, int) for item in result['vdb']['pgvector']['allowed_dimensions']) + def test_override_list_value_empty_items(self): """Test that empty items in comma-separated list are filtered.""" load_config = get_load_config_module()