Fix stale feature flags cache so specialized subagents respect env.

This commit is contained in:
CREDO23 2026-04-29 21:36:34 +02:00
parent bf9b606a61
commit 3908131105
2 changed files with 13 additions and 14 deletions

View file

@ -607,6 +607,10 @@ def _build_compiled_agent_blocking(
model=llm, model=llm,
extra_middleware=subagent_extra_middleware, 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 except Exception as exc: # pragma: no cover - defensive
logging.warning( logging.warning(
"Specialized subagent build failed; running without them: %s", "Specialized subagent build failed; running without them: %s",

View file

@ -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: def get_flags() -> AgentFeatureFlags:
"""Return the resolved feature-flag state, caching on first call.""" """Return the resolved feature-flag state from the **current** process environment.
global _FLAGS
if _FLAGS is None: Intentionally **not** cached: ``load_dotenv`` and operator edits to env vars
_FLAGS = AgentFeatureFlags.from_env() must affect the next agent build without requiring a full process restart.
return _FLAGS Cost is negligible (reads ``os.environ`` once per call).
"""
return AgentFeatureFlags.from_env()
def reload_for_tests() -> AgentFeatureFlags: def reload_for_tests() -> AgentFeatureFlags:
"""Force a fresh read from env. Tests should call this after monkeypatching env.""" """Compatibility helper for tests; equivalent to :func:`get_flags`."""
global _FLAGS return AgentFeatureFlags.from_env()
_FLAGS = AgentFeatureFlags.from_env()
return _FLAGS
__all__ = [ __all__ = [