Skip to content

The agent that grows with you

fix(review): run TTS warm/release command hooks under the caller's secret scope (#120481)

teknium1a2cdaa73885e
diff --git a/tests/tools/test_tts_lifecycle_leases.py b/tests/tools/test_tts_lifecycle_leases.py
index 86720db1b76..0f6e816b2e4 100644
--- a/tests/tools/test_tts_lifecycle_leases.py
+++ b/tests/tools/test_tts_lifecycle_leases.py
@@ -359,6 +359,40 @@ def test_command_provider_runs_warm_and_release_commands(monkeypatch, timers):
assert ran == [f"curl -s localhost:5002/load?model={quote}", "curl -s localhost:5002/unload"]
+def test_command_hook_thread_resolves_passthrough_under_the_callers_scope(monkeypatch, timers):
+ """The warm/release hook runs on its own thread; under the multiplexer that thread must carry
+ the caller's secret scope or ``resolve_passthrough_value`` fails closed and the hook never
+ runs (#120481)."""
+ from agent import secret_scope as ss
+ from tools.env_passthrough import resolve_passthrough_value
+
+ seen: list = []
+ done = threading.Event()
+
+ def _fake_run(command, timeout, env_passthrough=None):
+ try:
+ seen.extend(resolve_passthrough_value(k, None) for k in env_passthrough)
+ except Exception as exc: # noqa: BLE001 — recorded for the assertion
+ seen.append(exc)
+ finally:
+ done.set()
+
+ monkeypatch.setattr(tts_command_provider, "run_command_provider", _fake_run)
+ cfg = {"provider": "srv", "providers": {"srv": {
+ "command": "srv say {input_path} {output_path}", "warm_command": "curl -s localhost:5002/load",
+ "env_passthrough": ["MY_TTS_TOKEN"]}}}
+ monkeypatch.setattr(tts_tool, "_load_tts_config", lambda: cfg)
+ ss.set_multiplex_active(True)
+ token = ss.set_secret_scope({"MY_TTS_TOKEN": "tok-work"})
+ try:
+ assert tts_tool_lifecycle.acquire_tts_lease("desktop:read-aloud", cfg)["action"] == "warmed"
+ assert done.wait(5)
+ finally:
+ ss.reset_secret_scope(token)
+ ss.set_multiplex_active(False)
+ assert seen == ["tok-work"]
+
+
# --------------------------------------------------------------------------
# Keep-warm window (#118037): the last release schedules the unload on a
# cancellable timer instead of dropping the model inline, so a wake-word loop
diff --git a/tools/tts_tool_lifecycle.py b/tools/tts_tool_lifecycle.py
index 662cc6f8f3e..f84c6626e99 100644
--- a/tools/tts_tool_lifecycle.py
+++ b/tools/tts_tool_lifecycle.py
@@ -75,7 +75,8 @@ def _signal_user_tts_provider(name: str, tts_config: Dict[str, Any], hook: str)
env_passthrough=_command_provider_env_passthrough(cfg))
except Exception as exc: # noqa: BLE001 — best-effort hook
logger.debug("[TTS] %s_command for %s failed: %s", hook, name, exc)
- threading.Thread(target=_run, name=f"tts-{hook}-{name}", daemon=True).start()
+ # ctx_bound: env_passthrough resolves through the caller's profile secret scope.
+ threading.Thread(target=ctx_bound(_run), name=f"tts-{hook}-{name}", daemon=True).start()
return hook
plugin_provider = _lookup_plugin_provider(name)
if plugin_provider is None:
diff --git a/website/docs/user-guide/multi-profile-gateways.md b/website/docs/user-guide/multi-profile-gateways.md
index df72fdd0c49..127ba7bc8f8 100644
--- a/website/docs/user-guide/multi-profile-gateways.md
+++ b/website/docs/user-guide/multi-profile-gateways.md
@@ -663,6 +663,7 @@ profile and never shares with the default or any sibling:
|---|---|---|
| Provider keys, bot tokens, `${VAR}` refs in `config.yaml` | The profile's own `.env` (its secret scope) | Unresolved / no adapter — never the default profile's value |
| Authorization (`GATEWAY_ALLOW_ALL_USERS`, `GATEWAY_ALLOWED_USERS`, per-platform allowlists and allow-all opt-ins) | The owning profile's `.env` and `config.yaml` | Closed — a default-profile opt-in never opens a secondary's bot |
+| Slash-command gating (`allow_admin_from`, `user_allowed_commands`, `group_allow_admin_from`; see [Slash commands](../reference/slash-commands.md)) | The profile whose bot received the message — a secondary's own platform `extra` block governs its bots, not the default profile's | Fail closed: a served profile whose config the multiplexer has not loaded is gated with an **empty** admin list and no user-enabled commands, so only the always-allowed floor (`/help`, `/whoami`) runs — never the default profile's open policy |
| HTTP endpoints (`/p/<profile>/api/...`, `/p/<profile>/webhooks/...`, platform event callbacks) | The named profile's `API_SERVER_KEY`, `profile:`-bound webhook routes, and its own adapter | `401`/`404`; delivery without an adapter is `502`/`503`, never another profile's bot |
| Inbound-port platforms (`/p/<profile>/webhooks/twilio`, `/p/<profile>/line/webhook`, `/p/<profile>/api/messages`, …) | The named profile's own adapter and its secret (Twilio auth token, LINE channel secret, Teams app, BlueBubbles password, …); replies leave through that adapter | `401`/`403` on a wrong secret, `404` when the profile has no such adapter — never the default profile's adapter |
| Adapter settings (`*_REQUIRE_MENTION`, `*_REACTIONS`, `*_ALLOW_BOTS`, `*_PROXY`, Discord `allow_mentions`, Matrix `allowed_users` / `ignore_user_patterns`, webhook host/port/URL, Matrix thread/session/E2EE policy, Discord backfill/attachment caps, Buzz reply mode, A2A agent card / public URL, WhatsApp bridge policy, Yuanbao home channel) | The owning profile, in this order: explicit `.env` value → its `config.yaml` → the adapter's default | The adapter's documented default — never the default profile's setting. Single-profile installs keep env-over-YAML exactly as each platform page documents |