From 3908131105ee34f93478dad4871b718c8ec47037 Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Wed, 29 Apr 2026 21:36:34 +0200 Subject: [PATCH] Fix stale feature flags cache so specialized subagents respect env. --- .../app/agents/new_chat/chat_deepagent.py | 4 ++++ .../app/agents/new_chat/feature_flags.py | 23 ++++++++----------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/surfsense_backend/app/agents/new_chat/chat_deepagent.py b/surfsense_backend/app/agents/new_chat/chat_deepagent.py index bfb94ba2d..1bdeee100 100644 --- a/surfsense_backend/app/agents/new_chat/chat_deepagent.py +++ b/surfsense_backend/app/agents/new_chat/chat_deepagent.py @@ -607,6 +607,10 @@ def _build_compiled_agent_blocking( model=llm, extra_middleware=subagent_extra_middleware, ) + logging.info( + "Specialized subagents registered for task tool: %s", + [s["name"] for s in specialized_subagents], + ) except Exception as exc: # pragma: no cover - defensive logging.warning( "Specialized subagent build failed; running without them: %s", diff --git a/surfsense_backend/app/agents/new_chat/feature_flags.py b/surfsense_backend/app/agents/new_chat/feature_flags.py index 55525abc5..5d770de00 100644 --- a/surfsense_backend/app/agents/new_chat/feature_flags.py +++ b/surfsense_backend/app/agents/new_chat/feature_flags.py @@ -172,24 +172,19 @@ class AgentFeatureFlags: ) -# Module-level cache. Read once at import time so the values are consistent -# across the process lifetime. Use ``reload_for_tests`` to reset in tests. -_FLAGS: AgentFeatureFlags | None = None - - def get_flags() -> AgentFeatureFlags: - """Return the resolved feature-flag state, caching on first call.""" - global _FLAGS - if _FLAGS is None: - _FLAGS = AgentFeatureFlags.from_env() - return _FLAGS + """Return the resolved feature-flag state from the **current** process environment. + + Intentionally **not** cached: ``load_dotenv`` and operator edits to env vars + must affect the next agent build without requiring a full process restart. + Cost is negligible (reads ``os.environ`` once per call). + """ + return AgentFeatureFlags.from_env() def reload_for_tests() -> AgentFeatureFlags: - """Force a fresh read from env. Tests should call this after monkeypatching env.""" - global _FLAGS - _FLAGS = AgentFeatureFlags.from_env() - return _FLAGS + """Compatibility helper for tests; equivalent to :func:`get_flags`.""" + return AgentFeatureFlags.from_env() __all__ = [