Files
hermes-agent/gateway/platforms/api_server_store.py
Teknium 0242097635 fix(runtime): route every session_authority consumer by the routed profile's home
Every consumer of `runner.session_authority` assumed one authority per process. Under
multiplex each of them now resolves the authority for the profile it is acting for
(refusal rows R4, R6, R7, R8 and §4 row 8 of the parity report):

- inbound bot messages (`run_inbound`): the message handler already entered the routed
  profile's scope, so `active_authority(self)` admits into that ledger; a scope naming
  an unserved home is refused, never routed to the launch ledger.
- `session_ingress_context._binding`: the runtime home must have an authority in this
  process (`authority_for_home`) instead of comparing against the single launch DB.
  `/p/<profile>/` webhook and API producers that stamped `source.profile` address that
  served profile explicitly on the HOST listener; the URL prefix is the route.
- webhooks (`webhook_ingress.producer_scope`, `webhook.py`, `webhook_delivery`) admit
  and finalize in the routed profile's authority; retained destinations are read from
  the scoped ledger (or every served ledger for an unscoped reply leg).
- API server: `selected_session_db` returns the requested home's store when this
  runtime serves it; `admit_api_turn`, `/runs/{id}` controls
  (`api_server_authority_runs`), room dispatch and `recover_api_turns` (every ledger)
  follow the `/p/<profile>/` scope set by the prefix middleware.
- native WS clients: `GatewayRuntimeAPI` redeems the ticket against the served set, binds
  the connection to the grant's home authority (`scope['hermes.session_authority']`,
  read by `tui_gateway.ws`) and runs the connection inside that profile's scope.
- native HTTP tickets, dashboard `?profile=` mutations, heartbeat/completion automation,
  legacy auto-resume checks, TurnRunner approval owner / policy scope / frozen-config
  reads all use the scoped or explicit per-home authority.

R11: `_binding` no longer fails EVERY profile's ingress when one served directory is
missing; only the missing profile is refused. The `or 'default'` primary fallback is
gone: an unnamed primary is a profile_mismatch.

Single-profile gateways: the registry holds one authority and every lookup returns it.
2026-09-11 21:33:11 -07:00

15 lines
555 B
Python

"""Runtime-bound API storage selection; borrowed stores are never adapter-owned."""
from pathlib import Path
def selected_session_db(adapter, home):
from gateway.session_authorities import authority_for_home
# Only a home this runtime reserved has a store here; a multiplex route alone is not proof.
authority = authority_for_home(adapter.gateway_runner, home)
if authority is None:
return None
with adapter._session_db_cache_lock:
if adapter._session_db_cache_closed:
return None
return authority.db