From a7f99fc710d9f56e99d1effafcdeb665b32b148e Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 7 May 2026 15:10:53 +0800 Subject: [PATCH] fix: fallback to default DB for LLM config lookup - _get_llm_config now tries module DB and 'default' DB - Adds logging to show which DB is accessed - Prevents empty config when table is in default DB --- harnessed_agent/llm_client.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/harnessed_agent/llm_client.py b/harnessed_agent/llm_client.py index 6692e95..4ddbe8d 100644 --- a/harnessed_agent/llm_client.py +++ b/harnessed_agent/llm_client.py @@ -77,20 +77,29 @@ LLM_PROVIDERS = { async def _get_llm_config() -> Dict[str, Any]: """Get LLM client configuration from harnessed_agent_config table.""" + dbnames_to_try = ['default'] try: env = ServerEnv() - dbname = env.get_module_dbname('harnessed_agent') + module_db = env.get_module_dbname('harnessed_agent') + if module_db not in dbnames_to_try: + dbnames_to_try.insert(0, module_db) except Exception: - dbname = 'default' + pass - try: - async with DBPools().sqlorContext(dbname) as sor: - rows = await sor.R('harnessed_agent_config', {}, - orderby='updated_at DESC', limit=1) - if rows: - return rows[0] - except Exception as e: - error(f"Failed to fetch LLM config: {e}") + for dbname in dbnames_to_try: + try: + async with DBPools().sqlorContext(dbname) as sor: + rows = await sor.R('harnessed_agent_config', {}, + orderby='updated_at DESC', limit=1) + if rows: + info(f"Loaded LLM config from DB '{dbname}'") + return rows[0] + else: + warning(f"No rows in harnessed_agent_config in DB '{dbname}'") + except Exception as e: + error(f"Failed to fetch LLM config from DB '{dbname}': {e}") + + error("LLM config not found in any database") return {}