Symptom: ProcessRegistry.spawn_local starts every terminal(background=true) job in its own session, and
the agent-lifecycle sweeps that stop jobs (kill_all on release, agent_close, a turn timeout) only run
while the owner is alive. A CLI, TUI or worker that is SIGKILLed / OOM-killed / crashes left every job
running on init. Measured on Linux (tbg_probe, kill -9 the owner, check at +10 s, 2/2 runs): pipe job
1/1 alive, pipe job with a child 2/2 alive. A PTY job's hangup stops only jobs that keep the default
SIGHUP action: a HUP-ignoring PTY job (`nohup`'d server, trap '' HUP) and its child 2/2 alive.
Change (tools/process_registry_ownership.py, a new ProcessRegistry mixin; process_registry.py is at its
size cap and shrinks by 10 lines): a local background job's process group goes to the owner-death
supervisor (process_identity layer 4) for as long as the job's own process runs: pipe jobs start through spawn_owned
(purpose="terminal-background", recorded in the spawn ledger), PTY jobs hand their pty.fork group to
own_process_groups. The group is released when the job leaves _running (exit, kill, reconcile) and by
_reap_untracked after a failed setup, so a job's deliberate `server &` survivors keep today's
behaviour once the job ends. A foreground command that yields to background (adopt_local) hands its
supervised group to the job instead of releasing it.
Deliberately NOT owned (they must outlive the owner):
- persist_on_release jobs (#41225, ec5c9c738a): the user asked for them to outlive the agent.
- every job of a gateway (a host that ran recover_from_checkpoint, or a supervised gateway): it
re-adopts the jobs a crashed predecessor left running, so its own jobs must survive its crash the
same way. Its clean shutdown still kills them (kill_all(source="gateway_shutdown")).
- Windows: the layer-3 job object covers ownership; the spawn path there is unchanged.
The systemd-scope, TERM->KILL tree kill, start-time PID-reuse guards and post-kill survivor checks stay:
they cover a live owner.
Result: same probe, 3/3 runs: pipe 0/1, pipe+child 0/2, HUP-ignoring PTY job + child 0/2 alive; the
persist_on_release job 1/1 alive (as intended). tests/tools/test_terminal_owned_jobs.py now also covers
jobs: kill -9 owner vs live control owner (jobs + PTY job + command die, persist_on_release job lives,
control untouched), a recovering host's jobs outlive its kill -9, finished job releases, yielded
command keeps its group until the job ends, unowned jobs never reach the supervisor. 5/5 green x3, 5/5
red on the pre-change code, each red on its own mutation (8 mutations). Two existing tests build
sessions by hand or fake Popen + os.killpg; they now carry the new field / stub the supervisor.
_reap_untracked moves into the mixin unchanged apart from the release.
Mechanism: _write_checkpoint rebuilt the profile's processes.json from the
writer's own _running table (+ extra_entries) and atomic-replaced it, with no
read-merge and no lock. This PR made that file the only handoff of a managed
worker's background process to the next interpreter (recover_from_checkpoint
adopts the entry's output_log and tails it), and the always-running owner is
now a routine writer: the owner's next own process start/exit/kill (or a
second concurrent worker) dropped the worker's entry. The process kept
running and logging, but nobody tailed it: notify_on_complete never fired and
process poll/kill could not see it. (The generic CLI-vs-gateway overwrite race
stays pre-existing per round-12 N58; this fixes the PR's own handoff.)
Fix: read-merge-write under an exclusive file lock (processes.json.lock, the
active_sessions _FileLock: fcntl / msvcrt). A writer keeps on-disk entries it
neither runs nor has finished, but only worker handoffs whose output log
still decides an outcome: the log exists and either its recorded .exit is
waiting or the pid is alive with the same start time. Dead, recycled or
non-handoff foreign entries are still dropped.
Red on r13-base2: tests/tools/test_process_checkpoint_worker_handoff.py (real
live process, real checkpoint file): the owner's write dropped proc_worker;
after the fix it is kept, a dead handoff is dropped, and the successor
registry adopts the worker's process.
Review: ahrazzle B2-04
A managed worker is a per-turn interpreter. `terminal(background=true)`
spawned the child with stdout=PIPE whose only reader was a thread in that
worker. When the worker exited at its turn boundary the read end closed;
the child's next write took SIGPIPE (`broken_pipe`) and died, and the next
worker's `recover_from_checkpoint` (F24) adopted only a bare PID with
"output history unavailable". Reproduced on r6-base with a real managed
turn: a `trap ... PIPE` in the command fired, the output never reached any
interpreter, and turn two's `process_manage wait` returned `not_found`
(probe_b*_base.log), with and without notify_on_complete.
Root fix, no new subsystem: inside a registered worker process
(`is_worker_process()`) a local background spawn writes stdout+stderr to
an owner-only append log under the profile home
(logs/process-output/<proc_id>.log) and its shell records `$?` beside it
(<proc_id>.exit, an EXIT trap - the same contract the env-backend
wrapper already uses). The log path rides the process checkpoint. The
spawner tails the file while it lives; whoever adopts the checkpoint next
(the session's next worker, or the owner at startup) restarts a reader
from offset 0, so output and the recorded exit are collected exactly as a
spawner would, and a process that died past the trap settles `lost`. A
log-backed adoption is decided by its reader, never by the PID-reuse
heuristic, so a recycled PID is still never signalled. PTY mode is not
offered to worker spawns (a PTY master dies with the worker the same
way). Outside a worker nothing changes: the pipe/PTY readers are
untouched. notify_on_complete inside a worker is already declined by the
previous commit (no reader for the worker's completion queue); the
model is told to poll/wait, which now works across the boundary.
Retention: a log is removed only once its recorded exit is older than
the process-results retention (7 days); a still-running quiet process
keeps its log.
Shape: tools/process_registry.py stays at 2,766 lines (three duplicated
comment blocks folded to offset the wiring); the reader lives in the new
tools/process_registry_output_log.py mixin.
Red on r6-base (process_registry.py + _checkpoint.py swapped to r6-base,
output_log module removed):
test_worker_spawned_process_output_and_exit_survive_the_spawner:
AssertionError: {'status': 'not_found', 'error': 'No process with ID proc_d17db6107b4d'}
test_next_managed_turn_reads_the_previous_workers_background_output: FAILED
Green after: 2 passed (exit_code 7, output 'FIRST_42\nSECOND_42\n'
collected by a different interpreter / the next managed turn).
Adjacent: 45 files (tests/tools/test_process_*, completed_process_results,
local_background_child_hang, subagent_process_handoff, terminal_*background*,
zombie_process_cleanup, threaded_process_handle, tests/gateway/test_managed_*,
worker_ledger_tool_execution, worker_agent_execution)
341 passed, 0 failed, 7 skipped.
Review: https://github.com/NousResearch/hermes-agent/pull/106742#pullrequestreview-5462648005
Checkpoint refresh treated a failed start-time check as a collected exit
and queued a completion. A live PID whose start time matches, or whose
start time cannot be read, stays running. A reused PID is closed without
being signalled. A gone PID is pruned. A completion is emitted only when
an exit status was collected.
Under gateway.multiplex_profiles a secondary profile X is ticked, dispatched
and notified from the default profile's process, where os.environ holds the
DEFAULT profile's .env and X's values live only in the per-turn secret scope /
HERMES_HOME override. Every remaining read that skipped that scope made X
behave differently from `hermes -p X gateway run`:
- cron: HERMES_CRON_TIMEOUT, HERMES_MODEL (job/preflight fallback),
HERMES_CRON_MAX_PARALLEL, inflight allowance, prefill file and the script
timeout were bare os.getenv → the default profile's values; a job without a
model silently ran on the default's HERMES_MODEL instead of refusing.
cron/env_settings.py::cron_env_setting reads the scope (fire) or the ticked
home's .env (tick thread), plain environ when multiplexing is off.
- child env: the restart-safe cron worker, the Bot Chat delivery child and the
kanban worker inherited the launch profile's non-credential .env settings
and bridged TERMINAL_* policy (TERMINAL_ENV=docker, default's image,
HERMES_MODEL) — X's worker ran in the default's docker image on the
default's model. tools/environments/local.py::strip_launch_profile_env drops
them when the child targets another served profile.
- kanban: the worker --toolsets pin was silently dropped for every served
assignee (toolset probes call get_secret without a scope → swallowed
UnscopedSecretError); notifier pings, artifact uploads and the wake text ran
under the default's media policy / display language (only wake() was scoped).
- /loop: _post_turn_loop_completion hopped to the executor without contextvars,
writing the completed tick into the DEFAULT profile's state.db and leaving
X's row awaiting_response forever; the --until judge ran with the default's
aux credentials.
- background processes: a secondary's processes.json (scope-relative since
adf23550f5) was never read at startup; its processes were not re-adopted
and notify_on_complete notices were lost. Startup recovers every served
home under its scope; recovery adopts each session once.
- completion delivery: background_process_notifications was evaluated once per
drain for the ambient profile (default's mode for everyone; X's `off`
dropped a sibling's `all` event), recovered watchers used the default's
mode, HERMES_BACKGROUND_NOTIFICATIONS was read raw from environ;
_deliver_platform_notice used the default's GatewayConfig so a secondary's
notice_delivery: private went public.
Not changed: gateway/run.py and tools/async_delegation.py (PR #106742
rewrites both). Known residue left for the env-bridge lane:
HERMES_SESSION_STALL_TIMEOUT is bridged once from the launch config.
scheduler bug, not a parity gap; unchanged here.
Under `gateway.multiplex_profiles` one gateway process serves every profile
under ~/.hermes/profiles/NAME/; each routed turn runs with a context-local
HERMES_HOME override while `os.environ` still holds the DEFAULT profile's
values. Anything evaluated once at import, or memoised in a single unkeyed
module slot, therefore freezes the LAUNCH profile's value and leaks it into
every other profile's turns. This lands the tools-side half of that class:
- tools/process_registry.py, tools/environments/{modal,singularity}.py:
`_checkpoint_path()` / `_snapshot_store()` resolve `get_hermes_home()` at
call time (same seam as `tools/skills_tool._skills_dir`, so the existing
`monkeypatch.setattr(CHECKPOINT_PATH)` test sites keep working). Completes
the checkpoint_manager / sticker_cache half cherry-picked from #56315.
- plugins/platforms/feishu/feishu_comment_rules.py: `_MtimeCache` is now
path-keyed (accepts a Path or a zero-arg resolver, one (mtime, data) slot
per resolved path) with `invalidate()`; `_rules_file()` / `_pairing_file()`
resolve the routed profile's files. Proposed in #63962.
- tools/tool_output_limits.py, tools/browser_tool.py, tools/browser_camofox.py:
the process-lifetime config caches are dicts keyed by `hermes_home_key()`;
the `_X_resolved` flags and the lifecycle reset keep their shape.
tools/file_tools.py drops its private `file_read_max_chars` memo and reads
the already mtime+path-cached `load_config_readonly()`.
- hermes_time.py: `get_timezone_name()`; when `is_multiplex_active()` the
env `HERMES_TIMEZONE` (bridged from the default profile's config at gateway
startup) is ignored in favour of the routed profile's config.yaml. Both
sandbox TZ sites (code_execution_env/_tool) now use it.
- tools/cronjob_tools.py, tools/tts_tool.py, tools/skill_manager_tool.py:
the static schema text is profile-neutral and `dynamic_schema_overrides=`
rebuilds the `display_hermes_home()` / create-dir hint per
`get_definitions()`, so a routed profile's model sees its own paths.
Refs #95685.
Co-authored-by: Nathan Shan <nathanielcrush51@gmail.com>
(cherry picked from commit 6d3fc6b07b3155c6196b1fd61a829283f1d7855c)
Merge upstream b1f003e186 while preserving PM runtime ownership and
Python 3.14 worker startup, Windows signing, and macOS wait recovery.
Keep retired runtime modules deleted. Port upstream updater preflight
checks into the checkout strategy and preserve live build logging.
Carry checkpoint filename handling and process recovery into the current
module layout. Regenerate locks and adapt incoming platform test markers.
Focused Python and JavaScript tests, desktop and root-test typechecks,
conflict-path lint checks, lock validation, and retired-import checks pass.
The full test suite and packaged release builds were not run.