Commit Graph

52 Commits

Author SHA1 Message Date
John Paul Soliva
6887d4efaf fix(gateway): control socket falls back to a private temp dir when the home refuses sockets
v0.22.5 makes the control listener mandatory: the gateway refuses to start without it. On the
documented Docker layout (HERMES_HOME bind-mounted from the host) a Docker Desktop / virtiofs
mount answers EOPNOTSUPP, both for a new socket and for a stale socket inode an earlier container
left behind (it can be neither stat'ed nor removed from inside). The bind failed, start() returned
False, and the gateway shut down with "gateway session bootstrap control listener unavailable",
crash-looping under its restart backoff (#123761).

When binding in-home fails with EOPNOTSUPP/ENOTSUP, the server now listens on the same private
temp-dir socket + gateway.sock.path pointer an over-long home already uses, so every existing
protection applies unchanged: the 0700 hermes-gw-<hash> directory (squat-proof mkdtemp root when
the shared name is not private), the 0600 socket under a 0177 umask, the atomically published 0600
pointer, owner-identity cleanup, and the discovery client's pointer/peer-uid validation. Any other
errno still fails; EADDRINUSE (a live sibling) is never shadowed. The legacy client treats an
un-stat-able in-home path as absent instead of raising, and the start() warning no longer calls the
failure non-fatal.

Salvaged onto current main from #101337 by @jonpol01 (rebuilt on the private-directory,
squat-proof and atomic-pointer code that landed after it).
2026-10-24 05:21:17 -07:00
Teknium
f1d6277292 fix(gateway): publish the control-socket pointer atomically
The gateway accepted on its fallback control socket and then created
gateway.sock.path with O_CREAT|O_TRUNC before writing it, so a client
polling for the starting owner (every CLI cold start) could read an empty
pointer and report 'Gateway inaccessible: invalid_control_pointer'
instead of waiting. Write a mkstemp sibling and os.replace it into place:
the pointer is now absent or complete, never empty.
2026-10-21 04:01:43 -07:00
Teknium
cdfc0a5354 refactor(gateway): parse the auth:v1 login subject in one place
The control socket's forwarded-subject gate and the history login label
each re-parsed authenticated_subject's auth:v1:[provider, issuer, user]
format. parse_authenticated_subject now sits beside
authenticated_subject and both callers use its checked result; the
issuer-less label restriction stays in _login_label.

Also pins the per-login owner check: a forwarded subject for login bob
is refused (and cannot claim) a Desktop row stamped basic:alice, and
alice still owns it.

Review finding on #140191 (Greptile)
Refs #134889 (session-writes-backend)
2026-10-16 19:22:03 -07:00
liuhao1024
a055077c88 fix(gateway): mint forwarded tickets only for structured login subjects
The forwarded subject now has a meaning authorize_history trusts, so a bare
peer-named label (admin, uid:501) could collide with another stored owner
representation — the invariant test_private_control_peer_mints_profile_bound_ticket
guards. Fail closed on anything but authenticated_subject's auth:v1:[provider,
issuer, user] form; the standalone forward only ever passes that.

(cherry picked from commit fdf6e0200565d7d94f0251718512f43d8e195ce0)
2026-10-16 19:21:42 -07:00
liuhao1024
0bba83b868 fix(dashboard): forward mutations as the dashboard's authenticated principal
The owner-forward's ticket was minted over the peer UID, so a cold row owned
by a dashboard account (authorize_history compares the actor subject against
the stored owner) answered permission_denied even for the right logged-in
user. Let a verified same-user peer name the principal it acts for in the
session-ticket mint (fail-closed on anything malformed); the standalone
forward passes its authenticated subject through, and the native-transport
claim registration is unchanged.

(cherry picked from commit e3a5b0040c6119b24dbd1a33585c718d5a8c150d)
2026-10-16 19:21:41 -07:00
unsupportedpastels
0087b9de1f fix(gateway): gateway restart brings an auto-started gateway back
`hermes gateway restart` on a manual or client-started gateway printed
"Supervisor did not relaunch the gateway", exited 1, and left no gateway
running; cron and bots stayed down until some client auto-started one.

The session runtime protocol reports a manual or Desktop-spawned gateway as
`supervisor: "none"` (5a13562d66), but the control socket's local readers still
expect the launch value:

- gateway_declares_external_supervisor treated anything but "manual" as an
  external supervisor, so restart SIGUSR1'd the gateway and waited for a
  relaunch nobody would do.
- _drain_manual_gateway refused profile-data cleanup with "none gateway
  still owns <home>".
- `hermes update`'s inventory recorded the gateway's supervisor as "none"
  instead of classifying it.

The identify answer now also carries `launch_supervisor` (what
_detect_supervisor saw), and gateway.control_socket.launch_supervisor() gives
the three readers that value. The protocol `supervisor` field is unchanged for
client discovery. A gateway from before this change that answers only "none" is
unknown, never "manual": restart falls back to the --external-supervisor argv
check, cleanup keeps refusing, and the update inventory classifies the PID.

Refs #134889
2026-10-14 20:05:34 -04:00
Teknium
408cc0d12e Merge origin/main (#32: 36 commits to cf23a1a5cc) into feat/unified-gateway-runtime
17 conflicts, all from main's lint sweep (ruff UP007/UP017/UP022/UP028/UP031/UP037/UP041,
FURB188/FURB192); no other main commit touches a conflicted file. Resolution: the branch side
of each file plus main's exact autofix (ruff 0.15.10, main's ruff.strict.toml, --fix
--unsafe-fixes). ruff.strict.toml takes main's copy. The pool-retirement live fixture stays
deleted with the pooled backend this branch retires.
2026-10-09 10:24:04 -07:00
Maciej Lisiewski
aff64c3eeb ci: UP007, UP022, UP028, UP031, UP041 linter fixes 2026-10-09 17:31:52 +02: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
b4e4d812f5 fix: hosted observation polls bounded terminal receipts; size error is distinct
Cross-profile hosted observation (HostedRoomOwnerRPC._watch) polled the
`history` producer operation every 0.25s, which returns the member session's
FULL transcript plus terminal receipts in one private control-socket line
capped at 512 KiB. Once a member conversation grew past the cap the server
answered the unstructured `response too large`, owner_request folded every
unknown reason into `runtime_draining`, the watcher thread exited with its
callbacks retained, and the driver's explicit history recovery hit the same
cap: a completed, durably stored turn could never be observed.

