Commit Graph

21 Commits

Author SHA1 Message Date
kshitijk4poor
de5f56c92a refactor(deadline): one poll_until for check-until-deadline loops
Twenty loops across 17 files hand-wrote the same thing:

    deadline = time.monotonic() + timeout
    while time.monotonic() < deadline:
        if condition(): return ...
        time.sleep(interval)

with small drifts between copies: some re-checked once after the loop,
some did not, one slept before its first check, and update_cmd_windows
kept a private _poll_until. A copy without the final check can miss a
condition that becomes true during the last sleep.

agent/deadline.py (already the home of clamp_timeout / run_bounded_*)
gains poll_until(predicate, timeout, interval): checks at once, cuts the
last sleep to the time left, checks again at the deadline, and returns
the predicate's last value so callers that wait for a pid / row /
identity get it back directly. timeout <= 0 is one check.

Converted: outbound_webhooks.flush, cron delivery wait and jobs flock,
host_attach channel wait, browser profile unlock, data-cleanup drain,
gateway dbus/bus waits, launchd fresh-pid and supervision waits,
supervised restart, gateway_migrate live-gateway wait, Windows
drain/absent waits, kanban init lock, local-runtime boot wait,
update_cmd_windows (private helper deleted), bot desktop start/stop
waits, TUI browser connect.

Left as is: loops whose body does more than check (progress callbacks,
interrupt handling, two distinct exits) and one site whose blind except
the health gate would reject once moved.

Behaviour changes, all small:
- loops that stopped at the deadline without re-checking now make one
  more check there;
- loops that already re-checked after a full last sleep now cut that
  sleep to the time left, so the check lands at the deadline (up to one
  interval sooner);
- a timeout <= 0 now means one check (some loops made none);
- the local-runtime boot wait checks before its first sleep instead of
  after it;
- _wait_for_user_dbus_socket also exports the user systemd env when the
  socket appears on that final check (before, that path returned True
  without it).

update_cmd_windows is imported by update_cmd on every OS, so the
fresh-source-install acceptance fixture (which keeps agent/ out of the
update path) now copies the stdlib-only agent/deadline.py too.

