Files
hermes-agent/gateway/session_readiness.py
Teknium b6bf0183ba refactor(gateway): narrow or log blind excepts; time out eval subprocesses
Code-health ratchet on PR #106742 (BLE001/S110/HX006), no behaviour change:
- narrow per-row JSON skips: hosted_room_attachments.reconcile_room_events
  (ValueError/TypeError/AttributeError/RecursionError), hermes_state_gateway
  routing-entry lookups (ValueError/TypeError/RecursionError)
- approval_context: only the gateway import is optional (ImportError);
  finite_turn_required() is a ContextVar read that cannot fail
- deliberate boundaries keep their behaviour and now log the traceback:
  profile park (exc_info), session-store init (module logger, same
  "gateway.run" name, still WARNING), a2a profile dispatch (local log;
  outbound reply stays redacted), readiness probe and session_search
  profile open (debug), Windows control-pipe thread hand-off (debug; start()
  re-raises), eval harness top level (logger.exception)
- managed_worker.main: traceback goes to the worker's own stderr (the owner
  spawns it with stderr=DEVNULL) via a non-propagating handler, never the
  channel or profile log files; the owner still gets only
  managed_worker_failed
- evals/shared_gateway: timeout=30 on git rev-parse/diff calls

(cherry picked from commit dfc56cdd5ab875bd14b921de71be4a5bc8afc57f)
2026-10-07 10:57:34 -07:00

42 lines
1.9 KiB
Python

"""Profile-bound setup checks without legacy session execution dispatch."""
import asyncio
import logging
from pathlib import Path
from hermes_state_runtime import RuntimeStoreError
logger = logging.getLogger(__name__)
async def readiness(authority, actor, params, *, runtime):
if 'session:create' not in actor.capabilities or actor.profile_id != authority.profile_id:
raise RuntimeStoreError('permission_denied')
allowed = {'profile', 'provider'} if runtime else {'profile'}
if (not isinstance(params, dict) or set(params) - allowed
or any(not isinstance(value, str) for value in params.values())):
raise RuntimeStoreError('invalid_params')
if params.get('profile'):
from fastapi import HTTPException
from hermes_cli.web_server_profiles import _resolve_profile_dir
try:
home = _resolve_profile_dir(params['profile']).resolve()
except HTTPException:
raise RuntimeStoreError('profile_mismatch') from None
if home != Path(authority.profile_id):
raise RuntimeStoreError('profile_mismatch')
def probe():
from gateway.run import _profile_runtime_scope
from hermes_cli.main import _has_any_provider_configured
from hermes_cli.runtime_readiness import check_runtime_readiness
with _profile_runtime_scope(Path(authority.profile_id)):
try:
if runtime:
return check_runtime_readiness(params.get('provider') or None, strict_profile_scope=True)
return {'provider_configured': bool(_has_any_provider_configured(strict_profile_scope=True))}
except Exception as exc: # a readiness probe reports, never raises
logger.debug('readiness probe failed', exc_info=True)
return {'ok': False, 'error': str(exc)}
return await asyncio.to_thread(probe)