- New `results` hosted-producer operation (in _OPERATIONS, so attested at the
  source owner like every other verb): terminal receipts only, never the
  transcript, optionally narrowed to the admission ids whose callbacks the
  watcher holds, each text clipped just past the driver's persisted
  MAX_TERMINAL_TEXT_BYTES bound (so its truncation and notice are unchanged),
  newest first under a 384 KiB budget.
- The watcher polls `results` for its pending admission ids; delivery stays
  exactly-once (callbacks are popped under the lock by whichever read sees
  the receipt first).
- HostedRoomOwnerRPC.history falls back to the bounded receipt rows when the
  full history response is too large, so driver recovery
  (_find_terminal_receipt matches only receipt rows) still settles.
- The control socket's oversize envelope is structured
  ({"ok": false, "error": "response_too_large", "code": ..., "limit": N,
  "protocol", "id"}) and owner_request maps it to
  RuntimeStoreError('response_too_large') instead of runtime_draining.
  No caller string-matched the old text.

Review: https://github.com/NousResearch/hermes-agent/pull/106742#issuecomment-6067585232
2026-10-08 19:08:57 -07:00
Teknium
fcc760687e fix: a squatted shared-temp fallback dir no longer kills the gateway
Homes whose direct socket path exceeds sun_path bind under the predictable
$TMPDIR|/tmp/hermes-gw-<sha16(home)>/. Any local user can pre-create that
name; start() then refused it as unsafe and returned False, and the
session bootstrap treats a missing control listener as fatal ("control
listener unavailable"), so another account could keep the gateway down.

Prefer $XDG_RUNTIME_DIR (only when it is an absolute, owner-only directory,
as the spec promises) so the name lives where nobody else can create it.
When the shared-temp name is taken by something not private, bind instead
under a fresh mkdtemp root in the same temp dir, keeping the
hermes-gw-<hash>/control.sock leaf that clients (Python discovery and the
Desktop resolver) authenticate through the owner-only pointer file; the
root is removed on stop.

(cherry picked from commit b30c9a0ac0272658f69330d2653e21b01864c6a9)
2026-10-06 16:21:15 -07:00
Teknium
8b5688d6e0 fix: POSIX control-socket clients authenticate the listener's uid
query_identify, gateway_client._session_ticket, the Ink gateway_bootstrap
script and session_hosted_transport.owner_request validated the socket
path with lstat and then connect()ed by path. connect() follows a symlink
swapped in after the check, so a writer to the home could stand up an
impostor listener and hand clients its own api_origin (the earlier probe
got {"api_origin": "http://127.0.0.1:6666"} back from query_identify).
None of them asked the kernel who was listening.

Add gateway_runtime_discovery.connect_private(): validate the path, connect,
then require SO_PEERCRED (Linux) / getpeereid (macOS) uid == getuid(),
raising DiscoveryError("unsafe_control_peer") otherwise. All four clients
dial through it. The server's peer-subject check reuses the same
socket_peer_uid() so the platform branches live in one place. Platforms
with neither API keep the path checks only, as documented on the helper.

(cherry picked from commit 69b768f6bc82728395964b74bed3ad7dd98a0544)
2026-10-06 16:21:15 -07:00
Teknium
3c5ea91b14 fix: a POSIX ACL on the profile home makes group write unsafe
home_mode_unsafe accepts group-write when the owning group is the owner's
private group. With an access ACL the stat group bits are the ACL mask, so
`setfacl -m u:nobody:rwx` on a 0700 home reads as 0770 and was accepted
even though another account can now swap the control socket.

When group-write is set, check os.listxattr for system.posix_acl_access
and treat the home as unsafe if present. Only ENOTSUP/EOPNOTSUPP (no xattr
support, so no ACL possible) counts as "no ACL"; any other listxattr error
fails closed. Both the client discovery check and the server's peer-subject
check pass the path through.

(cherry picked from commit a5c39fe70c5128d45a66b3e28cf2c19cc7c74a7b)
2026-10-06 16:21:14 -07:00
Teknium
086801b82b fix: restarting the gateway heals a world-readable control pointer
Main wrote gateway.sock.path with write_text under umask 022 (mode 0644)
and a crash leaves it behind. The listener reopens it with
O_CREAT|O_TRUNC, whose mode argument only applies to a new file, so the
pointer stays 0644 and every client refuses discovery with
unsafe_control_pointer forever after an upgrade.

fchmod the descriptor to 0600 before writing so a restart repairs it.

(cherry picked from commit 59858c85aaad9dcf4249538112f1033fa364f3f5)
2026-10-06 16:21:14 -07:00
Teknium
4c9a532320 fix: control socket mints tickets for a symlinked HERMES_HOME
GatewayControlServer._posix_peer_subject refuses whenever
home.absolute() != home.resolve(), and the server kept the home exactly as
given. A gateway launched with a symlinked HERMES_HOME (or a symlinked
default ~/.hermes) therefore never produced a peer subject: discovery said
"ready" and every session-ticket request failed with "authenticated runtime
bootstrap unavailable". The PR promises a symlinked ~/.hermes keeps working.

Resolve the home once in __init__, the same canonical form clients already
dial (gateway_runtime._canonical_home). The symlink refusal still guards
against a home swapped to a symlink after start.

(cherry picked from commit 04b24405a6411b0c913098992bf845e51104c2f3)
2026-10-06 16:21:14 -07:00
Teknium
1e500ebce2 Merge origin/main (#16: 4,465 commits to 9dcab1e440) into feat/unified-gateway-runtime
99 conflicted files resolved in nine area lanes (Desktop composer, Desktop renderer/shared
client, Electron main, Ink, tui_gateway, gateway, state, CLI/config, cron/tools/CI). The
unified runtime's architecture wins where it deliberately replaced a mechanism (pool,
fallback lanes, claim poller, renderer queue); every orthogonal main change is kept, ported
into the <stem>_<topic> sibling that now owns relocated code.

Notable ports and repairs in this merge:
- tui_gateway/server.py relocated regions: atomic _attach_built_agent (#49852), slash ranking
  registry names, minted-key helpers methods_session.py calls, request_overrides, service tier.
- gateway/run_turn*.py: i18n accessors for the removed reply constants, first-contact
  internal/DM rule, rotated-compression persist, fast-mode tiers, prompt-pin rehydration.
- webhook: route_from_chat_id decodes main's opaque webhook:v2 chat ids (old ids still read).
- ws.py: main's per-connection dispatch queue with authority-first dispatch inside it.
- state: schema event for runtime revision renumbered to 31; worker mirrors updated for
  main's message uid/merge fields, on_contended lease arg, compression columns.
- config: branch's bot_chat_delivery_timeout removal renumbered v47 -> v50.
- Electron: primary-profile pin, redirect header scoping, remote fetchJsonForBackend, SSH
  teardown on profile delete, held-update dial gate restored (lost in earlier merges).
- Desktop: canonical clarify.request mapped to main's questions[] card; replay truncation vs
  snapshot_required; periodic secondary prune tick restored; DELETE already_absent restored.
- cron/tools: diagnostic category on cron failure notices restored; owner_holds_delivery
  ported onto the authority; admitted receipts can no longer be cancelled locally.
2026-10-06 14:24:24 -07:00
kshitijk4poor
d11d411f33 fix(gateway): bound the Windows control-pipe query at its own timeout
`_query_windows_pipe` reads a synchronous pipe handle that has no settimeout,
so `_read_response_line`'s deadline is only checked between chunks: a peer
that accepts and never answers (a wedged gateway, or this gateway dialling its
own pipe from its own loop thread, #132547) blocks the caller forever. The
POSIX twin is already bounded by sock.settimeout and degrades to None.

Run the pipe exchange through the existing agent.deadline.run_bounded_sync so
every Windows caller of query_gateway_control (identify, pause, rescan, serve,
...) gets the same `timeout` bound and falls back to the scan layer on expiry.
A timed-out exchange abandons one daemon thread until the pipe read returns;
that is bounded by the number of stalled dials, not per-item hot loops.

Refs #132547.
2026-10-04 11:57:03 +05:30
teknium1
1a1b3f0f11 fix(windows): the control-socket client speaks the native pipe server's protocol
Main's restored live named-pipe test found identify returning None against a live
GatewayControlServer: its Windows server is the PR's native overlapped pipe worker, and the
bare open() client got no answer. Route through query_runtime_control, which also verifies
the server's SID (update/cleanup/profile-identity consumers were silently falling back).
2026-09-27 04:05:01 -07:00
teknium1
16fd085d8a fix: a group-writable home on the owner's private group reaches the control socket
umask 002 with user-private groups (Ubuntu's default) makes an operator-created symlink target
0775; the group holds only the owner, so it cannot swap the socket. World-write and group-write
on a shared group are still refused.
2026-09-27 03:16:42 -07:00
teknium1
a858451b5f fix: -z keeps the oneshot auto-approve over the daemon; operator-mode homes reach the control socket
- hermes -z submits finite+unattended: main's oneshot ran with HERMES_YOLO_MODE (nobody can
  answer a prompt); the daemon mapped it to single-query deny, so execute_code/dangerous
  commands were blocked. -q keeps approvals.single_query_mode. unattended is only admitted
  with finite and binds for that turn alone.
- Control-socket discovery and the owner's peer check refuse group/other WRITE on the profile
  home (the socket-swap vector) instead of any group/other bit: main leaves modes beyond a
  directory link and HERMES_HOME_MODE to the operator, so a symlinked ~/.hermes (or 0750/0701)
  could not reach the gateway at all. Sockets, pointer and fallback directory stay owner-only.
- test_approval redaction tests pin the launch-snapshot switch (order-dependent otherwise).
2026-09-27 03:12:41 -07:00
teknium1
c6dc7ab120 Merge remote-tracking branch 'origin/main' into feat/unified-gateway-runtime
Merge #8: 2,771 commits from main (4b05f764fa). Ports main's moved code into the
unified runtime (run.py/run_turn.py splits, tui_gateway server, backup/restore
split), keeps the detached-daemon Desktop lifecycle, and adapts main's new tests
to the owner/authority contracts (canonical session deletes, retired-id
tombstones, zero-writer browsing, hermes_yaml, platforms() markers).
2026-09-27 02:30:04 -07:00
ethernet
16652eea18 Merge remote-tracking branch 'origin/main' into ethie/pm-clean
# Conflicts:
#	gateway/config.py
#	gateway/config_loader.py
#	gateway/readiness.py
#	hermes_cli/managed_scope.py
#	hermes_cli/plugin_python_deps.py
#	hermes_cli/plugins_cmd.py
#	hermes_cli/update_cmd_maint.py
#	plugin-catalog/hindsight.yaml
#	plugins/plugin_loader.py
#	providers/__init__.py
#	scripts/run_tests.sh
#	tests/gateway/test_control_socket_windows_live.py
#	tests/gateway/test_gateway_streaming_nested_config.py
#	tests/hermes_cli/test_doctor.py
#	tests/hermes_cli/test_plan_reconciliation_windows_live.py
#	tests/hermes_cli/test_update_apply_shallow_count.py
#	tests/hermes_cli/test_update_concurrent_quarantine.py
#	tests/hermes_cli/test_update_shim_self_lock.py
#	tests/hermes_cli/test_verify_console_scripts.py
#	tests/tools/test_lazy_deps.py
#	tests/tui_gateway/test_subprocess_encoding.py
#	tools/lazy_deps.py
2026-09-23 15:26:34 -04:00
teknium1
1eebdfa164 Merge remote-tracking branch 'origin/main' into fix/106742-thread-resolution
# Conflicts:
#	gateway/run.py
#	gateway/run_profile_reconcile.py
#	hermes_cli/web_server.py
2026-09-23 08:38:20 -07:00
Victor Kyriazakos
4c342c05de feat(gateway): stop, start and restart one profile under the host multiplexer
Under the host multiplexer every installed named profile came online because
its directory existed, and the only way to stop one profile's bots was to stop
the host, which stopped everyone's. Both are fleet-operator blockers.

`hermes -p X gateway stop` on a profile served by the host now parks it: it
writes `profiles/X/gateway.parked` first (so the 30s reconcile cannot re-add X
between the verb and the marker) and sends the new `unserve-profile` control
verb, which tears down X's adapters, reconnects and cron inside X's own scope
(the teardown `_unserve_profile` already used for deleted profiles). `start`
removes the marker and sends `serve-profile`, which runs the same add-path the
reconcile loop uses. `restart` cycles both without parking. The default
profile keeps today's whole-host meaning.

`profiles_to_serve()` skips parked profiles, so adapters, cron, ingress
membership and the served record follow from one chokepoint; roster callers
that mean "every installed profile" (plugin deps, Windows update, dashboard
listing and topology, migration inventory) pass `include_parked=True`.
Provisioning may pre-create the marker: an installed profile stays offline
until an operator starts it. Host boot logs one INFO per parked profile;
`gateway status` shows `parked (hermes -p X gateway start)`.

Tests: profiles_to_serve contract, control verbs through the runner
(round-trip and every refusal), CLI marker-before-socket ordering, reconcile
honouring the marker both ways, migration inventory retaining parked
profiles, two-home E2E through the real loaders.
2026-09-23 08:25:28 -07:00
ethernet
063560696e Merge remote-tracking branch 'origin/main' into ethie/pm-clean
# Conflicts:
#	tests/gateway/test_launchd_exit_timeout_drain_cap.py
2026-09-23 10:52:20 -04:00
teknium1
67f385f2d8 fix(gateway): every launchd-identity reader accepts the wrapper-forwarded label
The salvaged #119607 taught only the drain cap (launchd_service_label) to read
HERMES_LAUNCHD_LABEL. The gateway grandchild under the generated plist also
reads XPC_SERVICE_NAME=0 in is_gateway_supervisor_process (exit-75 restart
route) and control_socket._detect_supervisor (identify payload), so one
process was "launchd" to the drain cap and "manual" to the restart route.

One seam: gateway.restart.launchd_job_label applies the ai.hermes predicate to
XPC_SERVICE_NAME then HERMES_LAUNCHD_LABEL; the drain cap, the restart route,
the control socket and the wrapper's export all call it. launchd_service_label
and read_launchd_exit_timeout_s take `platform` as data so the mapping is
tested on Linux without patching sys.platform (AGENTS.md: don't fake the host
OS); the salvaged tests are trimmed to two invariants each and lose their
monkeypatch of sys.platform.

Not live-run: this host is Linux, launchd is code-path + wrapper-subprocess
proof only.
2026-09-23 07:48:32 -07:00
teknium1
eec5bd6673 Merge remote-tracking branch 'origin/main' into fix/106742-thread-resolution
4,048 upstream commits (Sep 16-23) composed onto the unified gateway runtime by six
per-domain conflict lanes (gateway, desktop/shared, cli/state, cron, bots/tui_gateway, ink).
Retired lanes stay retired (Desktop secondary pool + exit supervisor, deferred Bot Chat
pending queue, subprocess retry adoption); main's gateway.standalone, host-role claim,
clarify capability gate, config-read caches and idle gates ride on top.
2026-09-23 03:25:31 -07:00
ethernet
1f48a3d036 Merge remote-tracking branch 'origin/main' into ethie/pm-clean 2026-09-22 13:03:25 -04:00
teknium1
21d0b12958 feat(plugins): late-loaded plugins wire their platform handlers live (#87770)
A plugin that finished loading after an adapter connected never got its platform
handlers (slash commands, button callbacks, inbound transforms) registered until a
gateway restart, silently. Three pieces, one seam shared by every surface:

1. Discovery listener: PluginManager.on_plugin_loaded(cb) fires from INSIDE
   discover_and_load for the plugins a sweep newly loaded (diff of the loaded set),
   with a per-plugin activation summary (hermes_cli/plugins_activation.py):
   activated_now {gateway_commands, gateway_transforms, hooks, callbacks} vs
   deferred {tools, prompt, mcp_servers}. Every mid-run load path now performs a real
   discover_plugins(force=True): CLI install/enable (via the gateway), Desktop/TUI
   plugins.manage install/toggle/update, dashboard REST install, tool-triggered
   force re-discovery, the new `reload-plugins` control-socket verb. A non-forced
   discover_plugins() short-circuits on _discovered, which is why reload.mcp after
   a mid-run install used to reload the OLD server set.
2. Idempotent re-wire: BasePlatformAdapter.rewire_plugin_handlers() runs only
   factories not yet wired on the live native client (keyed (plugin, qualname);
   a force reload hands back new function objects). Telegram hoists late handlers
   ahead of core's catch-all filters.COMMAND / CallbackQueryHandler (PTB dispatches
   the first match per group) and re-wires on the transient-init rebuild; Slack
   dedupes register_slack_action_handler per AsyncApp. The gateway runner
   subscribes per served profile and re-wires on the loop.
3. Scope limit + honest messaging: handlers only. Tools/prompt stay deferred to
   the next session (prompt-cache invariant), MCP servers to mcp.reload; the CLI
   hint and plugins.manage results (activation, gateway_reloaded,
   restart_required only when no gateway answered) say exactly that.
2026-09-22 09:50:22 -07:00
ethernet
e1576d06a6 Merge remote-tracking branch 'origin/main' into ethie/pm-clean
Resolved toward the branch: PM provisions uv/python (main's install.ps1 uv-shim
salvage + its test and workflow steps dropped), the shim re-exec stays retired,
package.json carries no electron-builder block (afterExtract identity stamp wired
into electron-builder.config.cjs instead; after-pack.mjs keeps signing only),
Desktop workspace-deps helpers stay retired. Main's scratch-dir bootstrap
(export_scratch_tmp_env) is taken and re-run after profile resolution.
2026-09-19 22:57:07 -04:00
teknium1
4586cde64d chore: mark the deliberate /tmp literals and shrink the lint baseline to one code block
The seventeen remaining literals are container-side paths, AF_UNIX socket-path-limit
candidates on darwin, detection needles, guard regexes and guidance text that tells the
model to avoid /tmp. Each carries an inline `no-tmp: ok — <why>` so the reason lives
next to the line; the baseline keeps only a fenced tree listing where a marker would render.
2026-09-19 10:44:26 -07:00
ethernet
b4a294fff9 Merge origin/main; keep PM as plugin dependency owner
Reconcile plugin declarations and validation through PM's atomic generation publication; preserve external runtimes, target markers, and conflict refusal. Keep one source-update completion owner and port upstream lifecycle changes to the PM desktop/runtime paths.
2026-09-17 13:52:05 -04:00
teknium1
ac353ee059 Merge remote-tracking branch 'origin/main' into fix/106742-thread-resolution
# Conflicts:
#	gateway/run.py
#	gateway/run_adapters.py
2026-09-16 15:02:39 -07:00
xielevi
a41552fad4 fix(profiles): purge a deleted profile's session/routing identity on delete
`hermes profile delete` removes the profile directory and tears its runtime down, but the name is
also baked into durable identity the delete path never touches — `agent:<name>:*` routing keys,
`gateway_heartbeats.profile` and `delivery_obligations`. An inbound event on a chat keyed to the
dead name then enters the routing index, resolves a profile whose directory is gone, and logs
`Profile '<name>' does not exist` on every event for the life of the store (the #111926 flood,
reached from a *deleted* rather than a renamed profile). The delete side is now symmetric with the
rename rekey (`rekey_profile_state` / `rekey_profile_routing` / `migrate-profile-identity`), with
the same ownership rule:

- `SessionDB.purge_profile_state(name)` — the mirror of `rekey_profile_state`, in one
  `_execute_write` transaction. Routing keys, heartbeat rows and the telegram topic rows the rekey
  also owns are hard-deleted (a binding is matched by `profile_name` OR its `session_key`
  namespace, because the rename rewrites both); `delivery_obligations` rows are terminalized
  (`state='abandoned'`) rather than dropped, so pending delivery state is not lost silently.
- `SessionStore.purge_profile_routing(name)` — the mirror of `rekey_profile_routing`: drops the
  in-memory entries and persists the drop. Mandatory, not belt-and-braces — the owning process
  writes its in-memory copy back, so a durable delete made elsewhere is undone by its next save.
- A delete-only control verb `purge-profile-identity`, deliberately NOT inside
  `_unserve_profile()`: that hook also unserves a rename's old name, whose identity the rekey still
  has to migrate. `hermes profile delete` requires the owner's `{"ok": true}` answer and reports a
  partial settlement (naming the retry) instead of a clean success.
- The retry is the new `hermes profile purge-identity <name>`. It refuses a name that is a live
  profile again: the purge keys off the name alone, so `delete foo` (settlement pending) →
  `create foo` → `purge-identity foo` would otherwise delete the NEW incarnation's identity. The
  delete path tombstones the directory before it purges, so the guard never blocks the delete.
- `sessions` rows are not deleted by the purge: it settles identity, not history. What a delete
  leaves of a profile's conversation record is `delete_profile`'s business — it removes the
  profile's own home, `state.db` included.

Tests (`scripts/run_tests.sh`, red on base → green): `tests/hermes_state/test_purge_profile_state.py`,
`tests/gateway/test_purge_profile_routing.py`, `tests/gateway/test_profile_identity_purge.py`,
`tests/hermes_cli/test_profile_identity_purge_cmd.py` and `TestDeleteProfile` in
`tests/hermes_cli/test_profiles.py` — 95 passed, 0 failed across those five files.
2026-09-16 14:21:14 -07:00
teknium1
43c477571e Merge origin/main (61154b6f68) into feat/unified-gateway-runtime
1,446 upstream commits; 84 conflicted files resolved per family, porting
every post-branch main fix onto the cutover architecture rather than
dropping it or resurrecting replaced pre-cutover code:

- gateway/cron/kanban/a2a: #111988 hygiene bound, silence-marker rejection,
  UX copy, clarify-card retirement on explicit no-answer, Slack task-card
  publication_suppressed, webhook per-route coalescing (wrapping the durable
  admit_producer), kanban dead-worker last output + fingerprint boot witness,
  migrate-profile-identity control verb, SupervisedTickerThread, api-server
  terminal_run_status; config migration 45 kept from main, ours renumbered 46.
- hermes_cli/hermes_state/tools/tui_gateway: read_only SessionDB alongside
  explicit db_path, sessions_cmd observational flag, #111958 served-profile
  skips service install, #111999 usage source upsert repair, archived Bot Chat
  title release, find_canonical_owner, #111151 serves_routed_profile MCP scope,
  session_search after/before/exclude, server.py hunks into session_registry/
  agent_factory siblings, #111775 runtime_check resolve hook, Bot Chat
  silence rule on delivery reply.
- Desktop/apps/shared: pool modules stay deleted; SSH teardown fencing,
  default-profile + peer-window routing, per-session remote headers,
  server->client requests, generated gateway contract with our owner stamps
  and session.replay_gap retained.
- Ink: canonical WebSocket client kept; storedSid reconnect recovery, server
  request store, generated contract types, plain-language copy ported.
2026-09-16 13:20:14 -07:00
xielevi
4ba717df12 fix(profiles): migrate session/routing identity on profile rename
Renaming a profile moved profiles/<old>/ to profiles/<new>/, so the row DATA
travelled with the directory, but the profile name is also baked into
keys/values the move left untouched: session keys (agent:<old>:* namespace),
sessions.profile_name (fail-closed owner ladder / Desktop sidebar scope /
@session: deep links), sessions.origin_json.profile,
gateway_heartbeats.profile, delivery_obligations (session_key +
adapter_profile), telegram_dm_topic_* profile_name bindings, and the
gateway_routing index. Left stale, every inbound event on a chat keyed to the
old name resolved to a profile that no longer exists — flooding errors.log
with "Profile <old> does not exist ... falling back to global HERMES_HOME"
every few seconds — and renamed sessions dropped out of the sidebar / broke
their deep links.

The routing index is held in memory by a live multiplexer and written back
periodically, so a CLI-side DB rewrite alone is clobbered. Fix in layers:

- SessionDB.rekey_profile_state: atomic durable rewrite of the state.db
  tables, matching the agent:<name>: namespace by exact prefix (substr, not
  LIKE — '_' is a legal profile-name character and a LIKE wildcard), rewriting
  the profile inside routing/origin JSON, and REFUSING on a target collision
  (routing rows or telegram bindings) instead of silently merging.
- SessionStore.rekey_profile_routing: rekey the in-memory routing index
  (keys + origin.profile) then persist — the half a DB write cannot reach.
  Raises on a target-key collision before mutating.
- Control verb migrate-profile-identity (params-carrying; the socket passes
  params only to handlers that declare them, bare handlers unchanged) so a
  live gateway rekeys its in-memory copy AND both durable stores (routing home
  + the renamed profile's own state.db).
- rename_profile calls the verb when a multiplexer is live and, if it fails,
  does NOT fall back to a racing CLI-side write: it prints a warning telling
  the operator to restart the gateway and retry. With no live gateway it
  performs the durable rewrite itself (safe: nothing else holds the store
  open).

Checkpoints keyed by the profile's workdir path are a known related gap,
tracked separately, not addressed here.

Tests: rekey_profile_state (all tables, routing/origin JSON, collisions,
idempotent, no-op), rekey_profile_routing (namespace + origin, no-op, no
overwrite), control verb param passing, and rename end-to-end for both the
live-gateway (delegates, refuses unsafe fallback) and no-gateway (durable
rewrite) paths.
2026-09-16 00:32:15 -07:00
ethernet
b681f0c50e merge: reconcile origin/main with PM runtime ownership
Preserve upstream fixes without restoring retired dependency installers.
Run configured-feature checks in the selected build interpreter. Reuse a
supported base Python during bootstrap, and preserve durable backup media.

Refresh the dependency lock through PM. Keep the frozen historical import
surface unchanged. Adapt incoming native tests to the platform markers.

Verification: the incoming 86-file pass found two fixture mismatches;
both passed after correction. Targeted PM/update/compatibility checks,
Electron and renderer typechecks, and desktop tests passed.
Native Windows/macOS update journeys and the full suite remain unrun.
2026-09-12 16:55:32 -04:00
teknium1
e3c497f04f Merge origin/main into feat/unified-gateway-runtime (Sep 12)
# Conflicts:
#	agent/subdirectory_hints.py
#	gateway/run.py
#	gateway/run_turn.py
#	hermes_cli/config_migrations.py
#	tests/hermes_cli/test_config.py
2026-09-12 11:31:43 -07:00
teknium1
d1dbb0ac9e feat(gateway): multiplexer hot-serves profiles created while it runs, unroutes deleted ones
A `gateway.multiplex_profiles` gateway enumerated `profiles/` once at boot, so a profile
created afterwards (CLI, dashboard, Desktop, TUI) was never served until `hermes gateway
restart`; Desktop and the dashboard gave no reminder, so a new profile's bot simply never
connected.

The served set is now reconciled at runtime (`gateway/run_profile_reconcile.py`):
- `hermes_cli/profiles.py` create/delete ping the multiplexer over its control socket
  (new `rescan-profiles` verb); a supervised watcher rescans every 30s as the safety net.
- A new profile gets its adapters under its own runtime scope from its config/.env
  (`_start_one_profile_adapters`, same duplicate-credential guard as boot, now seeded
  with the LIVE secondaries' claims), `served_profiles` in gateway_state.json is
  updated, MCP discovery + log routing run for it. Other profiles' adapters are never
  touched.
- A served profile whose config.yaml/.env changed is re-scanned so a token added after
  create builds the adapter; already-live/queued platforms are skipped (no second poller).
- A deleted profile (tombstone) has its reconnects cancelled, adapters torn down,
  pairing/busy bookkeeping and cached agents dropped, and this process's SQLite /
  memory-store handles released so the deleter's rmtree succeeds.
- The in-process cron ticker takes a live enumerator so new profiles' jobs fire.
- PUT /api/messaging/platforms/<id>?profile=X returns `hot_served` when a live
  multiplexer rebuilt X's adapters; Desktop/dashboard skip the restart banner then.
- `hermes profile create` confirms hot-serve; the restart reminder stays for a gateway
  that did not pick the profile up (older build / signal failed).
2026-09-12 08:49:16 -07:00
Teknium
51189b0533 feat: transport hosted producers through authenticated owner sockets 2026-09-10 14:01:42 -07:00
Teknium
d3ccac14e8 feat: restrict runtime bootstrap peers and bound native pipe I/O
Retain lock inodes on access failures, protect fallback socket directories, and fence old socket cleanup. Native Windows implementation uses a protected same-user DACL, local-only named pipes, caller/server SID verification and cancellable overlapped I/O. Native execution remains pending a Windows host; Linux final regression rerun is queued behind the campaign test lock.
2026-09-08 11:44:06 -07:00
Teknium
5a13562d66 feat: authenticate local runtime tickets with OS peer identity 2026-09-08 11:44:06 -07:00
ethernet
e8fcb007b9 Merge remote-tracking branch 'upstream/main' into ethie/pm-clean
# Conflicts:
#	AGENTS.md
#	acp_adapter/edit_approval.py
#	acp_adapter/server.py
#	agent/agent_init.py
#	agent/anthropic_adapter.py
#	agent/anthropic_credentials.py
#	agent/auxiliary_client.py
#	agent/azure_identity_adapter.py
#	agent/bedrock_adapter.py
#	agent/browser_registry.py
#	agent/chat_completion_helpers.py
#	agent/coding_context.py
#	agent/context_references.py
#	agent/conversation_loop.py
#	agent/copilot_acp_client.py
#	agent/credits_tracker.py
#	agent/curator.py
#	agent/curator_backup.py
#	agent/deadline.py
#	agent/display.py
#	agent/errors.py
#	agent/estop.py
#	agent/i18n.py
#	agent/image_gen_registry.py
#	agent/image_routing.py
#	agent/learning_graph.py
#	agent/learning_mutations.py
#	agent/lsp/servers.py
#	agent/model_metadata.py
#	agent/models_dev.py
#	agent/monitoring/gateway_health_export.py
#	agent/monitoring/otlp_exporter.py
#	agent/pet/store.py
#	agent/process_bootstrap.py
#	agent/prompt_builder.py
#	agent/proxy_sources/iron_proxy.py
#	agent/secret_sources/_cache.py
#	agent/secret_sources/bitwarden.py
#	agent/secret_sources/registry.py
#	agent/shell_hooks.py
#	agent/skill_bundles.py
#	agent/skill_commands.py
#	agent/skill_utils.py
#	agent/ssl_guard.py
#	agent/ssl_verify.py
#	agent/system_prompt.py
#	agent/terminal_env_registry.py
#	agent/trace_upload.py
#	agent/transcription_registry.py
#	agent/tts_registry.py
#	agent/verify/environment.py
#	agent/vertex_adapter.py
#	agent/video_gen_registry.py
#	agent/web_search_registry.py
#	cli.py
#	cron/jobs.py
#	cron/scheduler.py
#	gateway/agent_cache_pressure.py
#	gateway/cgroup_cleanup.py
#	gateway/channel_directory.py
#	gateway/config.py
#	gateway/control_socket.py
#	gateway/dead_targets.py
#	gateway/drain_control.py
#	gateway/hooks.py
#	gateway/kanban_watchers.py
#	gateway/lifecycle_ledger.py
#	gateway/mirror.py
#	gateway/pairing.py
#	gateway/platform_registry.py
#	gateway/platforms/helpers.py
#	gateway/platforms/weixin.py
#	gateway/readiness.py
#	gateway/restart_loop_guard.py
#	gateway/rich_sent_store.py
#	gateway/run.py
#	gateway/session.py
#	gateway/shutdown_flush.py
#	gateway/shutdown_forensics.py
#	gateway/slash_commands.py
#	gateway/status.py
#	gateway/sticker_cache.py
#	gateway/whatsapp_identity.py
#	hermes_bootstrap.py
#	hermes_cli/_early_recovery.py
#	hermes_cli/_install_repair.py
#	hermes_cli/_startup_fast.py
#	hermes_cli/_subprocess_compat.py
#	hermes_cli/agent_plugins.py
#	hermes_cli/auth.py
#	hermes_cli/backup.py
#	hermes_cli/banner.py
#	hermes_cli/browser_connect.py
#	hermes_cli/build_info.py
#	hermes_cli/cli_agent_setup_mixin.py
#	hermes_cli/cli_commands_mixin.py
#	hermes_cli/codex_models.py
#	hermes_cli/config.py
#	hermes_cli/config_defaults.py
#	hermes_cli/config_migrations.py
#	hermes_cli/container_boot.py
#	hermes_cli/dashboard_auth/registry.py
#	hermes_cli/debug.py
#	hermes_cli/dep_ensure.py
#	hermes_cli/doctor.py
#	hermes_cli/doctor_live.py
#	hermes_cli/dump.py
#	hermes_cli/env_loader.py
#	hermes_cli/foreign_sessions.py
#	hermes_cli/gateway.py
#	hermes_cli/gateway_windows.py
#	hermes_cli/gui_uninstall.py
#	hermes_cli/image_provenance.py
#	hermes_cli/install_identity.py
#	hermes_cli/kanban.py
#	hermes_cli/kanban_db.py
#	hermes_cli/linux_desktop_entry.py
#	hermes_cli/local_runtime/binaries.py
#	hermes_cli/local_runtime/endpoint.py
#	hermes_cli/local_runtime/growth.py
#	hermes_cli/local_runtime/supervisor.py
#	hermes_cli/logs.py
#	hermes_cli/macos_tcc_anchor.py
#	hermes_cli/main.py
#	hermes_cli/memory_setup.py
#	hermes_cli/model_catalog.py
#	hermes_cli/models.py
#	hermes_cli/nous_subscription.py
#	hermes_cli/npm_engine.py
#	hermes_cli/plugin_index.py
#	hermes_cli/plugins.py
#	hermes_cli/plugins_cmd.py
#	hermes_cli/profile_distribution.py
#	hermes_cli/profiles.py
#	hermes_cli/prompt_size.py
#	hermes_cli/psutil_android.py
#	hermes_cli/runtime_repair.py
#	hermes_cli/security_advisories.py
#	hermes_cli/security_audit.py
#	hermes_cli/security_audit_startup.py
#	hermes_cli/service_manager.py
#	hermes_cli/session_export_md.py
#	hermes_cli/setup.py
#	hermes_cli/skills_hub.py
#	hermes_cli/slack_cli.py
#	hermes_cli/status.py
#	hermes_cli/subcommands/gateway.py
#	hermes_cli/subcommands/uninstall.py
#	hermes_cli/tools_config.py
#	hermes_cli/uninstall.py
#	hermes_cli/update_cmd.py
#	hermes_cli/update_contract.py
#	hermes_cli/update_inventory.py
#	hermes_cli/update_lock.py
#	hermes_cli/update_receipt.py
#	hermes_cli/urllib_security.py
#	hermes_cli/web_routers/local_models.py
#	hermes_cli/web_routers/profiles.py
#	hermes_cli/web_routers/skills.py
#	hermes_cli/web_server.py
#	hermes_constants.py
#	hermes_state.py
#	plugins/disk-cleanup/__init__.py
#	plugins/disk-cleanup/disk_cleanup.py
#	plugins/google_meet/node/registry.py
#	plugins/google_meet/node/server.py
#	plugins/google_meet/process_manager.py
#	plugins/google_meet/realtime/openai_client.py
#	plugins/hermes-achievements/dashboard/plugin_api.py
#	plugins/memory/hindsight/__init__.py
#	plugins/memory/honcho/__init__.py
#	plugins/memory/honcho/cli.py
#	plugins/memory/honcho/client.py
#	plugins/memory/honcho/oauth.py
#	plugins/memory/honcho/session.py
#	plugins/memory/mem0/__init__.py
#	plugins/memory/mem0/_setup.py
#	plugins/memory/openviking/__init__.py
#	plugins/memory/retaindb/__init__.py
#	plugins/memory/supermemory/__init__.py
#	plugins/platforms/a2a/protocol.py
#	plugins/platforms/dingtalk/adapter.py
#	plugins/platforms/discord/adapter.py
#	plugins/platforms/feishu/adapter.py
#	plugins/platforms/google_chat/adapter.py
#	plugins/platforms/matrix/adapter.py
#	plugins/platforms/photon/adapter.py
#	plugins/platforms/photon/auth.py
#	plugins/platforms/photon/cli.py
#	plugins/platforms/slack/adapter.py
#	plugins/platforms/teams/adapter.py
#	plugins/platforms/telegram/adapter.py
#	plugins/platforms/wecom/callback_adapter.py
#	plugins/platforms/whatsapp/adapter.py
#	plugins/teams_pipeline/store.py
#	plugins/video_gen/fal/__init__.py
#	plugins/web/ddgs/provider.py
#	plugins/web/exa/provider.py
#	plugins/web/firecrawl/provider.py
#	plugins/web/parallel/provider.py
#	tests/agent/test_ssl_ca_guard.py
#	tests/hermes_cli/test_certifi_repair.py
#	tests/hermes_cli/test_cmd_update.py
#	tests/hermes_cli/test_cmd_update_apt.py
#	tests/hermes_cli/test_dashboard_unified_launch.py
#	tests/hermes_cli/test_dep_ensure.py
#	tests/hermes_cli/test_doctor.py
#	tests/hermes_cli/test_doctor_live.py
#	tests/hermes_cli/test_gui_command.py
#	tests/hermes_cli/test_kanban_boards.py
#	tests/hermes_cli/test_kanban_db.py
#	tests/hermes_cli/test_lazy_refresh_venv_repair.py
#	tests/hermes_cli/test_memory_setup_provider_arg.py
#	tests/hermes_cli/test_nous_subscription.py
#	tests/hermes_cli/test_pip_install_detection.py
#	tests/hermes_cli/test_profile_export_credentials.py
#	tests/hermes_cli/test_psutil_android_extract.py
#	tests/hermes_cli/test_status.py
#	tests/hermes_cli/test_tui_npm_install.py
#	tests/hermes_cli/test_update_fleet_restart_pending.py
#	tests/hermes_cli/test_update_head_moved_gate.py
#	tests/hermes_cli/test_update_interrupted_recovery.py
#	tests/hermes_cli/test_web_server.py
#	tests/hermes_cli/test_web_ui_build.py
#	tests/test_hermes_logging.py
#	tests/test_managed_runtime_resolution.py
#	tests/tools/test_browser_chromium_autoinstall.py
#	tests/tools/test_browser_chromium_check.py
#	tests/tools/test_browser_homebrew_paths.py
#	tests/tools/test_browser_lightpanda.py
#	tests/tools/test_browser_npx_warmup.py
#	tests/tools/test_browser_open_timeout.py
#	tests/tools/test_browser_orphan_reaper.py
#	tests/tools/test_browser_real_profile.py
#	tests/tools/test_browser_suspect_recycle.py
#	tests/tools/test_find_shell.py
#	tests/tools/test_local_env_blocklist.py
#	tests/tools/test_macos_protected_search.py
#	tests/tui_gateway/test_compute_host.py
#	tools/approval.py
#	tools/blueprints.py
#	tools/bot_mode_dm.py
#	tools/bot_mode_probe.py
#	tools/bot_relay.py
#	tools/browser_tool.py
#	tools/browser_use_cli.py
#	tools/checkpoint_manager.py
#	tools/code_execution_tool.py
#	tools/code_kernel.py
#	tools/computer_use/cua_backend.py
#	tools/cronjob_tools.py
#	tools/discord_tool.py
#	tools/environments/base.py
#	tools/environments/daytona.py
#	tools/environments/local.py
#	tools/environments/modal.py
#	tools/environments/vercel_sandbox.py
#	tools/fal_common.py
#	tools/file_operations.py
#	tools/lazy_deps.py
#	tools/mcp_tool.py
#	tools/neutts_synth.py
#	tools/process_registry.py
#	tools/read_extract.py
#	tools/registry.py
#	tools/skill_ledger.py
#	tools/skill_linter.py
#	tools/skill_manager_tool.py
#	tools/skill_usage.py
#	tools/skills_ast_audit.py
#	tools/skills_guard.py
#	tools/skills_hub.py
#	tools/skills_sync.py
#	tools/skills_sync_client.py
#	tools/skills_tool.py
#	tools/terminal_scope.py
#	tools/terminal_tool.py
#	tools/tirith_security.py
#	tools/transcription_tools.py
#	tools/tts_tool.py
#	tools/vision_tools.py
#	tools/voice_mode.py
#	tools/wake_word.py
#	tools/web_result_cache.py
#	tools/website_policy.py
#	tools/working_diff.py
#	tools/write_approval.py
#	tui_gateway/entry.py
#	tui_gateway/methods_tools.py
#	tui_gateway/server.py
2026-09-04 13:03:39 -04:00
Teknium
e83816a4d1 review-fix(comments): restore lost #NNNN rationale comments across non-test source (mechanical sweep, condensed, code unchanged)
For each issue anchor present in BASE 63279301bc non-test .py and absent on HEAD, the BASE comment/docstring block was re-attached at the HEAD location of the code it explained (matched by the distinctive code line / enclosing def). Sentences already covered by an existing HEAD comment were deduped; the issue number always survives. Insert-only: no code lines changed.
2026-09-03 09:44:26 -07:00
Teknium
6df4bb09cf refactor(gateway): second-pass compaction of delivery ledger/router, control socket, dead targets 2026-09-02 20:13:08 -07:00
Teknium
f22fbb264c refactor(gateway): fold delivery send-result/dead-target micro-helpers, dedupe ledger claim rows, compact control socket 2026-09-02 19:09:25 -07:00
Teknium
659c6b9fff refactor(gateway): simplify session, status, stream_consumer, kanban_watchers, relay adapter, hosted-room driver/discussion/replicas, shutdown/lifecycle, pairing, channel_directory, control_socket and small modules 2026-09-02 13:31:54 -07:00
ethernet
6e294f543d fix: read source files with encoding=utf-8-sig
Read text files with the encoding utf-8-sig so a BOM at the start of a
file does not cause a Unicode decode error (Windows editors add BOMs).

Reconstructed from ethie/pm commits 48a32b135b + 013219e814 onto the
current upstream/main base: only the utf-8 -> utf-8-sig transforms were
carried (370 exact line pairs across 205 files); pm-rename hunks that
rode in the original commit were left to the pm-store commit, and
utf8sig hunks entangled with content changes ride their owning commit.

Rebuilt on ethie/pm-clean off ac6c8028e0 (upstream/main).
2026-08-29 21:23:00 -04:00
Teknium
03537d69dc feat(gateway): updaters pause gateways over the control socket instead of tree-killing them (#92091 step 2)
Windows updates forced a choice between 'gateway survives' and 'update
proceeds': the pause machinery's only tools were the planned-stop marker
poll and the force-kill ladder, so a mid-turn gateway was tree-killed and
its active turn lost. Step 2 of the socket migration adds the
pause-for-update verb: the updater ASKS the gateway to drain in-flight
turns and exit cleanly — releasing every venv file handle on the way out
— through the same request_restart(via_service=True) drain path SIGUSR1
and service restarts already use.

- gateway/run.py: pause-for-update verb handler registered on the
  existing control server; marshals onto the loop thread, ACKs with
  {pausing, already_stopping, pid, drain_timeout}.
- gateway/control_socket.py: pause_gateway_for_update() client — None on
  no-answer (older gateway / no socket), so every caller keeps the
  legacy path when the verb is missing.
- update_cmd.py (_pause_windows_gateways_for_update): socket-first ask
  per mapped profile gateway before the drain wait; positive ACKs extend
  the wait to the gateway's own declared drain budget (+ teardown grace)
  so a mid-turn gateway isn't force-killed at the end of a too-short
  local default. Marker write + force-kill ladder retained verbatim as
  the fallback.

Live E2E: real gateway process (isolated HERMES_HOME), real socket:
identify -> pause ACK {pausing: true} -> gateway drained and exited on
its own (rc=75, zero signals) -> dead-gateway re-ask returns None.
A step-1 gateway without the verb answers ok:false -> client None ->
legacy path (pinned by test).
2026-08-26 09:59:17 -07:00
Teknium
7a54ab22e6 fix(gateway): control-socket hardening from #92447 post-merge review
- bind under umask 0o177 so the socket is never world-connectable, even
  pre-chmod (review pt 3)
- verb handlers run in an executor: state-file reads stay off the
  adapter event loop (pt 2)
- inventory dedupes one multiplex gateway answering identify for several
  homes — one runtime record per pid, with regression test (pt 1)
- v1 wire contract (one request per connection) documented in the module
  docstring (pt 5); /tmp-unwritable skip in the short-home test

Live-verified: perms 600 at bind, identify 4.3ms via executor path, 20
rapid queries healthy.
2026-08-22 18:05:26 -07:00