Tests: 4 pins for poll_until (two red against the classic
no-final-check variant), plus the existing suites for every touched
module.
2026-10-27 16:30:14 +05:30
Teknium
8a465ede75 fix(gateway): every reader that trusts a host record as a live owner checks the host lock
record_names_live_owner() = proven incarnation AND host lock not observed free. Attach, topology
(status/doctor/cron), and the update and shutdown multiplex inferences all use it, so the #133744
start-tick-collision shape (createTime matches a recycled pid, lock free) no longer reports the
recycled pid as the running host gateway anywhere.
2026-10-16 14:33:41 -07:00
joaomarcos
5fdf0e8047 fix(gateway): a free host lock falsifies a leftover rendezvous owner
Every live publisher holds host-gateway.lock for its lifetime and the OS
releases that flock on death. A leftover record can still name a live pid
after an unclean exit: create_time/start_time are missing (psutil failed at
write), or the pid is recycled, or a post-reboot process lands inside the
start-tick drift tolerance (#138343, #133744).

The attach path used only process-incarnation liveness. `_same_incarnation`
treats a missing create_time as a match, so a recycled pid looked live
forever and decide() returned the never-expiring transient refuse that
wedges supervised units in a restart loop.

Two complementary gates, both at the shared boundary:

* liveness_is_proven() now refuses a record with neither createTime nor
  startTime (topology already refused this shape; attach did not).
* host_lock_is_held() probes the real flock without retaining it. A free
  flock means the recorded owner is gone, whatever the pid looks like, so
  _probe_host_gateway returns no owner and decide() STARTs. The boot-race
  window is preserved: lock claimed before the socket binds stays transient.

This covers records that carry incarnation fields (the reboot tick-collision
family #138342's 90s grace cannot reach) and all liveness_is_proven()
callers, not only the attach probe.
2026-10-16 14:33:41 -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
teknium1
304cf75bbd fix(review): a second tenant's host gateway never attaches, refuses, or reports as ours (#121352)
The PR filtered a foreign tenant root only in hermes_cli.gateway.host_multiplexer_serving; the
seam `gateway run` actually goes through had no cross-tenant path, so tenant B's gateway still
never started: host_attach.decide() answered ATTACH (exit 0, nothing running) on tenant A's
record "serving default", and run._claim_host_gateway_role lost the per-OS-user host lock to A
and refused 75 forever (a race B can never win).

* gateway/host_attach.py: one predicate, launched_by_other_tenant(owner_home, our_home), used by
  decide() (foreign owner -> START), by the lock-loss branch of _claim_host_gateway_role (start
  beside it, WARNING), by host_multiplexer_serving (replaces its inline copy) and by
  host_topology._from_host_record (doctor / cron status / dashboard ladder no longer report a
  foreign tenant's process as this tenant's host gateway).
* gateway/host_topology.py + gateway/status.py: HostGatewayTopology carries the launch home, and
  multiplexer_liveness_for_profile reads the multiplexer's gateway_state.json from THAT home, so a
  named-hosted multiplexer no longer projects a stale standalone record from the default root.
* hermes_cli/gateway_multiplex_mode.py: recorded_standalone_warning_lines gates on gateway_state
  + live PID only; a paused/wedged-heartbeat live gateway still warns.
* docs: `hermes -p X gateway restart` on a parked profile with no live gateway behaves as start.

Tests: one regression per finding (decide()+lock loss; topology home+tenant filter), both red on
the PR head. tests/gateway/test_host_gateway_lock_refusal.py publishes its record from the
process home instead of an arbitrary tmp dir (the home was never consulted before; assertions
unchanged). test_gateway_multiplex_mode case 3 flips to "stale heartbeat + live PID still warns".
2026-09-28 13:30:57 -07:00
teknium1
1dd55aae9d Merge remote-tracking branch 'origin/main' into fix/106742-thread-resolution
# Conflicts:
#	gateway/run.py
2026-09-24 01:57:46 -07:00
kshitijk4poor
fa4714ca6a refactor(gateway): trim the --replace ownership prose and reuse _migrate_command
One statement of the ownership rule (module doc) instead of three; the
lock-refusal docstring keeps only why --replace is not offered. The
record-less-holder note names the real cause (a holder this process cannot
interrogate), and the start-beside INFO line and the lock refusal take the
migrate command from MIGRATE_COMMAND / _migrate_command() like their
siblings.
2026-09-24 13:58:24 +05:30
kshitijk4poor
78fbbb0557 fix(gateway): log the foreign-standalone-owner warning once per start
decide() runs twice per start (the CLI guard in hermes_cli.gateway and again
from start_gateway -> _host_attach_or_none), and the lock-losing path in
_claim_host_gateway_role re-derives the same fact via _owner_is_standalone(),
so every boot of a generated unit beside another profile's standalone gateway
logged the "starting beside it" WARNING three times. decide() is a verdict
function; reporting belongs at the action site. Demote host_attach's copy to
INFO and keep run.py's lock-claim WARNING, which fires exactly once on both the
--replace and plain paths and carries the `gateway migrate --multiplex` hint.

The lifecycle test still asserts the converge hint is logged by decide(); it
now captures at INFO.
2026-09-24 13:58:24 +05:30
kshitijk4poor
9a27bcc903 docs(gateway): --replace crosses homes only for an owner serving this profile
decide() grants REPLACE_HOST for an owner whose served set is unknown, but
_replace_target_belongs_to_other_profile can then only prove ownership from
THIS home's gateway.pid record (owner.serves() is False when served_known is
False, so the cross-home served-set shortcut never fires). "Whichever home
launched it" is therefore true only for the serves-this-profile leg; a
served-unknown owner launched from another home is refused (exit 1, one
supervisor retry). Say so at the host_attach module doc, the decide()
REPLACE_HOST comment and the _host_attach_or_none comment, and qualify the
`--replace` remedy in _unknown_served_message the same way.

_refuse_message is reached for an owner known NOT to serve this profile, so
its "take the host over: --replace" line pointed at a path that lands on the
same refusal (decide() only returns REPLACE_HOST for an owner that serves us
or has an unknown served set). Drop it in favour of a note, and interpolate
MIGRATE_COMMAND like the sibling refusal in run.py instead of hard-coding the
command. Text/comment changes only; no behaviour change.
2026-09-24 13:58:24 +05:30
kshitijk4poor
0717586e55 docs(gateway): drop the remaining whichever-home --replace claims
The host_attach module doc, the REPLACE_HOST consumer comment in
_host_attach_or_none and the _refuse_second_host_gateway refusal still
promised the old semantics: --replace takes the host over from whichever
home launched it. Since decide() only returns REPLACE_HOST for an owner
that serves this profile (or has not published its served set), and the
lock claim no longer treats --replace as --force, that advice is untrue
on exactly the path where it was printed.

_refuse_second_host_gateway is reached after losing the host lock to a
live process -- including one with no readable record (publish_record
failed after the claim, or a different HOST_PROTOCOL_VERSION during a
rolling upgrade). Offering --replace there sends the operator around a
loop that ends in the same exit 75. The message now says to stop the
other gateway or use --force, and states that --replace does not skip
the lock check. Text/comment changes only; no behaviour change.
2026-09-24 13:58:24 +05:30
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
teknium1
f6ce02eafa fix(gateway): parking composes with gateway.standalone and the dashboard Stop/Start twin
gateway.standalone wins over the parked marker: profile_lifecycle() returns
False for an opted-out profile, so `-p X gateway stop|start` keeps addressing
X's own gateway process and never writes gateway.parked, even while a stale
host record still lists X. Every installed-roster caller now threads both
kwargs (`include_standalone=True, include_parked=True`): the host-attach peer
walk and the standalone boot notice were reading the roster without parked
profiles.

Dashboard twin (#119886 class): `/api/gateway/stop?profile=X` on a served
profile no longer answers 409 — the spawned `hermes -p X gateway stop` parks
it; `/api/gateway/start` on a parked profile is allowed while a host
multiplexer is live (the child unparks it) and still refused when nothing can
serve it. Tests trimmed to the invariants: the marker-appearing case was a
subset of the boot-and-reconcile test.
2026-09-23 08:25:28 -07:00
teknium1
b0aa41586e Merge commit '09fbc27a4a93' into fix/106742-thread-resolution
# Conflicts:
#	apps/desktop/electron/backend-dial-claim.test.ts
#	apps/desktop/electron/gateway-file-download-transport.test.ts
#	apps/desktop/electron/pool-limits.test.ts
#	apps/desktop/electron/pool-spawn-coordinator.test.ts
#	apps/desktop/electron/quit-guard.test.ts
#	apps/desktop/src/app/chat/composer/controls.test.tsx
#	apps/desktop/src/components/notifications.test.tsx
#	apps/desktop/src/plugins/hermes-bots/group-chat-view.inline-code.test.tsx
#	apps/desktop/src/sdk/profile-routing.test.ts
#	apps/desktop/src/store/gateway-spawn-priority.test.ts
#	apps/desktop/src/store/profile.test.ts
#	gateway/run.py
#	gateway/run_turn.py
#	gateway/status.py
#	hermes_cli/dashboard_auth/ws_tickets.py
#	hermes_cli/web_routers/sessions.py
#	tests/agent/test_secret_scope_tier1_migration.py
#	tests/cron/test_bot_chat_delivery_child_env.py
#	tests/cron/test_bot_chat_warning_replay.py
#	tests/cron/test_codex_execution_paths.py
#	tests/cron/test_cron_bot_chat_delivery.py
#	tests/cron/test_cron_empty_payload.py
#	tests/cron/test_cron_mcp_toolset_empty_block.py
#	tests/cron/test_cron_memory_contract.py
#	tests/cron/test_cron_no_agent.py
#	tests/cron/test_cron_request_overrides.py
#	tests/cron/test_cron_workdir.py
#	tests/cron/test_run_one_job.py
#	tests/cron/test_scheduler.py
#	tests/cron/test_sessiondb_init_hang.py
#	tests/desktop/test_bots_chat_live_append.py
#	tests/gateway/test_api_server_runs_extraction.py
#	tests/gateway/test_approval_prompt_redaction.py
#	tests/gateway/test_auto_reset_clean_context.py
#	tests/gateway/test_auto_reset_evicts_cached_agent.py
#	tests/gateway/test_compression_deferred_soft_result.py
#	tests/gateway/test_compression_session_id_persistence.py
#	tests/gateway/test_control_socket_windows_live.py
#	tests/gateway/test_fallback_chain_reload.py
#	tests/gateway/test_model_switch_after_auto_reset.py
#	tests/gateway/test_session_hygiene.py
#	tests/gateway/test_warning_wiring_conservation.py
#	tests/hermes_cli/test_backup.py
#	tests/hermes_cli/test_chat_q_exit_clear.py
#	tests/hermes_cli/test_cli_preloaded_skills.py
#	tests/hermes_cli/test_cron.py
#	tests/hermes_cli/test_ensure_gateway_service.py
#	tests/hermes_cli/test_kanban_gateway_restart_handoff.py
#	tests/hermes_cli/test_observational_sessiondb_modes.py
#	tests/hermes_cli/test_profiles_sidebar_cache.py
#	tests/hermes_cli/test_sessions_export_md_cli.py
#	tests/hermes_cli/test_single_query_session_finalize.py
#	tests/hermes_cli/test_web_server.py
#	tests/hermes_state/test_hermes_state.py
#	tests/tools/test_bot_live_owner_delivery.py
#	tests/tools/test_bot_mode_dm.py
#	tests/tools/test_bot_retry_policy.py
#	tests/tools/test_bot_turn_lock.py
#	tests/tui_gateway/test_bot_live_owner_delivery.py
#	tests/tui_gateway/test_compute_host_turn_protocol.py
#	tui_gateway/server.py
#	ui-tui/src/__tests__/createSlashHandler.test.ts
#	ui-tui/src/__tests__/submissionCore.test.ts
#	ui-tui/src/app/useSessionLifecycle.ts
2026-09-23 07:47:09 -07:00
teknium1
46819c45bb fix(gateway): a restart over a SIGKILLed owner no longer loses the PID race to itself
main's `gateway.standalone` work persists the multiplex verdict into gateway_state.json from
`load_gateway_config_for_runner`, which on the unified bootstrap runs BEFORE the pre-reserve
`get_running_pid()` probe. That write stamps the booting process's own pid into the record, so
`get_runtime_status_running_pid()` reported the new daemon as a live rival, the stale gateway.pid
left by the killed owner was never unlinked, and the O_EXCL claim failed with "PID file race
lost". A record naming os.getpid() is never a rival.

Also composed for the host multiplexer preflight, so a fixture-launched standalone owner is
visible to the default daemon arriving second:
- host_attach._served_from_identity reads our [{profile_id, home}] served set, not bare names
- status._gateway_command_subcommand recognises `python -m gateway.run` as the gateway entry
- run_bootstrap._launch_home_may_multiplex: an unset multiplex default on a NAMED launch home is
  downgraded to standalone (a guard verdict) instead of EX_CONFIG; explicit true still refuses
- tests/conftest.py live-system guard admits `-m gateway.run` children whose env re-homes both
  HOME and HERMES_HOME away from the developer account (disposable daemon fixtures)
- test_unified_gateway_native_live accepts main's attach outcome for a second `gateway run`
2026-09-23 06:41:22 -07:00
John Paul Soliva
516687d7e3 fix(gateway): --replace starts beside another profile's standalone owner
host_attach.decide() returned REPLACE_HOST for any live host owner whenever
--replace was passed, before checking whether that owner serves this profile.
On a one-process-per-profile fleet the owner is another profile's standalone
gateway: _replace_target_belongs_to_other_profile correctly refuses to signal
it (fail closed), the gateway exits, and the supervisor restarts it into the
same refusal. hermes gateway install generates --replace for every unit, so
every profile but the one holding the host lock respawn-storms.

The non-replace path already handles this owner by starting beside it; only
--replace skipped that branch. --replace now targets the owner only when it
serves this profile, or when its served set is not known yet (the boot race,
where replacing keeps --replace's authority and the ownership guard still
decides). An owner known not to serve us takes the non-replace path.

Reproduced on a live macOS launchd fleet after updating to 0.21.4: the first
profile to restart claimed the host lock, and the default profile's unit then
looped on "Refusing --replace: PID <other profile's gateway> cannot be proven
to belong to this profile's gateway" until the respawn-storm breaker engaged.
2026-09-23 06:27:24 -07:00
Victor Kyriazakos
0238c9d740 feat(gateway): gateway.standalone opts a named profile out of the host multiplexer
A named profile that authors `gateway.standalone: true` in its own config.yaml
runs its own gateway again, the pre-multiplex topology, while the default
gateway keeps serving every other profile. Topology becomes something the
operator authors per profile instead of something the box infers from boot
state, which is what a fleet running per-profile gateways lost when
`gateway.multiplex_profiles: false` was retired.

Changed
- hermes_cli/profiles.py: `profile_is_standalone(home)` reads the profile's
  own config.yaml (memo by file signature, tolerant of malformed yaml, always
  False for the default profile with one warning). `profiles_to_serve()`
  excludes standalone profiles; roster callers that mean "every installed
  profile" (plugin deps, Windows update, launch policy, dashboard listing and
  topology) pass `include_standalone=True`.
- gateway/host_attach.py: `standalone_attach_decision` starts a standalone
  profile's gateway beside the host multiplexer once every live gateway
  confirms it does not serve that profile; refuses with a rescan message while
  one still does. Used by the initial attach check and the lock-losing race.
- hermes_cli/gateway_multiplex_mode.py: a standalone launcher never becomes
  the host multiplexer (`STANDALONE_PROFILE_REASON`), including callers that
  supply an explicit GatewayConfig.
- hermes_cli/gateway.py, web_server_gateway.py: `hermes -p X gateway
  install/start/run` proceeds without --force for a standalone profile; the
  refusal text for other profiles points at the opt-out; status shows
  "standalone (gateway.standalone: true)" and the default lists skipped
  profiles.
- gateway/run_profile_reconcile.py: the host does not re-adopt a profile whose
  own gateway is live (removing the key while it runs no longer double-binds).
- hermes_cli/gateway_migrate.py: standalone profiles are neither blocker nor
  fold target; the plan lists them as "standalone by config".
- gateway/run.py: one INFO line per standalone profile at host boot.

Tests: two-home E2E through real loaders and resolve_multiplex_mode, decide()
with fake host records for both arms, lock-losing branch, reconcile guard,
migrate plan, refusal predicate both ways, topology, memo and malformed-yaml
contracts. All red on base.
2026-09-22 19:55:02 -07:00
teknium1
bb359ec5c1 fix(gateway): log the converge hint on a standalone owner; put a refusal in the profile's own log
Two gaps left by the standalone-owner START (field report on #118097):

* decide() now logs ONE WARNING when it starts beside another profile's
  standalone gateway, naming `hermes gateway migrate --multiplex`. The
  legacy per-profile topology stays live, but the fleet should be able to
  find out it is still on it from its own logs.

* A REFUSE on `gateway run` prints to stdout, which under launchd is the
  unit's stdout file; the wrapper then maps 78 to 0 and the unit is
  parked with nothing in that profile's gateway/errors log. Log the
  verdict and the remedy at WARNING before exiting. The exit code is
  unchanged: a multiplexing owner that excludes the profile is a
  config-derived, permanent refusal, and 75 would make launchd relaunch
  it every ThrottleInterval forever (#89477) — the smaller correct
  change is to stop the refusal being silent, not to make it retry.
2026-09-21 08:38:15 -07:00
kshitijk4poor
d39ce8f455 refactor(gateway): build the rescanned owner once; fix docstrings the new outcome contradicted
Review follow-ups on the standalone-owner fix:
- _request_serve_profile built the HostGateway twice three lines apart; the standalone
  branch also copied the probe's stale profiles instead of the rescan answer's served set.
  One construction from the answer, standalone= from its multiplex key.
- START no longer carries an owner nobody reads.
- Module doc said 'exactly one gateway per host' / 'Four outcomes' / 'never a second gateway',
  all contradicted by the START-beside-standalone outcome; scoped to 'beside a multiplexer'
  and pointed at #109417 for the forced migration that removes the standalone branch.
2026-09-21 08:38:15 -07:00
kshitijk4poor
804cc3c021 fix(gateway): a standalone owner is the per-profile topology, not a refusal
`gateway/host_attach.py::decide()` treated a host owner that answers `multiplex: False`
to the rescan — another profile's standalone gateway — the same as a multiplexer whose
roster excludes us, and issued the permanent REFUSE. On the supervised path that is
exit 78, which `hermes_cli/stderr_timestamp.py` maps to 0 so launchd's
`KeepAlive.SuccessfulExit=false` parks the unit. On a one-process-per-profile fleet
(the topology `multi-profile-gateways.md` documents and `multiplex_profiles: false`
promises to keep) every launchd gateway except the first to claim the host lock was
parked at boot, silently; which ones survived was a boot race against the owner's
record landing.

`request_serve_profile` now returns the owner flagged `standalone` instead of `None`
for a `multiplex: False` answer, and `decide()` turns that into START — this profile
runs its own gateway beside the owner, as before #118097; the host-lock claim still
logs the two-gateway topology and `gateway migrate --multiplex` stays the converge
path. REFUSE is unchanged for a multiplexing owner that excludes the profile.

A/B against a REAL owner process (real host lock, record and control socket answering
the rescan): base → `refuse`, exit 78 → launchd 0 (parked); fix → `start`. Negative
control (owner answers `multiplex: True`, roster excludes the profile): `refuse` on
both.

Field report: debug share 5024e996 (11 launchd profile gateways, 0.21.3 ea0c2b82 —
only 2 of 11 came back after `hermes update`), discussed on #118097.
2026-09-21 08:38:15 -07:00
teknium1
a10620a669 fix(gateway): a record alone never means "attach", and --replace/--force work
Review fixes on the lifecycle-verbs PR. Three of them were escape hatches that
looked implemented and were dead code, and one turned a boot race into a
permanently parked unit.

- ATTACH now requires a LIVE `identify` answer. The claim-time record is
  published with NO served set (the runner settles multiplex a moment later),
  and `host_gateway()` reports `served_known=False` when nothing answers. An
  owner whose served set is unknown yields a TRANSIENT refusal, never an
  attach: previously `default`'s claim published "default,other" before its
  socket bound, `other`'s systemd unit read that as "I am served", exited 78,
  and systemd parked it for good.
- `served_profiles()` honours the actual `gateway.multiplex_profiles` setting
  instead of forcing `multiplex=True`, so a standalone gateway stops claiming
  the whole roster.
- `--replace` is threaded through the CLI guard into `start_gateway`, and
  `--force` into `_host_attach_or_none`. Both previously exited in the guard
  before the code that implements them ever ran ("nothing to start", rc=0).
- A supervised attach exits 75 (EX_TEMPFAIL), not 78. 78 is the PERMANENT
  config refusal every supervisor parks on; "someone else serves me right now"
  is a runtime observation that ends when that process does. No unit files
  change: systemd already has RestartForceExitStatus=75/RestartSec=5, the s6
  finish script passes 75 through, launchd relaunches a non-78 failure. Exit 0
  would not do — s6 parks a clean exit too.
- `restart --all` retracts the stopped owner's record (`discard_dead_record`)
  and re-enters with `replace=True`, so it can no longer attach to the corpse
  it just stopped and exit 0.
- Rendezvous hardening: the dir is created/repaired 0o700, a record whose
  `st_uid` is not ours is ignored, liveness is proven BEFORE we dial the home
  it names, and a live `identify` must agree about `hermes_home`.
- `-p X gateway restart --all` reaches the `--all`-aware branch instead of the
  generic guard's `hermes -p default gateway restart` one-liner.
- `host_gateway()` is memoized (2s TTL, invalidated on every record write), so
  `gateway status`/doctor across N profiles pays one probe, not N.

Tests: the two new files build the record as raw JSON, so they COLLECT and RUN
against a tree without the `home` field and fail on the outcome. A/B against
the PR head: 9 failed / 6 passed → 15 passed. conftest's per-test
HERMES_GATEWAY_LOCK_DIR now defers to a caller-supplied value (and
run_tests.sh forwards it through `env -i`), and the per-process dir is a
deterministic self-sweeping per-PID path instead of an atexit-only mkdtemp.
`test_runner_startup_failures.py` stubs the new attach gate and releases the
host role it claims.
2026-09-21 05:02:29 -07:00
teknium1
a20a88398f gateway: lifecycle verbs mean "the one host multiplexer"
`gateway run`, `start --all`, `restart --all` and `stop` each assumed "this
profile's gateway". Under the multiplex-only ruling there is exactly ONE
gateway process per host, so they now target that process:

- `gateway run` for a profile the host gateway already serves ATTACHES: print
  its PID + served set, exit 0, spawn nothing. Not served yet -> ask the owner
  to re-scan `profiles/` (control socket) and attach once the answer includes
  it. Refuse only when the host gateway cannot be made to serve it. Under a
  service supervisor the attach exits 78 instead of 0 so a redundant unit is
  parked, not restart-looped.
- The attach channel is reachable BEFORE the PID claim: the decision reads the
  landed rendezvous record (now carrying the owner's HERMES_HOME) and talks to
  the owner's control socket, so it no longer depends on the claim ordering in
  start_gateway.
- `start --all` / `restart --all` no longer SIGTERM every gateway-looking
  process: they restart the host multiplexer and preserve its served set. A
  secondary still running its own gateway is reported with the
  `gateway migrate --multiplex` one-liner, never killed.
- Ownership is decided by the live served set (record + control socket), not by
  argv: a host singleton runs bare/default argv and can never prove it serves
  profile X, which rejected every secondary.
- The implicit-multiplex verdict no longer requires the DEFAULT profile: the
  multiplexer is whichever profile launched the one host process.

Tests: per-test HERMES_GATEWAY_LOCK_DIR isolation in tests/conftest.py — the
host record is shared per OS user by design, so one test that boots a gateway
made every other file's lifecycle code attach to it.
2026-09-21 05:02:29 -07:00