The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): warn when a resume keeps the stored policy for a reason other than a busy session
unsupportedpastelsc11e653ba82b
diff --git a/gateway/session_policy_refresh.py b/gateway/session_policy_refresh.pyindex 8db265be5cf..fa81700856d 100644--- a/gateway/session_policy_refresh.py+++ b/gateway/session_policy_refresh.py@@ -168,12 +168,15 @@ async def commit_refresh(authority, ref, *, mcp_only=False):async def refresh_resumed_policy(authority, ref):"""Commit the config refresh of an idle local session before it is attached. Never fails the resume:- a busy session, a revoked launch credential or an unreadable profile keeps the stored policy."""+ a busy session, a revoked launch credential or an unreadable profile keeps the stored policy. Only a turn+ running or queued (or admitted during the commit) is expected; anything else is a WARNING."""try:await commit_refresh(authority, ref)except Exception as exc: # health: allow BLE001 -- a refresh is best-effort; the resume itself must proceed- logger.info('Session %s keeps its stored policy on resume: %s', ref.session_id,- getattr(exc, 'reason', None) or type(exc).__name__)+ reason = getattr(exc, 'reason', None) or type(exc).__name__+ busy = reason in {'session_busy', 'unknown_execution', 'revision_conflict'}+ logger.log(logging.INFO if busy else logging.WARNING, 'Session %s keeps its stored policy on resume: %s',+ ref.session_id, reason)def _drop_terminal(authority, ref):diff --git a/tests/gateway/test_session_resume_config_refresh.py b/tests/gateway/test_session_resume_config_refresh.pyindex e53cc9ac3bf..7a5afa3ce0c 100644--- a/tests/gateway/test_session_resume_config_refresh.py+++ b/tests/gateway/test_session_resume_config_refresh.py@@ -557,3 +557,22 @@ async def test_the_next_command_after_a_terminal_refresh_runs_on_the_new_backendfor connection in (owner, later, last):await connection.close()store.close_all_db_handles()+++def test_a_skipped_resume_refresh_warns_unless_the_session_is_busy(monkeypatch, caplog):+ """A turn running or queued is the expected skip; a revoked credential or an unreadable profile leaves a+ silent no-refresh, so it is a WARNING."""+ import logging+ from gateway import session_policy_refresh as refresh+ from hermes_state_runtime import RuntimeStoreError+ for failure in (RuntimeStoreError('session_busy'), RuntimeStoreError('launch_credentials_unavailable'),+ OSError('config.yaml unreadable')):+ async def fail(authority, ref, failure=failure):+ raise failure+ monkeypatch.setattr(refresh, 'commit_refresh', fail)+ with caplog.at_level(logging.INFO, logger=refresh.__name__):+ asyncio.run(refresh.refresh_resumed_policy(None, SimpleNamespace(session_id='s1')))+ levels = [(record.levelno, record.getMessage().rsplit(': ', 1)[1]) for record in caplog.records+ if 'keeps its stored policy' in record.getMessage()]+ assert levels == [(logging.INFO, 'session_busy'), (logging.WARNING, 'launch_credentials_unavailable'),+ (logging.WARNING, 'OSError')], levels