From be82d52cb730f582dd0f554a3ad942fc655c44e8 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Sat, 12 Sep 2026 00:50:52 -0700 Subject: [PATCH] docs: migrating from per-profile gateways to the multiplexer What `hermes update` does, blockers and fixes, URL change for inbound-port profiles, the post-create restart reminder, rollback, and the `gateway migrate` reference row. --- hermes_cli/AGENTS.md | 6 ++ website/docs/getting-started/updating.md | 1 + website/docs/reference/cli-commands.md | 1 + .../docs/user-guide/multi-profile-gateways.md | 101 ++++++++++++++++++ 4 files changed, 109 insertions(+) diff --git a/hermes_cli/AGENTS.md b/hermes_cli/AGENTS.md index 1d79b3880b..abbaf5e942 100644 --- a/hermes_cli/AGENTS.md +++ b/hermes_cli/AGENTS.md @@ -136,6 +136,12 @@ Enumeration is a pure read: never `mkdir` a profile home from a served path (`Se cron all go through `mkdir_under_hermes_home` / `_ensure_cron_dir`, which refuse a deleted or missing named profile, #94590). Process-global per-profile slots (MCP discovery in `mcp_startup.py`, tool registry overlays) key on `hermes_constants.hermes_home_key()`, never a single flag. +Migration from per-profile gateways: `hermes_cli/gateway_migrate.py` (`hermes gateway migrate +--multiplex|--standalone`, table-driven `_PREFLIGHT_CHECKS`, manifest `/gateway_migration.json`); +`update_cmd_fleet._verify_fleet_after_update` calls `maybe_auto_migrate_after_update` on the success +path only. Blockers reuse `GatewayRunner._adapter_credential_fingerprint` and `platform_binds_port`; +"has a `/p//` ingress" is the adapter class attribute `serves_profile_prefix` — set it on a +new HTTP-inbound adapter when it answers the prefix, never extend a list here. ## Nous free tier (`hermes_cli/anon_auth.py`) diff --git a/website/docs/getting-started/updating.md b/website/docs/getting-started/updating.md index 24c9efde0e..c843f84917 100644 --- a/website/docs/getting-started/updating.md +++ b/website/docs/getting-started/updating.md @@ -41,6 +41,7 @@ When you run `hermes update`, the following steps occur: 5. **Config migration** — detects new config options added since your version and prompts you to set them 6. **Desktop rebuild (stage-and-swap)** — if the Hermes Desktop app was built from this checkout, it is rebuilt so the GUI matches the new code. The rebuild packs into a temporary staging directory next to `apps/desktop/release/`, verifies the staged app, and only then renames it over the previous build. A rebuild that fails at any point — corrupt Electron download, missing dependency, disk full — leaves the previous app untouched and launchable; the update reports `⚠ Update partially complete` and `hermes desktop` retries the rebuild. 7. **Gateway auto-restart** — running gateways are refreshed after the update completes so the new code takes effect immediately. Service-managed gateways (systemd on Linux, launchd on macOS) are restarted through the service manager. Manual gateways are relaunched automatically when Hermes can map the running PID back to a profile. Manually-launched `hermes serve` / `hermes dashboard` backends (for example a network-bound serve powering a remote Desktop) are handled the same way: each backend records its bind address in the install's spawn ledger at startup, so the update stops it before the code swap and relaunches it afterward on the **same host and port** — a remote Desktop pointed at that endpoint reconnects instead of stranding. Backends owned by a running Desktop app are left to the app's own respawn. +8. **Multiplex migration (multi-profile installs)** — once the fleet is verified on the new code, an install with two or more profiles that still run **one gateway per profile** is folded into a single multiplexed default gateway when nothing blocks it (same as `hermes gateway migrate --multiplex --yes`); if a blocker exists (a bot token shared by two profiles, a secondary profile binding a port with no `/p//` ingress) the update prints the blockers with their fixes and changes nothing. Single-profile installs are never touched. See [Migrating from per-profile gateways](../user-guide/multi-profile-gateways.md#migrating-from-per-profile-gateways). ### Missing Windows updater files diff --git a/website/docs/reference/cli-commands.md b/website/docs/reference/cli-commands.md index 4fbeef440a..2fee9daf02 100644 --- a/website/docs/reference/cli-commands.md +++ b/website/docs/reference/cli-commands.md @@ -273,6 +273,7 @@ Subcommands: | `install` | Install as a systemd (Linux) or launchd (macOS) background service. | | `uninstall` | Remove the installed service. | | `setup` | Interactive messaging-platform setup. | +| `migrate` | Move per-profile standalone gateways onto one multiplexed default gateway (`--multiplex`, the default) or roll back from the recorded manifest (`--standalone`). Runs a preflight (duplicate bot tokens, secondary port-binders without a `/p//` ingress) and changes nothing when blocked. Flags: `--dry-run`, `-y`/`--yes`. See [Migrating from per-profile gateways](/user-guide/multi-profile-gateways#migrating-from-per-profile-gateways). | | `migrate-legacy` | Remove legacy `hermes.service` units left over from pre-rename installs. Profile units (`hermes-gateway-.service`) and unrelated services are never touched. Flags: `--dry-run`, `-y`/`--yes`. | | `enroll` | Experimental: enroll this gateway with a relay connector and save relay credentials for connector-backed platforms. See [Hermes Relay](/user-guide/messaging/relay). | diff --git a/website/docs/user-guide/multi-profile-gateways.md b/website/docs/user-guide/multi-profile-gateways.md index 74b5504f58..96a3f250e8 100644 --- a/website/docs/user-guide/multi-profile-gateways.md +++ b/website/docs/user-guide/multi-profile-gateways.md @@ -708,6 +708,102 @@ grep -H 'TELEGRAM_BOT_TOKEN\|DISCORD_BOT_TOKEN' \ ~/.hermes/.env ~/.hermes/profiles/*/.env ``` +## Migrating from per-profile gateways + +If your profiles each run their own gateway today (one systemd unit or launchd +agent per profile), you can fold them into a single multiplexed default gateway +with one command — and roll back with another. Standalone per-profile gateways +remain fully supported; this is an optional migration, not a removal. + +```bash +hermes gateway migrate --multiplex --dry-run # print the plan and any blockers; changes nothing +hermes gateway migrate --multiplex # apply (asks for confirmation on a TTY; -y skips) +hermes gateway migrate --standalone # roll back to per-profile gateways +``` + +### What `hermes update` does + +After a successful update, when the install has two or more profiles, at least +one secondary profile runs its own gateway (a live process or an installed +service) and `gateway.multiplex_profiles` is off, `hermes update` runs the same +preflight: + +- **Nothing blocks it** → the migration runs automatically (the same code path + as `hermes gateway migrate --multiplex --yes`) and prints what it did. This + is deterministic and never prompts, so it also runs on headless/cron updates. +- **Something blocks it** → a warning block lists each blocker with its exact + fix and the one-liner to run later. Nothing is changed. + +Single-profile installs are never migrated (there is nothing to gain), and an +install that is already multiplexing is left alone. + +### What the migration does + +1. Stops each secondary profile's standalone gateway and uninstalls its + service (systemd user/system unit or launchd agent). What was removed is + recorded in `~/.hermes/gateway_migration.json` for rollback. +2. Sets `gateway.multiplex_profiles: true` in the **default** profile's + `config.yaml`. +3. Restarts the default gateway — or installs and starts it on the same service + manager the secondaries were using, so a systemd-managed fleet stays + systemd-managed. +4. Waits for the default gateway to record `served_profiles` covering every + profile, then prints a summary. + +### Blockers and fixes + +| Blocker | Why | Fix | +|---|---|---| +| Two profiles configure the same platform credential (e.g. the same `TELEGRAM_BOT_TOKEN`) | Under one process a bot token can only be polled once; the multiplexer would park the duplicate and that profile's bot would go silent | Remove the token from the second profile, or keep it in `default` and route that profile's chats with [`profile_routes`](#routing-shared-bot-chats-to-profiles-profile_routes) | +| A secondary profile enables a port-binding platform that has **no** `/p//` ingress on the default listener | The multiplexer skips that whole profile (see [rule 2](#2-http-inbound-platforms-are-reached-via-a-pprofile-url-prefix)) | Disable the platform in that profile (`platforms..enabled: false`), or keep the profile on a standalone gateway with `hermes -p gateway start --force` | + +The credential check reuses the gateway's own conflict detection, so its verdict +matches what the multiplexer does at startup. Which port-binding platforms have +a `/p//` ingress is read from the adapters themselves (each declares +`serves_profile_prefix`), so the preflight stays correct as new HTTP-inbound +adapters gain the prefix. + +### What changes for inbound-port profiles + +A secondary profile that used `api_server` or `webhook` on its own port is +**not** blocked — but its URL changes. The preflight prints the exact new URL, +for example: + +``` +Profile 'coder': api_server moves onto the default listener at +http://127.0.0.1:8642/p/coder/v1/... (its key/secret is unchanged; update +clients that call the old per-profile port). +``` + +The profile's own `API_SERVER_KEY` / webhook secret keeps authenticating the +prefixed URL; nothing else about the key changes. + +### Profiles created after the migration + +The multiplexer snapshots the profile set at startup. `hermes profile create` +prints the reminder when a live multiplexer is detected: run +`hermes gateway restart` (from the default profile) and the new profile is +served. + +### Rollback + +```bash +hermes gateway migrate --standalone +``` + +reads `gateway_migration.json`, sets `gateway.multiplex_profiles` back to its +previous value, restarts the default gateway, and reinstalls/starts every +recorded per-profile service. The manifest is removed once everything is back. +If no manifest exists (you enabled multiplexing by hand), leave multiplex mode +with `hermes config set gateway.multiplex_profiles false && hermes gateway restart` +and reinstall the per-profile services you want. + +Not covered automatically: s6-supervised containers (set the flag on the +default profile and restart the container) and Windows Scheduled Tasks (set the +flag, stop the per-profile tasks, `hermes gateway restart`). The dashboard's +System page offers the same migration as a button when the preflight finds an +eligible install. + ## Updating the code `hermes update` pulls the latest code once and syncs new bundled skills into @@ -718,6 +814,11 @@ hermes update hermes-gateways restart ``` +Running gateways are restarted by the update itself; on an install that still +runs one gateway per profile, the update then offers the +[migration to a single multiplexed gateway](#migrating-from-per-profile-gateways) +— automatically when nothing blocks it, otherwise as a warning with the fixes. + User-modified skills are never overwritten. ## Troubleshooting