Skip to content

The agent that grows with you

fix: expose profile-bound setup readiness on canonical sessions

Teknium971c3c95515e
diff --git a/gateway/session_controls.py b/gateway/session_controls.py
index 557828d2935..aacfd650aab 100644
--- a/gateway/session_controls.py
+++ b/gateway/session_controls.py
@@ -34,6 +34,7 @@ class AuthorityConnection:
handlers = {'session.create': self.create, 'ping': self.ping, 'runtime.describe': self.describe,
'session.list': self.list_sessions, 'session.info': self.info,
'session.mutate': self.mutate,
+ 'setup.status': self.setup_status, 'setup.runtime_check': self.setup_runtime_check,
'session.resume': self.resume, 'prompt.submit': self.submit,
'prompt.receipt': self.receipt, 'prompt.cancel': self.cancel,
'session.interrupt': self.interrupt, 'session.events.since': self.events_since,
@@ -50,6 +51,14 @@ class AuthorityConnection:
return {'jsonrpc': '2.0', 'id': rid, 'error': {
'code': 5001, 'message': 'storage_unavailable', 'data': {'reason': 'storage_unavailable'}}}
+ async def setup_status(self, ref, params):
+ from gateway.session_readiness import readiness
+ return await readiness(self.authority, self.actor, params, runtime=False)
+
+ async def setup_runtime_check(self, ref, params):
+ from gateway.session_readiness import readiness
+ return await readiness(self.authority, self.actor, params, runtime=True)
+
async def create(self, ref, params):
from gateway.session_local import create_local_session, local_session_info
ref = create_local_session(self.authority, self.actor, params)
diff --git a/gateway/session_readiness.py b/gateway/session_readiness.py
new file mode 100644
index 00000000000..8fd40c3291f
--- /dev/null
+++ b/gateway/session_readiness.py
@@ -0,0 +1,37 @@
+"""Profile-bound setup checks without legacy session execution dispatch."""
+import asyncio
+from pathlib import Path
+
+from hermes_state_runtime import RuntimeStoreError
+
+
+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:
+ return {'ok': False, 'error': str(exc)}
+
+ return await asyncio.to_thread(probe)
diff --git a/hermes_cli/runtime_readiness.py b/hermes_cli/runtime_readiness.py
new file mode 100644
index 00000000000..985a0bcf580
--- /dev/null
+++ b/hermes_cli/runtime_readiness.py
@@ -0,0 +1,22 @@
+"""Provider readiness shared by authenticated frontend transports."""
+
+
+def check_runtime_readiness(requested=None, *, strict_profile_scope=False):
+ from hermes_cli.runtime_provider import resolve_runtime_provider
+ from hermes_cli.auth import has_usable_secret
+ from hermes_cli.main import _has_any_provider_configured
+
+ runtime = resolve_runtime_provider(requested=requested)
+ configured = bool(_has_any_provider_configured(strict_profile_scope=strict_profile_scope))
+ provider = runtime.get('provider') or 'provider'
+ source = str(runtime.get('source') or '')
+ result = {'ok': True, 'provider': runtime.get('provider'),
+ 'model': runtime.get('model'), 'source': runtime.get('source')}
+ if not configured and provider == 'bedrock' and source in {'iam-role', 'aws-sdk-default-chain'}:
+ return {**result, 'ok': False, 'error': 'No Hermes provider is configured.'}
+ api_key = runtime.get('api_key')
+ api_key_text = '' if callable(api_key) else str(api_key or '').strip()
+ if not (callable(api_key) or api_key_text in {'aws-sdk', 'no-key-required'}
+ or has_usable_secret(api_key_text) or bool(runtime.get('command'))):
+ return {**result, 'ok': False, 'error': f'No usable credentials found for {provider}.'}
+ return result
diff --git a/tests/gateway/test_normal_runtime_boot.py b/tests/gateway/test_normal_runtime_boot.py
index 2e74407c340..da06028ecb2 100644
--- a/tests/gateway/test_normal_runtime_boot.py
+++ b/tests/gateway/test_normal_runtime_boot.py
@@ -75,6 +75,12 @@ async def handshake(home, descriptor):
assert 'result' in result, result
return result['result']
+ status = await rpc(ws, 'setup.status')
+ assert status['provider_configured'] is True, status
+ readiness = await rpc(ws, 'setup.runtime_check', provider='custom')
+ assert readiness['ok'] is True and readiness['provider'] == 'custom', readiness
+ for method in ('setup.status', 'setup.runtime_check'):
+ await rpc(ws, method, expected_error='profile_mismatch', profile='foreign-profile')
created = await rpc(ws, 'session.create', request_id='ordinary-launch', source='cli')
sid = created['session_id']
assert sid == created['stored_session_id']
diff --git a/tui_gateway/methods_config.py b/tui_gateway/methods_config.py
index b60562e1a87..d57e72ef67e 100644
--- a/tui_gateway/methods_config.py
+++ b/tui_gateway/methods_config.py
@@ -283,30 +283,11 @@ def _(rid, params: dict) -> dict:
error when the model can't be served, so UIs surface onboarding before a doomed prompt.
``profile`` answers for THAT profile's pin and ``.env``; unknown -> ``ok=False``."""
try:
- from hermes_cli.runtime_provider import resolve_runtime_provider
- from hermes_cli.auth import has_usable_secret
- from hermes_cli.main import _has_any_provider_configured
+ from hermes_cli.runtime_readiness import check_runtime_readiness
requested = str(params.get("provider") or "").strip() or None
def probe(profile, scoped):
- runtime = resolve_runtime_provider(requested=requested)
- provider_configured = bool(_has_any_provider_configured(strict_profile_scope=bool(profile)))
- provider = runtime.get("provider") or "provider"
- source = str(runtime.get("source") or "")
-
- def fail(error, src):
- return {"ok": False, "provider": provider, "model": runtime.get("model"),
- "source": src, "error": error, **scoped}
- if (not provider_configured and provider == "bedrock"
- and source in {"iam-role", "aws-sdk-default-chain"}):
- return fail("No Hermes provider is configured.", source)
- api_key = runtime.get("api_key")
- api_key_text = "" if callable(api_key) else str(api_key or "").strip()
- if not (callable(api_key) or api_key_text in {"aws-sdk", "no-key-required"}
- or has_usable_secret(api_key_text) or bool(runtime.get("command"))):
- return fail(f"No usable credentials found for {provider}.", runtime.get("source"))
- return {"ok": True, "provider": runtime.get("provider"), "model": runtime.get("model"),
- "source": runtime.get("source"), **scoped}
+ return {**check_runtime_readiness(requested, strict_profile_scope=bool(profile)), **scoped}
return _readiness_check(rid, params, probe)
except Exception as e:
return _ok(rid, {"ok": False, "error": str(e)})
diff --git a/website/docs/developer-guide/gateway-internals.md b/website/docs/developer-guide/gateway-internals.md
index e7f8f556b7f..d99704ff734 100644
--- a/website/docs/developer-guide/gateway-internals.md
+++ b/website/docs/developer-guide/gateway-internals.md
@@ -8,6 +8,15 @@ description: "How the messaging gateway boots, authorizes users, routes sessions
The messaging gateway is the long-running process that connects Hermes to 20+ external messaging platforms through a unified architecture.
+## Shared authority setup readiness
+
+Authenticated local clients can call `setup.status` and `setup.runtime_check` before
+creating a session. Both require `session:create` and run against the daemon's owned
+profile; a selector for another profile is rejected. Runtime readiness reuses the
+existing provider resolver off the event loop and does not create a legacy session
+runtime. Missing provider credentials remain a failed readiness result, not a bypass
+of onboarding.
+
## Shared authority clarification protocol
When the HTTP/WebSocket surface is bound to a `SessionAuthority`, attached authorized