Skip to content

The agent that grows with you

fix(agent): a gateway-owned chat -q session keeps main's one-shot toolset and prompt

Teknium1a3bad8d6add
diff --git a/agent/oneshot_footprint.py b/agent/oneshot_footprint.py
index 6857ad442a9..e19fb3e3e32 100644
--- a/agent/oneshot_footprint.py
+++ b/agent/oneshot_footprint.py
@@ -22,7 +22,19 @@ ONESHOT_HIDDEN_TOOLS = frozenset({"skill_manage"})
def is_single_query_session() -> bool:
- """The finite ``-q`` marker, read through the session env so gateway-bound sessions never see it."""
+ """The finite ``-q`` marker, read through the session env so gateway-bound sessions never see it.
+
+ A gateway-owned ``chat -q`` / ``-z`` session never has that env (only the client process set it): its
+ one-shot fact is the frozen launch policy's ``oneshot`` source, a property of the SESSION, not of one
+ admission, so the cached agent's tools[] and system prompt stay byte-stable across its turns."""
+ try:
+ from gateway.session_policy import active_policy
+ except ImportError: # install without the gateway package: no owner-bound session
+ pass
+ else:
+ policy = active_policy()
+ if policy is not None:
+ return policy.source == "oneshot"
try:
from gateway.session_context import get_session_env
except Exception:
diff --git a/tests/agent/test_oneshot_footprint.py b/tests/agent/test_oneshot_footprint.py
index ecc8d16b033..80302a6bd80 100644
--- a/tests/agent/test_oneshot_footprint.py
+++ b/tests/agent/test_oneshot_footprint.py
@@ -63,3 +63,30 @@ def test_oneshot_delegation_budget_charges_total_children_then_refuses(oneshot,
# Interactive sessions are never charged, whatever the count.
monkeypatch.delenv("HERMES_SINGLE_QUERY_SESSION")
assert delegate_tool._oneshot_spawn_budget(parent, 50) is None
+
+
+def test_gateway_owned_oneshot_session_takes_its_footprint_from_the_frozen_policy(tmp_path, monkeypatch):
+ """The gateway daemon never has the client's HERMES_SINGLE_QUERY_SESSION: a `chat -q` session it owns is
+ one-shot by its frozen ``oneshot`` source, so it gets main's in-process -q shape (no skill_manage, no
+ authoring coaching). An interactive session's policy wins over a stray daemon env marker, keeping its
+ tools[] and system prompt (the prompt-cache prefix) unchanged."""
+ from gateway.session_policy import build_policy, policy_scope
+
+ monkeypatch.delenv("HERMES_SINGLE_QUERY_SESSION", raising=False)
+ skills = _skills_dir(tmp_path)
+
+ def shape(source):
+ with policy_scope(build_policy({"source": source, "cwd": str(tmp_path), "model": "m"}, {})):
+ names = {t["function"]["name"] for t in oneshot_footprint.prune_oneshot_tools(_tools("skill_manage", "skill_view"))}
+ prompt = build_skills_system_prompt(available_tools={"skill_view", "skills_list", "skill_manage"},
+ skills_dir_override=skills)
+ return names, prompt
+
+ names, prompt = shape("oneshot")
+ assert names == {"skill_view"}
+ assert prompt.startswith(oneshot_footprint.ONESHOT_SKILLS_LOAD_GUIDANCE) and "offer to save as a skill" not in prompt
+
+ interactive = build_skills_system_prompt(available_tools={"skill_view", "skills_list", "skill_manage"},
+ skills_dir_override=skills)
+ monkeypatch.setenv("HERMES_SINGLE_QUERY_SESSION", "1") # inherited by a daemon a -q client auto-started
+ assert shape("cli") == ({"skill_manage", "skill_view"}, interactive)