Skip to content

The agent that grows with you

docs: publish supported local creation policy and recovery boundary

Teknium0400a5efc141
diff --git a/docs/gateway-local-sessions.md b/docs/gateway-local-sessions.md
index a7603a02beb..64dc6af1b05 100644
--- a/docs/gateway-local-sessions.md
+++ b/docs/gateway-local-sessions.md
@@ -1,6 +1,6 @@
# Gateway-owned fresh local sessions
-The composed gateway listener can create a fresh local **CLI-policy** session without
+The composed gateway listener can create fresh local **CLI, TUI, or GUI-policy** sessions without
starting `tui_gateway`'s separate agent runtime. The existing `GatewayRunner` / `TurnRunner`
own execution, approval waiters, tool calls, session storage, and canonical event delivery.
@@ -25,13 +25,23 @@ pending approval alive. A new viewer can resume the same identity and answer thr
## Deliberately limited compatibility
-- Only `source: "cli"` (also the default) is currently accepted. It maps to the existing
- `Platform.LOCAL` → CLI tool/display policy. GUI/TUI policy is **not** inferred from
- process environment or the identity of an attaching viewer. Explicit GUI/TUI/native/
- automation source selections are rejected until their own policy is wired and tested.
-- Creation currently accepts only `request_id` and `source`. Model/provider/reasoning,
- cwd/worktree, toolsets/skills, seeded history, profile switching, YOLO, and other launch
- options return `invalid_params`; none silently modify daemon-wide configuration.
+- `source` accepts `cli` (default), `tui`, or `gui`. These select the existing agent
+ platforms `cli`, `tui`, and `desktop`, respectively. The native local routing identity
+ remains server-owned `Platform.LOCAL`; source never grants messaging/native trust.
+ Default TUI selection folds in `project`; GUI folds in `project` and `desktop_ui`.
+ GUI policy is independent of `HERMES_DESKTOP` and of the attaching viewer's identity.
+- Optional flat creation fields: `cwd` (existing absolute gateway-local directory),
+ `model` (nonempty model identifier on the daemon's configured provider), and `toolsets`
+ (explicit array of established toolset names, including an empty array). Unknown or
+ policy-filtered toolsets reject instead of silently disappearing. Explicit toolsets
+ override the default surface additions; CLI/TUI cannot explicitly request `desktop_ui`.
+ `cwd`, model selection, source and effective toolsets are captured at creation; attach
+ cannot change them. A conflicting repeat `request_id` returns `invalid_params`.
+- Provider/base URL overrides, reasoning/service-tier, skills, cwd worktree creation,
+ seeded history, profile switching, YOLO, and other launch options still return
+ `invalid_params`. Provider credentials/routing and reasoning/service-tier defaults still
+ use the existing gateway resolution lifecycle; this is not full launch-option parity.
+ No supported launch field mutates daemon-wide configuration or process environment.
- Fresh creation currently requires the identity stamped by the existing gated WS ticket
path. The legacy ungated `?token=` path in this base does not stamp identity and cannot
create. The authentication/bootstrap integration must supply the proper server principal;
@@ -61,3 +71,12 @@ reattaches after all viewers close, and verifies the answer reaches the next loo
model request. No native messaging allow-all credential authorizes the execution; a
separate negative control enables messaging allow-all only while proving reconstructed
local source/profile objects still fail closed.
+
+`tests/gateway/test_session_policy.py` adds three simultaneous CLI/TUI/GUI turns against
+an owned loopback model. A barrier holds their first requests concurrently; real terminal
+calls write separate files in three owned working directories. The next requests expose
+the correct cwd results, distinct requested models and surface-specific tool schemas.
+Reconnect preserves each agent; launcher environment carriers and config bytes do not
+change. This is loopback integration evidence, not native launcher or vendor evidence.
+The frozen policy is currently adapter-owned memory; restart integration must persist and
+restore it before execution. A registered local source missing its policy fails closed.
diff --git a/gateway/session_controls.py b/gateway/session_controls.py
index 605da532904..557828d2935 100644
--- a/gateway/session_controls.py
+++ b/gateway/session_controls.py
@@ -69,7 +69,8 @@ class AuthorityConnection:
return {'instance_id': self.authority.instance_id, 'profile_id': self.authority.profile_id,
'authority_epoch': self.authority.epoch,
'capabilities': ['durable-admission-v1', 'event-replay-v1', 'local-cli-create-v1'],
- 'session_create': {'sources': ['cli'], 'parameters': ['request_id', 'source']}}
+ 'session_create': {'sources': ['cli', 'tui', 'gui'],
+ 'parameters': ['request_id', 'source', 'cwd', 'model', 'toolsets']}}
async def info(self, ref, params):
from gateway.session_local import local_session_info
diff --git a/gateway/session_local.py b/gateway/session_local.py
index 8dedd03b2fd..89c1704264f 100644
--- a/gateway/session_local.py
+++ b/gateway/session_local.py
@@ -1,7 +1,6 @@
"""Fresh local routes owned by the authenticated gateway, not by a viewer.
-This initial surface uses CLI policy. Unsupported launch policies fail explicitly
-rather than mutating the daemon environment or pretending to provide GUI parity.
+Source and supported launch settings are frozen per route, never process env.
"""
from __future__ import annotations
diff --git a/gateway/session_policy.py b/gateway/session_policy.py
index ff4bf674811..863a8376ffb 100644
--- a/gateway/session_policy.py
+++ b/gateway/session_policy.py
@@ -75,7 +75,12 @@ def policy_for_source(runner, source):
return None
adapter = runner._adapter_for_source(source)
if isinstance(adapter, LocalSessionAdapter) and adapter.authorize_source(source):
- return adapter.policies.get(source.chat_id)
+ policy = adapter.policies.get(source.chat_id)
+ if policy is None:
+ # Cold recovery must restore the frozen policy before executing, not
+ # reinterpret a LOCAL route as a default CLI launch.
+ raise RuntimeStoreError('storage_unavailable')
+ return policy
return None
diff --git a/tests/gateway/fixtures/session_policy_peer.py b/tests/gateway/fixtures/session_policy_peer.py
index 9ebec9e2a53..e9bbbf07152 100644
--- a/tests/gateway/fixtures/session_policy_peer.py
+++ b/tests/gateway/fixtures/session_policy_peer.py
@@ -82,6 +82,19 @@ async def probe(peer):
assert 'result' in created, created
sid = created['result']['session_id']
sessions.append(sid)
+ from gateway.session_policy import policy_for_source
+ from hermes_state_runtime import RuntimeStoreError
+ live_source = authority.sessions[sid].source
+ adapter = runner._adapter_for_source(live_source)
+ saved_policy = adapter.policies.pop(live_source.chat_id)
+ try:
+ policy_for_source(runner, live_source)
+ except RuntimeStoreError as exc:
+ assert exc.reason == 'storage_unavailable'
+ else:
+ raise AssertionError('missing recovered policy silently selected CLI')
+ finally:
+ adapter.policies[live_source.chat_id] = saved_policy
again = await rpc(ws, 'session.create', **params)
assert again['result']['session_id'] == sid
conflict = await rpc(ws, 'session.create', **{**params, 'model': 'conflict'})