Skip to content

The agent that grows with you

fix(tools): uncached check_fn probes classify UnscopedSecretError from the live scope

teknium109a7c297eca0
diff --git a/tests/tools/test_terminal_tool_requirements.py b/tests/tools/test_terminal_tool_requirements.py
index 4817c2cdc08..7022834cce4 100644
--- a/tests/tools/test_terminal_tool_requirements.py
+++ b/tests/tools/test_terminal_tool_requirements.py
@@ -384,24 +384,67 @@ class TestUnscopedSecretReadLogging:
assert verdicts and all(r.exc_info and r.exc_info[0] is RuntimeError for r in verdicts)
def test_expected_fail_closed_probe_is_quiet_but_lost_scope_stays_loud(self, caplog):
+ """The verdict comes from the LIVE scope at the catch site (#110635): unscoped caller →
+ expected boot-time miss (DEBUG, no traceback); scoped caller whose probe still hit the
+ fail-closed path → a dropped scope inside the probe (WARNING + traceback)."""
import logging
+ import threading
import tools.registry as reg
- from agent.secret_scope import get_secret, set_multiplex_active
+ from agent.secret_scope import (
+ get_secret, reset_secret_scope, set_multiplex_active, set_secret_scope,
+ )
def probe():
return bool(get_secret("REGISTRY_LOG_PROBE_TOKEN", ""))
+ def probe_on_bare_thread():
+ # A bare thread starts with an EMPTY context: the scope the caller holds never reaches
+ # the get_secret inside — the spawn-site bug the loud branch exists to expose.
+ out = []
+ t = threading.Thread(target=lambda: out.append(probe()))
+ t.start()
+ t.join()
+ return out[0]
+
set_multiplex_active(True)
try:
with caplog.at_level(logging.DEBUG, logger="tools.registry"):
- assert reg._run_check_fn_uncached(probe, unresolved_scope=True) is False
+ assert reg._run_check_fn_uncached(probe) is False
boot = [r for r in caplog.records if r.name == "tools.registry"]
caplog.clear()
- assert reg._run_check_fn_uncached(probe, unresolved_scope=False) is False
+ token = set_secret_scope({})
+ try:
+ assert reg._run_check_fn_uncached(probe_on_bare_thread) is False
+ finally:
+ reset_secret_scope(token)
lost = [r for r in caplog.records if r.name == "tools.registry"]
finally:
set_multiplex_active(False)
assert boot and all(r.levelno == logging.DEBUG and r.exc_info is None for r in boot)
assert any(r.levelno >= logging.WARNING and r.exc_info for r in lost)
+
+ def test_uncached_probe_at_boot_is_not_reported_as_a_lost_scope(self, caplog):
+ """#110635: a ``no_cache_check_fn`` probe (the browser vault gate) skips the cache-scope
+ lookup, so on the old branch-derived hint every gateway start under multiplexing logged
+ WARNING + traceback for an EXPECTED fail-closed read. Same probe, cached or uncached,
+ same DEBUG verdict."""
+ import logging
+
+ import tools.registry as reg
+ from agent.secret_scope import get_secret, set_multiplex_active
+
+ def probe():
+ return bool(get_secret("REGISTRY_LOG_PROBE_TOKEN", ""))
+
+ reg.no_cache_check_fn(probe)
+ set_multiplex_active(True)
+ try:
+ with caplog.at_level(logging.DEBUG, logger="tools.registry"):
+ assert reg._check_fn_cached(probe) is False
+ finally:
+ set_multiplex_active(False)
+ reg._NO_CACHE_CHECK_FNS.discard(probe)
+ records = [r for r in caplog.records if r.name == "tools.registry"]
+ assert records and all(r.levelno == logging.DEBUG and r.exc_info is None for r in records)
diff --git a/tools/registry.py b/tools/registry.py
index 9aa89f613cf..26257fccc25 100644
--- a/tools/registry.py
+++ b/tools/registry.py
@@ -282,33 +282,34 @@ def check_fn_cache_scope() -> Optional[str]:
return CHECK_FN_CACHE_BYPASS
-def _run_check_fn_uncached(fn: Callable, *, unresolved_scope: bool = False) -> bool:
+def _run_check_fn_uncached(fn: Callable) -> bool:
"""Run an availability check without cache/grace handling."""
- from agent.secret_scope import UnscopedSecretError
+ from agent.secret_scope import UnscopedSecretError, current_secret_scope
try:
return bool(fn())
except UnscopedSecretError:
- if unresolved_scope:
- # Expected fail-closed probe: with multiplexing on, boot-time check_fns run before
- # any profile secret scope exists, so get_secret raises by design. No traceback,
- # so it isn't mistaken for a crashed check_fn.
+ # The verdict comes from the LIVE scope at the catch site, not from which registry branch
+ # ran the probe: ``no_cache_check_fn`` probes skip the cache-scope lookup entirely, so a
+ # branch-derived hint misreported every boot-time uncached probe as a lost scope (#110635).
+ if current_secret_scope() is None:
+ # Expected fail-closed probe: with multiplexing on, boot-time check_fns run before any
+ # profile secret scope exists, so get_secret raises by design. No traceback, so this
+ # cannot be mistaken for a crashed check_fn (#100697).
logger.debug(
- # The tool re-probes on the first scoped turn — log without a traceback so this cannot be
- # mistaken for a crashed check_fn (#100697).
"check_fn %s hit the multiplex fail-closed path with no "
"profile secret scope active; dependent tools re-probe on the first scoped turn",
_fn_label(fn))
else:
- # The scope resolved but the read still failed closed: a genuinely lost scope.
+ # The caller IS scoped but the read still failed closed: the probe dropped the scope on
+ # the way to get_secret (a bare thread/executor hop) — a spawn-site bug, kept loud.
logger.warning(
"check_fn %s raised UnscopedSecretError while the profile cache "
"scope was resolved; dependent tools will be unavailable this turn",
_fn_label(fn), exc_info=True)
except Exception:
- detail = " while profile cache scope was unresolved" if unresolved_scope else ""
logger.warning(
- "check_fn %s raised%s; dependent tools will be unavailable this turn",
- _fn_label(fn), detail, exc_info=True)
+ "check_fn %s raised; dependent tools will be unavailable this turn",
+ _fn_label(fn), exc_info=True)
return False
@@ -319,7 +320,7 @@ def _check_fn_cached(fn: Callable) -> bool:
return _run_check_fn_uncached(fn)
scope = check_fn_cache_scope()
if scope == CHECK_FN_CACHE_BYPASS:
- return _run_check_fn_uncached(fn, unresolved_scope=True)
+ return _run_check_fn_uncached(fn)
cache_key = (fn, scope)
with _check_fn_cache_lock:
_prune_check_fn_caches(now) # leaves only entries within TTL