The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(approval): MCP/vault consent declines at once when no user can answer
kshitijk4poor762f419fe837
diff --git a/tests/tools/test_mcp_trust_gating.py b/tests/tools/test_mcp_trust_gating.pyindex 666b6d3b53f..68c1260bce5 100644--- a/tests/tools/test_mcp_trust_gating.py+++ b/tests/tools/test_mcp_trust_gating.py@@ -267,6 +267,32 @@ class TestTrustGateApprovalRouting:assert gateway_waits == []+ @pytest.mark.parametrize("context", ["single_query", "cron", "webhook"])+ def test_cli_panel_callback_is_never_asked_without_a_user(self, monkeypatch, context):+ """`hermes chat -q`, cron and unattended platforms can keep the CLI panel callback registered, but+ nobody answers it: consent declines at once instead of waiting the approval timeout (the e2e+ hang after ef1faa4cf8)."""+ from gateway.session_context import clear_session_vars, set_session_vars+ from tools import approval_prompt+ from tools.terminal_tool import set_approval_callback++ if context == "single_query": # cli_single_query exports the marker into the process env+ monkeypatch.setenv("HERMES_SINGLE_QUERY_SESSION", "1")+ tokens = set_session_vars()+ elif context == "cron": # the cron scheduler binds it per job+ tokens = set_session_vars(cron_session="1")+ else: # an unattended platform: no adapter can carry an approval prompt+ tokens = set_session_vars(platform="webhook")+ asked = []+ set_approval_callback(lambda *args, **kwargs: asked.append(args) or "once")+ try:+ assert approval_prompt.request_elicitation_consent("write", "Approve once or deny.") == "decline"+ finally:+ set_approval_callback(None)+ clear_session_vars(tokens)+ assert asked == []++class TestTrustNormalization:def test_unknown_trust_value_treated_as_untrusted(self):"""Garbage trust strings fail closed to untrusted."""diff --git a/tools/approval_prompt.py b/tools/approval_prompt.pyindex b10812dcb1e..0d9484d43fa 100644--- a/tools/approval_prompt.py+++ b/tools/approval_prompt.py@@ -330,6 +330,13 @@ def request_elicitation_consent(message: str, description: str, *,return "cancel" # nobody answered (timeout / prompt withdrawn) — not a user refusalreturn _consent(decision.get("choice"), "decline")+ # Nobody can answer a -q, cron or unattended-platform worker. A `hermes chat -q` turn still has the CLI's+ # panel callback registered, which would wait the full approval timeout before failing closed.+ if (_ctx._is_single_query_approval_context() or _ctx._is_cron_approval_context()+ or _ctx._is_unattended_platform_approval_context()):+ logger.info("Elicitation consent (%s) declined: no user can answer in this session", surface)+ return "decline"+# Same observer payload as the gateway branch (#131876); post fires in a finally so the# wait settles for observers on the early fail-closed return too.hook_kwargs = dict(command=message, description=description, pattern_key="mcp_elicitation",