8 Commits

Author SHA1 Message Date
Teknium
dbde5a991a fix(kanban): the owner refuses a worker that dials into a restart wait opened after discovery
connect_gateway's restart-wait refusal read the state discovery returned. A restart that began
between discovery and the WebSocket dial still admitted the Kanban worker on its interactive
ticket into the after-turn wait, where each prompt.receipt answer refreshed its silence budget
and held `hermes update` until the forced-restart deadline.

The policy now rides the ticket: inside outside_restart_wait() the session-ticket request carries
`restart_wait: "refuse"`, the ticket store records it on the grant, and GatewayRuntimeAPI decides
admission from the grant at redeem time, so the owner closes the socket (1013) whenever its
restart wait is open by the time the worker connects. Interactive clients still attach (#139041).
An owner older than the client refuses the unknown parameter; the client re-mints without it and
keeps the pre-dial check rather than stranding the worker until that owner restarts.
2026-10-28 20:40:14 -07:00
Teknium
aa00b801b9 fix(profiles): rename and delete a served profile over a dedicated native registry grant
A multiplexing gateway refused PATCH/DELETE /api/profiles/<name> under every
native grant, even one minted for that very profile, so the Desktop Profiles
screen could never rename or delete a profile while a gateway ran (403
profile_scope_mismatch). Separately, the Desktop's registry route appended the
ambient ?profile= (the sidebar's profile, or "__all__") to a path that already
names its profile, so SOUL reads/writes 403'd for every profile but the
active one, and for all of them in All-profiles scope.

One grant design for both:
- gateway/runtime_bootstrap.py: new `native-profile-registry` purpose
  (capability `profiles:registry`), the twin of `native-profile-create`.
- native_http: that grant redeems only for PATCH/DELETE /api/profiles/<name>,
  only for the profile it was minted for, never deletes or moves the
  gateway's launch home (the default root's presentation-only rename stays
  allowed), and is single-use. An ordinary native-http grant keeps refusing
  both writes; a registry grant authorizes nothing else (401).
- Desktop: nativeGrantPurpose() mints the registry grant for those two
  writes; pathWithProfileScope never adds the ambient profile to an
  /api/profiles/<name>/... path (collection routes still get it).

Refs #134889 (DB-5)
Refs #134889 (DB-6)
Refs #140345
Refs #140346
Refs #140791
Refs #140719
2026-10-18 03:27:52 -07:00
unsupportedpastels
4ef87f4c4c fix(desktop): authorize native profile creation with a dedicated grant 2026-10-13 01:38:59 +00:00
Teknium
2107ea5f90 fix(gateway): an auto-started gateway exits once nothing needs it
Every `hermes chat` / `chat -q` / TUI client that found no gateway for its
home started a detached `gateway run` that nothing ever stopped: ~270-350 MB
each, so throwaway homes (scripts, CI, test suites, five homes in the review)
piled up daemons indefinitely.

A client's own start now launches `gateway run --idle-exit` (hidden flag).
That gateway arms a watcher (gateway/run_idle_exit.py) only when no
supervisor owns it (systemd/launchd/Desktop/external stay excluded, as do
installed services, Desktop's `gateway ensure` start, which keeps its
attached gateway for the app's lifetime, and a hand-run `hermes gateway run`).
It exits after `gateway.unmanaged_idle_exit_seconds` (default 600, 0
disables) when all of these hold on two consecutive checks:
- no live ticketed WebSocket, no unredeemed ticket, no HTTP/WS activity
  inside the window;
- no messaging adapter configured, connected or reconnecting (any profile);
- no runnable cron job, no running cron job, no kanban task in
  scheduled/ready/running/review;
- no queued/started admission, live managed worker, hosted-room task,
  in-flight agent/cron/API work, background process/delegation, active
  heartbeat/loop or pending handoff.
Every probe fails closed (an unreadable source keeps it up). The exit
withdraws admission synchronously and publishes draining with
`drain_reason: idle_exit`, so a client that races it waits for the old
process to go and starts a fresh one transparently.

Live (fresh fake homes, loopback provider, window 6 s): chat -q -> gateway
gone at +8.6 s -> second chat -q ok on a new gateway -> gone again; a client
arriving mid-drain succeeds on a fresh gateway; a configured webhook adapter,
a scheduled cron job, a running kanban task, `unmanaged_idle_exit_seconds: 0`,
a Desktop-style `gateway ensure` start and a hand-run `gateway run` all stay
up (watched 24 s).

Review: https://github.com/NousResearch/hermes-agent/pull/106742#issuecomment-6073624820
(cherry picked from commit 7cdfa2364afb89ac85430d10542cc46cecea0bd4)
2026-10-09 02:10:48 -07:00
Teknium
1b93988e1b fix: an issued interactive ticket keeps its profile scope across sibling selectors
andrexibiza W1 (P0): a multiplexed gateway serving alpha + beta let a ticket minted for alpha
read beta's live sessions. `AuthorityConnection._sibling_for` copied the connection identity,
rewrote profile_id/instance_id to the sibling named by a `profile` param and carried the
operator capability over, so `session.list` / `session.resume` (and the submit/mutate/control
verbs on the same dispatch map) with `profile: 'beta'` answered from beta's authority. No beta
grant was ever presented. Reproduced on r6-base against a real `hermes gateway run`
multiplexer: alpha-bound and root-bound tickets both list and resume beta's session.

Root cause: the grant had no notion of profile reach; every ticket was implicitly host-wide.
Fix: the reach is now part of the grant. `TicketStore.mint(scope=...)` stamps `scope` =
'profile' (default) or 'host' (interactive purpose only). The control socket's closed
`session-ticket` params accept an optional `scope`, and run_api carries it into the connection
identity as `profile_scope`. `_sibling_for` routes to a sibling only under a host-scoped grant;
a profile-bound ticket naming any other profile gets `profile_mismatch`, the same answer an
unserved profile gets. No profile_id is rewritten for a profile-bound grant.

Legitimate cross-profile flows are kept, and each one asks for host scope explicitly:
- Desktop shared-primary socket (main routes every local profile onto the one host socket
  with a `profile` param, #118246/#120005): `mintLocalGatewayTicket` and the Python ticket
  bridge request `scope: 'host'` for the interactive purpose. native-http stays profile-bound;
  its `?profile=` reads already mint for the routed home.
- The dashboard `/api/ws` sidecar (already behind the dashboard gate, operator=True, REST
  `?profile=` host-wide) is stamped host scope.
- The CLI, Ink TUI, ACP, cron, Kanban, bot relay, A2A and worker store only ever select their
  own profile, so the default profile-bound ticket covers them unchanged (own-profile
  selectors still succeed).

Red/green: tests/gateway/test_ticket_profile_scope.py fails on r6-base (alpha ticket's
session.list profile=beta returns beta-private) and passes after. It covers
list/resume/submit/interrupt/mutate/create for alpha- and root-bound tickets, own-profile
success, unserved profile_mismatch, the host-scoped sibling route, and refusal of host scope
for non-interactive purposes. The Desktop vitest pins the `scope: 'host'` wire field on both
mint paths.

Review: https://github.com/NousResearch/hermes-agent/pull/106742#pullrequestreview-5460639040
2026-10-08 19:08:58 -07:00
Teknium
8b8559bf58 feat(runtime): one session authority per served profile home under multiplex
`initialize_gateway_runtime` raised RuntimeError whenever gateway.multiplex_profiles
was on (R1 in the multiplex parity report): the unified runtime bound exactly one
SessionAuthority/TicketStore to the launch home, so a multiplexing gateway could not
boot at all and every served secondary was a profile_mismatch by construction.

Build one authority per RESERVED home instead: the launch home plus every
`_runtime_profile_homes` entry. Each is constructed under that profile's
`_profile_runtime_scope` against that profile's own state.db handle (the runner's
scope-following handle cache, so the owner still has one writer per store), begins
its own runtime epoch and binds its own cron owner. `gateway/session_authorities.py`
holds the registry keyed by `hermes_home_key(home)`:

- `active()` resolves the authority for the active runtime scope (unscoped code is
  the launch profile's; a scope naming an unserved home gets None, never the launch
  ledger);
- `for_home()` / `authority_for_home()` for callers that already know the routed home;
- `served_profiles()` feeds the instance descriptor (so `identify` and
  gateway_state.json agree) and `profile_ids()` the TicketStore, which now redeems
  a ticket minted for ANY served profile (`profile_id=None`) and returns the grant's
  home for the connection to bind to.

`runner.session_authority` stays the launch profile's authority: a single-profile
gateway is a registry of one and behaves byte-for-byte as before.

LOCAL sessions of a served secondary (CLI/TUI/Desktop attach, cron fires, legacy
adoption) now carry `source.profile`, so `build_session_key` namespaces them
`agent:<name>:local:...`, the SessionStore writes their rows to that profile's
state.db, and their LocalSessionAdapter lives in `_profile_adapters[name]` rather
than shadowing the launch profile's slot (`local_source` / `local_adapter_map`).
`reset_local_session` fences with the OWNING store's epoch (`_local_authority_epochs`).

Before: `python -m gateway.run` with default + 2 secondaries →
  RuntimeError: shared gateway bootstrap does not yet support multiplex profile authorities
After: boots, `identify` lists 3 served_profiles, each home has its own runtime_epoch.
2026-09-11 21:32:51 -07:00
Teknium
75764b2ad0 feat: authenticate native HTTP through private daemon grants 2026-09-08 11:48:42 -07:00
Teknium
5a13562d66 feat: authenticate local runtime tickets with OS peer identity 2026-09-08 11:44:06 -07:00