Commit Graph

60661 Commits

Author SHA1 Message Date
kshitijk4poor
e8ccfffc0b fix(browser): a shared daemon is owned only by the Hermes whose command started it
Two same-user Hermes processes can reach one daemon. Both read bu-default.pid on the default
Browser Use name, and every Hermes shares the real-profile attach session. The identity checks (uid,
module, session leader, socket-dir binding) prove what the daemon is, not who started it, so both
Hermes registered its group. Killing either one then killed the browser the other was still using.
The real-profile attach's before/after pid-file diff had the same hole: two concurrent attaches
both see the file change.

Each agent-browser and browser-harness command now carries this process's spawn tag (spawn_env:
pid plus create time). The daemon it forks inherits the tag, and _own_local_daemon /
_own_harness_daemon register a daemon only when its tag names this process
(process_identity.spawned_by_this_process; an unreadable environment fails closed). The pid-file
diff is gone. Probed on macOS against agent-browser 0.26.0: the forked daemon carries the tag.

New tests start a verified daemon tagged with another live process. Each fails with its check
removed (the daemon gets registered) and passes with it.

Reported by Greptile on #137057 (two threads).
2026-10-29 16:58:09 +05:30
kshitijk4poor
57644ec000 fix(process): a family's stop path releases its group only once the group is empty
Same class as the router fix: nine stop paths released their group from the owner-death supervisor
as soon as the leader exited, but members that ignore TERM or outlive the leader keep the group
alive. Releasing it let those members survive a later kill -9 of this process.

Lightpanda, real-profile Chrome, embedded cua-driver, the TTS command provider, dashboard WhatsApp
pairing, the raft and WhatsApp bridges, verify's app server, agent-browser session groups, and
Browser Use harness daemons stopped by --reload now go through release_process_group_once_empty.

New test stops a raft bridge whose TERM-ignoring helper survives. It fails when raft releases
unconditionally, and the group stays covered with the fix. Test seams moved from the per-module
release_process_groups name to the shared helper.

Reported by Greptile on #137057 (thread on the router).
2026-10-29 16:58:09 +05:30
kshitijk4poor
8bc78140fc fix(local-runtime): stop() after a router crash stops its surviving model children and keeps them covered
The watcher's restart backoff: llama-server crashed, its model children still run in its group.
stop() skipped _terminate_tree (the leader was dead) and then unregistered the group anyway, so the
model children were neither stopped nor covered by the owner-death supervisor: they kept their VRAM
after Hermes exited.

stop() now ends with process_identity.stop_owned_group_survivors: for a group this process still
owns it TERMs what is left, waits, KILLs, and releases the group only once it is empty. A group it
fails to empty stays registered. New test crashes a stand-in router with a live model child and
calls stop(); it fails without the fix (the child survives, timed out after 10 s).

The router-tree test's sleep loop now uses tests.waiting.wait_until.

Reported by Greptile on #137057.
2026-10-29 16:58:09 +05:30
kshitijk4poor
41d0a947f4 fix(mcp): an owned spawn racing MCP discovery no longer hands MCP the owner-death supervisor
The supervisor starts lazily, on the first owned spawn of any family (slash worker, terminal job,
...). When that lands between an MCP stdio connect's before/after child snapshots, the delta holds
the supervisor and _filter_mcp_children kept it: MCP tracked it as its own server, and teardown or
the orphan sweep would group-kill it, leaving every other owned child unreaped if Hermes then died.

_filter_mcp_children now drops this process's supervisor, matched by its live pid and its script
argv (process_identity.is_owner_death_supervisor). New test drives the race with a real owned spawn
and a real supervisor; it fails with the check removed (supervisor pid in the adopted set).

Reported by Greptile on #137057.
2026-10-29 16:58:09 +05:30
kshitijk4poor
dd9e087a19 ci(process): mark the three detached spawns main gained since the ratchet
Rebasing onto main brought three new detached spawns the ratchet flags:
- gateway exec quick commands: awaited, and the timeout/cancel path kills the group (_stop_exec_tree);
- managed session workers: covered, the worker kills its own group when its owner dies (_die_with_owner);
- runtime gateway start: a gateway daemon launch that must outlive its launcher.
2026-10-29 16:58:09 +05:30
kshitijk4poor
c2b1e4391c refactor(process): one release-once-empty helper; the kernel and slash-worker tests stop racing a loaded host
LSP, the code kernel and the slash worker each had their own "release the group once nothing in
it is left" (a killpg(pgid, 0) probe; the kernel's version also waited for reaps). They are now
one helper, process_identity.release_process_group_once_empty(pgid, proc=, timeout=). It polls
the leader so a zombie leader does not keep the group alive, waits up to `timeout` for killed
members to be reaped by init, and keeps covering a group that still has a member. LSP's async
close path probes once (timeout=0), as before.

The slash worker used to probe exactly once right after SIGKILL. On a loaded macOS host (load
25+) init had not reaped the killed members yet, so a group that was about to be empty stayed
registered (test_close_stops_the_whole_group_then_releases_it, flaky). It now waits up to 1 s,
like the kernel did.

The kernel survivor test raced too: under load the cell child's `trap '' TERM` could land after
the teardown's SIGTERM, and the 5 s escalation could SIGKILL it. The child now signals once its
trap is installed, and the test turns escalation off (the escalation is not what it pins).

New tests/hermes_cli/test_process_identity_release_once_empty.py: an unreaped empty group is
released, a live member keeps it covered, a late exit is waited for, and Windows never releases.
Teeth: forcing the helper to always release, or to never release, turns 5 tests red in the 4
touched files. macOS: the 9 owned-child files, 78 tests, 3 runs in a row, 0 flaky.
2026-10-29 16:58:09 +05:30
kshitijk4poor
d1cb5d5cbd ci(process): no new detached spawn outside spawn_owned without a reason
A child started in its own session or group (start_new_session, os.setsid /
setpgid / setpgrp, windows_detach_popen_kwargs) does not die with a SIGKILLed
Hermes: it reparents to init and runs forever. That is how every family this PR
migrates leaked. With the families on spawn_owned, this keeps the class closed.

scripts/check_detached_spawns.py (AST) flags those shapes in the production trees
unless the line, or the line above it, says `detached-spawn: ok — <why>`. It runs
in scripts/check ("detached-spawns") and as a blocking lint.yml step. The baseline
is empty: every remaining site is on spawn_owned / own_process_groups, or carries
its reason. The reasons this commit adds are the census verdicts:
- must outlive the starter on purpose: restart watchers, /update and the updater
  hand-offs, dashboard/desktop/service launches, cron and kanban workers
  (restart-safe), the update-custody watchdog itself;
- awaited with a group kill on timeout: cron scripts, rg search, the Browser Use
  CLI, update completion (holds the checkout lock fd);
- covered by its own parent guard: the compute host (compute_host._parent_guard_loop
  flushes sessions; a supervisor KILL could cut that short);
- not a spawn: the wake-word `start_new_session` config key and event field.

tests/scripts/test_check_detached_spawns.py: each shape flagged, non-detached and
commented/string shapes not, the marker opts out on its line or the line above
and nowhere else, tests and the helper are out of scope, main() fails on a new
unmarked spawn, and the repository scan is empty. Teeth: appending an unmarked
start_new_session Popen to tools/file_operations_search.py turns
`scripts/check --only detached-spawns` red (rc 1); restoring it turns it green.
2026-10-29 16:58:09 +05:30
kshitijk4poor
bcf275a675 fix(dashboard): the WhatsApp pairing bridge dies with the dashboard that started it
The dashboard's WhatsApp onboarding starts `node bridge.js --pair-only` detached
(start_new_session) and stops it on cancel, expiry or supersession. A SIGKILLed or
OOM-killed dashboard skipped all of that, so the pairing bridge kept running and kept
the session directory busy until it timed out on its own.

It now starts through process_identity.spawn_owned (purpose "whatsapp-pairing"): it
still leads its own group, and that group dies with the dashboard however the
dashboard dies. _terminate_whatsapp_pairing and the watcher release the group once the
process has exited; one it failed to stop stays covered.

tests/hermes_cli/test_owned_agent_subprocs.py: a real kill -9 owner and a live control
owner through _spawn_whatsapp_pairing_process (child + same-group grandchild gone, the
live owner's tree untouched), plus terminate releasing the group. Reverting spawn_owned
to Popen turns the kill -9 case red.
2026-10-29 16:58:09 +05:30
kshitijk4poor
dd7a47917b chore(process): mark the browser/desktop spawns that must stay detached, with the reason
The detached-spawn check flags every start_new_session outside spawn_owned. Three in this family are
deliberate, and each line now says why:

- tools/bot_desktop/runtime.py (Bot Desktop launcher: Xvnc + Xfce per profile). The screen outlives
  whichever CLI or gateway started it. `hermes computer-use screen start` exits right after start(),
  launcher.pid records (pid, create_time) so any later process reports or stops it, and the gateway's
  display watcher idle-stops it (b41c8ddfc4, 71971e9205). Owning it would kill every CLI-started screen
  the moment the CLI exits.
- hermes_cli/browser_connect.py (/browser connect launching the user's debug Chrome). It is the user's
  browser: the connection persists in BROWSER_CDP_URL and a later session re-attaches to it, and Hermes
  never stops it (d1ee4915f3 made the detach explicit on both platforms).
- tools/bot_desktop/install.py (apt/dnf under sudo). Short-lived and awaited. The group exists only so
  the timeout kill reaches the package manager.

Comments only; no behaviour change.
2026-10-29 16:58:09 +05:30
kshitijk4poor
adf564d01b fix(computer-use): the private embedded cua-driver daemon dies with the Hermes that started it (survivors after kill -9: 1 -> 0)
A session in a non-standard permission mode (unrestricted = YOLO, or bounded) gets a private
`cua-driver serve --embedded` daemon. On Linux/Windows it was a plain Popen child. Only
_EmbeddedCuaDaemon.stop() (session release / the computer_use atexit handler) ended it, and cua-driver
does not exit when its parent dies. A SIGKILLed or OOM-killed Hermes therefore left an approval-bypassing
daemon listening on its socket with nothing left to stop it.

On POSIX non-macOS the daemon is now started with process_identity.spawn_owned and released in
stop(). macOS is unchanged: there the launch goes through `/usr/bin/open` to LaunchServices, so the
daemon is launchd's child and never in our tree. Windows keeps the plain Popen (spawn_owned is a plain
Popen there; the layer-3 job object covers it). The cua-driver MCP proxy needs nothing: it is an stdio
child of the MCP SDK (already start_new_session) and exits on stdin EOF, measured 0/3 alive 0.1 s after
the owner's SIGKILL on base.

Measured on Linux (real cua-driver 0.21.0 serve --embedded, kill -9 of a real owner process):
  base:   1/1 cua-driver serve alive 8 s after SIGKILL
  branch: 0/1 alive after 0.0 s; with the owner still alive, 1/1 untouched after 6 s
Tests: the kill -9 + live-owner-control case (red when spawn_owned is reverted); the socket/ack contract
test now also pins the register at start / unregister at stop. Three existing tests that hand the
daemon a fake Popen stub the supervisor so a fake pid never reaches it.
2026-10-29 16:58:09 +05:30
kshitijk4poor
6ff702ec0d chore(process): mark the agent/plugin detached spawns that are not owned children, with the reason
The detached-spawn check (scripts/check_detached_spawns.py, from the owned-child API) flags every
start_new_session outside spawn_owned. Five sites in this family are deliberately not owned. Each
now carries a `detached-spawn: ok — <why>` marker, so the check passes without a baseline entry:

- iron-proxy daemon: meant to outlive the CLI that started it; `hermes egress stop` ends it
  through the pidfile + nonce.
- google_meet bot: reached through files across turns and stopped by meet_leave (pid in
  .active.json).
- photon sidecar: exits on stdin EOF (PHOTON_SIDECAR_WATCH_STDIN). kill -9 probe with that exact
  watch block: 0 of 1 survived; the same probe with the watch off: 1 of 1 survived.
- ddgs search worker: awaited under a 30 s cap that kills its group. Blocked reading its request
  on a stdin pipe, it exits when the owner dies (kill -9 probe: 0 of 1 survived).
- secret_sources command helper: awaited under a hard timeout (default 3 s) that kills its group.

Comments only; no behaviour change.
2026-10-29 16:58:09 +05:30
kshitijk4poor
118712327d fix(tts): a command TTS/STT provider dies with the Hermes process that ran it (orphans after kill -9: 3 -> 0)
Command providers run in their own session so the IDLE timeout (default 120 s, reset by every byte
of output) can kill the whole tree. That timer lives in the Hermes process: a SIGKILLed or
OOM-killed gateway left a stalled or long-running provider (a shell plus its synthesiser) running
forever, detached and reparented to init.

run_command_provider now starts the command through process_identity.spawn_owned (POSIX: group
leader, group handed to the owner-death supervisor, so provider_popen_group_kwargs no longer adds
start_new_session) and releases the group once the command has exited or the idle kill stopped it.
Windows keeps its CREATE_NEW_PROCESS_GROUP | CREATE_NO_WINDOW flags and taskkill tree kill.

Measured on Linux, owner killed inside the idle timeout, 6 s settle: origin/main 3 of 3
survived; this commit 0 of 4 descendants. New kill -9 / live-owner case and an own-then-release
test (success and idle kill); reverting spawn_owned to the main-era Popen turns the kill -9 case
red. Existing spawn-kwargs tests now patch the module's spawn_owned seam.
2026-10-29 16:58:09 +05:30
kshitijk4poor
b4031c37c8 fix(verify): a verify run's app server dies with the Hermes process running it (orphans after kill -9: 3 -> 0)
`hermes verify`'s start phase launches the project's dev server (recipe.start, a shell string) in
its own session and polls readiness for up to 60 s. Killing the Hermes process mid-poll (SIGKILL,
OOM, a closed terminal) skipped the finally that killpg()s it, and the detached group (shell + server
+ its workers) kept running on the port forever.

_run_start_phase now starts it through process_identity.spawn_owned: still a group leader for the
existing group teardown, and the group goes to the owner-death supervisor. It is released once the
teardown has stopped it (a group that survived the teardown stays covered).

Measured on Linux, owner killed mid-readiness-poll, 6 s settle: origin/main 3 of 3 (sh +
two workers) survived; this commit 0 of 4 descendants. New kill -9 / live-owner case and an
own-then-release test; reverting spawn_owned to the main-era Popen turns the kill -9 case red.
2026-10-29 16:58:09 +05:30
kshitijk4poor
9c0641eb47 fix(raft): the raft bridge dies with the gateway that started it (orphans after kill -9: 1 -> 0)
`raft agent bridge` was a plain Popen child of the gateway. A SIGKILLed or OOM-killed gateway
reparented it to init, where it kept polling Raft and posting wakes to a channel endpoint nobody
serves, forever. The next gateway starts a second bridge beside it.

_spawn_bridge now starts it through process_identity.spawn_owned (its own group, handed to the
owner-death supervisor, recorded in the spawn ledger as "raft-bridge"), and _stop_bridge releases
the group once the bridge has exited (a bridge it failed to stop stays covered).

Measured on Linux, real adapter _spawn_bridge with a stand-in `raft` CLI, owner SIGKILLed,
6 s settle: origin/main 1 of 1 survived; this commit 0 of 2 descendants (bridge + supervisor).
New kill -9 / live-owner case and a _stop_bridge release test; reverting spawn_owned to the
main-era Popen turns the kill -9 case red. test_raft_adapter's multiplex test now patches the
adapter's spawn_owned seam.
2026-10-29 16:58:09 +05:30
kshitijk4poor
73804ca2f9 fix(whatsapp): the Node bridge dies with the gateway that started it (orphans after kill -9: 1 -> 0)
The bridge is spawned detached (start_new_session, via windows_detach_popen_kwargs) so a container
stop reaches it directly (#127047). Detached also meant a SIGKILLed or OOM-killed gateway left it
running forever: still holding the port and the logged-in WhatsApp session, serving a /messages
queue nobody polls. The next gateway's connect() only recovers it if the bridge reports the same
session, script hash and read-receipt config; otherwise it kills it through the pidfile or port path,
or with a foreign profile on that port refuses to start.

The bridge now starts through process_identity.spawn_owned (_spawn_bridge_process): it still
leads its own session, and its group goes to the per-process owner-death supervisor, so it dies the
moment the gateway dies, however it dies. disconnect() releases the group once the bridge has exited.
A bridge it failed to stop stays covered. Windows keeps its detach flags (windows_detach_flags)
and its taskkill tree kill unchanged. The pidfile / port reaping for bridges left by older versions
stays: it covers bridges this process never owned.

Measured on Linux, real node bridge stand-in, owner SIGKILLed, 6 s settle:
origin/main 1 of 1 bridge survived; this commit 0 of 2 descendants (bridge + supervisor).
tests/hermes_cli/test_owned_agent_subprocs.py: a real kill -9 owner and a live control owner
through _spawn_bridge_process (child + same-group grandchild gone in 15 s, the live owner's tree
untouched), plus disconnect() releasing the group. Reverting spawn_owned to the main-era Popen turns
the kill -9 case red. Existing connect / stale-bridge tests now patch the adapter's spawn_owned
seam instead of the global subprocess.Popen, which also starts the supervisor.
2026-10-29 16:58:09 +05:30
kshitijk4poor
755a280ff0 fix(processes): a background job dies with the Hermes process that started it (orphans_after_10s 3 -> 0); persist_on_release jobs still outlive it
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.
2026-10-29 16:58:09 +05:30
kshitijk4poor
63519c9a74 fix(terminal): a foreground command dies with the Hermes process that ran it (orphans_after_10s 2 -> 0)
Symptom: LocalEnvironment._run_bash starts every terminal command in its own session
(start_new_session=True, so the TERM->KILL group teardown reaches its children). Nothing reaps that
group when the Hermes process dies without running its cleanup (SIGKILL, OOM killer, crash): the
command and everything it started reparent to init and keep running. Measured on Linux (tbg_probe:
an owner runs `sleep 305` in env.execute() on a thread, owner gets kill -9, check at +10 s): bash and
sleep 2/2 alive, 2/2 runs.

Change: _run_bash hands the command's group to the owner-death supervisor
(process_identity.own_process_groups; pipe EOF -> TERM, 3 s, KILL). LocalEnvironment._wait_for_process
releases it once the wait returns, by any path (exit, timeout, interrupt), so what a command
deliberately leaves in the background after it returns (`server &`) keeps its current behaviour, the
same as a graceful exit. Not spawn_owned: an awaited command needs no spawn-ledger entry. Windows is
unchanged (the layer-3 job object). The existing TERM->KILL teardown, the setsid-escapee sweep and the
start-time PID-reuse guards stay: they cover a live owner.

Result: same probe, 3/3 runs: 0/2 alive. Per-command cost with the supervisor resident: own+release is
0.02 ms (3.4 ms when it has to start the supervisor); env.execute("true") 20.8-24.2 ms on the base vs
22.4-23.4 ms here, inside load noise. New tests/tools/test_terminal_owned_jobs.py (kill -9 owner vs live
control owner; a returned command releases its group): green x3, both red on the pre-change code and red
on their own mutation (no own / no release). test_local_env_cwd_recovery fakes subprocess.Popen, so its
class now stubs the supervisor calls.
2026-10-29 16:58:09 +05:30
kshitijk4poor
f3ebdfadbd fix(tui): the slash worker's process group dies with the gateway that owns it (orphans_after_30s 1 -> 0)
Symptom: when a TUI/Desktop gateway was SIGKILLed or OOM-killed while a slash worker ran a quick
command (`type: exec`, shell=True, up to 30 s), the command's shell and its children outlived
everything. The worker's own ppid watchdog (slash_worker._start_parent_death_watchdog, firefly
8b6a8f667d) only ends the worker: it polls for 2 s, waits up to 5 s for the in-flight command, then
os._exit()s, leaving the worker's group members to init. A normal close had the same hole:
_SlashWorker.close() signalled the worker pid alone, so closing a session mid-command left the
shell running too.

Change:
- _SlashWorker spawns the worker through process_identity.spawn_owned(purpose="slash-worker"): the
  worker still leads its own session (the reason it had start_new_session=True: mcp_tool's orphan
  sweep must never killpg the gateway's group), and the group now goes to the gateway's owner-death
  supervisor, so it dies the moment the gateway dies by any cause.
- close() TERMs, waits 1 s, then KILLs the worker's whole group, and releases it from the supervisor
  once the group is empty. A group is only signalled while its leader was alive on entry, so a dead
  worker's recycled pgid is never signalled; a group with survivors stays covered.
- The worker's ppid watchdog, its env knobs (HERMES_SLASH_WATCHDOG_POLL_S/_GRACE_S), --parent-pid
  plumbing and the in-flight event go: the supervisor reaps the worker AND its group, at the moment
  of death instead of 2-7 s later, with no thread per worker. --parent-pid is still accepted
  (suppressed) so a gateway started before an update can spawn the updated worker.
- Windows keeps its existing path (terminate/kill on the Popen; the layer-3 job object covers
  ownership).

Measured on Linux, real _SlashWorker + real worker, owner kill -9, survivors at t+30 s:
  idle worker:            main 0, branch 0
  worker running a quick: main 1 (`sleep 300`, alive at +30 s), branch 0 (gone by +2 s; the worker
                          itself took 5-10 s on main)
  close() mid-command:    main 1 survivor, branch 0

Tests: test_slash_worker_owned.py (live kill -9 of a real owner, with a live-owner control whose
worker must survive; close() stops a TERM-ignoring group then releases it; a dead worker's group is
never signalled; legacy --parent-pid accepted). Reverting spawn_owned to Popen fails the kill -9
test; reverting close() to signal the leader only fails the close test. The watchdog's unit tests
(test_slash_worker_watchdog.py) go with the watchdog; the cli-before-MCP-discovery ordering test
moves to the new file.
2026-10-29 16:58:09 +05:30
kshitijk4poor
eb834d16f2 fix(execute_code): a kernel's cell subprocesses die with the Hermes process that ran them (orphans_after_10s 3 -> 0)
Symptom: the POSIX death pipe (365e2835d4) only told the KERNEL its host had died. Every subprocess a
cell starts (a dev server, a `sleep`, a training job) shares the kernel's process group and never sees
that pipe, so a SIGKILLed / OOM-killed host left them running on init indefinitely. Measured on Linux
against origin/main 7770e397f3 (ck_probe: host spawns a kernel, the cell Popen()s `sleep 300`, host
gets kill -9, check at +10 s): kernel 0/3 alive, cell child 3/3 alive.

Change: _spawn starts the kernel through process_identity.spawn_owned(purpose="code-kernel"): it leads
its own group (as before, via start_new_session), that group goes to the per-process owner-death
supervisor, which killpg()s it the moment the host dies by any cause, and the kernel is recorded in
the spawn ledger. teardown() releases the group once it is empty (waiting up to 1 s for SIGTERMed
cell children to exit); a cell child that survives the teardown's SIGTERM keeps the group registered
until it exits. The kernel-only death pipe (runner watchdog thread, pipe plumbing,
HERMES_KERNEL_PARENT_DEATH_FD) is deleted: the supervisor kills the kernel too. Windows keeps its
SYNCHRONIZE-handle watchdog unchanged; atexit graceful shutdown, the idle reaper and the
stale-staging-dir sweep stay (they cover a live host and disk, not owner death).

Result: same probe, 3/3 runs: kernel 0 alive, cell child 0 alive. tools/code_kernel.py +25/-57.
New tests/tools/test_code_kernel_owned_group.py (kill -9 owner vs live control owner, graceful
release, surviving-child coverage): 3/3 green x10 runs, all 3 red on the pre-change spawn, each red
on its own mutation (no registration / no release / unconditional release). Family files on main
75 passed; on this branch 78 passed (75 + 3 new).
2026-10-29 16:58:09 +05:30
kshitijk4poor
3d24fce471 fix(lsp): a language server's whole process tree dies with its Hermes owner (orphans_after_30s 1 -> 0)
Symptom: LSPClient starts every language server in its own session (start_new_session=True) so a
killpg aimed at the server can never reach Hermes. That also took the server's descendants out of
Hermes's kill domain. The server itself exits on stdin EOF when Hermes dies, but a descendant that
neither holds nor watches that pipe (a wrapper's background child, a SIGTERM-ignoring worker)
outlived a SIGKILLed / OOM-killed Hermes forever. The atexit hook and the idle reaper both live
inside the owner, so neither runs on that path.

Change: _spawn hands the server's process group to the per-process owner-death supervisor
(own_process_groups) and records it in the spawn ledger (register_child "lsp-server").
_cleanup_process hands the group back only once nothing in it is left, so a member that survived
teardown stays covered and still dies with Hermes. No new process: the supervisor is shared with
every other owned child. The atexit hook stays: it runs the LSP shutdown/exit handshake on a
clean exit, which the supervisor's TERM/KILL does not replace. Windows path unchanged.

Measured on Linux (Linux), kill -9 of a real owner running LSPClient, survivors of the server
tree after 30 s:
  mock server with a SIGTERM-ignoring child (slow_tree), 3 trials: main 1/2 alive every trial,
  branch 0/2 every trial (gone by +5 s).
  basedpyright, pylsp, typescript-language-server (4 procs), gopls, rust-analyzer: 0 on main and
  branch (they exit on stdin EOF, and their helpers die with them).

Tests (tests/agent/lsp/test_lsp_owned_server.py): owned on spawn + released on shutdown, a
surviving member keeps coverage, a real kill -9-the-owner end to end, and a live-owner control.
Removing the own_process_groups call turns 3 of them red; making the release unconditional turns
the coverage test red.
2026-10-29 16:58:09 +05:30
kshitijk4poor
7da67cfac1 refactor(process): spawn_owned is the one way to own a child; own/release replace the verb string
Names the owned-child API in process_identity layer 4:

- spawn_owned(argv, purpose=..., **popen_kwargs): starts the child as a session/group leader,
  hands the group to the owner-death supervisor and records it in the spawn ledger.
- own_process_groups(pgids) / release_process_groups(pgids): for groups something else spawned
  (MCP SDK servers, agent-browser's Chromium, harness daemons) and for children the owner stopped
  itself.

The stringly update_supervised_pgids("register"/"unregister", ...) becomes the private protocol
writer. llama-server's spawn_server(owned=True) now goes through spawn_owned instead of
re-spelling it. Adds a contract test for spawn_owned (group leader, supervisor registration,
ledger entry, release); it goes red when the registration is removed.
2026-10-29 16:58:09 +05:30
kshitijk4poor
bcec3f8a2f fix(process): the owner-death supervisor's control pipe pins encoding=utf-8
text=True without encoding= decodes with the ANSI code page on Windows (#55658); CI's
test_text_mode_subprocess_calls_pin_utf8 caught it on process_identity.py.
2026-10-29 16:58:09 +05:30
kshitijk4poor
9857b35c22 fix(process): log a supervisor that will not exit on release; the SIGKILL daemon test waits on the condition
Narrow the release-time wait to subprocess.TimeoutExpired and log it, instead of a silent blind
except (health BLE001/S110). subprocess becomes a top-level import. The Browser Use kill -9 test
polls with tests.waiting.wait_until rather than a hand-rolled sleep loop (HX013).
2026-10-29 16:58:09 +05:30
kshitijk4poor
6139223158 fix(browser): Browser Use harness daemons die with the Hermes process that drove them (orphans_after_30s 2 -> 0)
browser_harness detaches its daemon on purpose (start_new_session) so a session persists across
browser_exec calls, and the daemon has no idle exit. A SIGKILLed or OOM-killed Hermes therefore
left every daemon it drove running forever, each holding a CDP connection (#121095). A clean exit
leaked them too: stop_harness_daemons() only ran from cleanup_all_browsers(), which the atexit
handler calls only when an agent-browser session was tracked, and a browser_exec-only process
never tracks one (measured: 4 of 4 daemons leaked after the owners exited normally).

After each browser_exec, the daemon behind its BU_NAME is handed to the per-process owner-death
supervisor. The harness publishes the daemon pid in its runtime dir; it is accepted only while it
is this user's live `python -m browser_harness.daemon` leading its own session, so a stale or
planted pid file can never put a stranger's group in front of the supervisor. stop_harness_daemons()
releases the groups it stopped, and the atexit handler now calls it unconditionally.

Replaces the per-family reaper of #120739 (trevornk, owner-pid claim files + a janitor sweep of
dead-owner daemons, +1150 lines): the owner dying is detected by the shared supervisor at the
moment it happens, not by the next Hermes that happens to start the browser janitor, and the live
control daemon of another Hermes is never in this process's registry at all. The claim-file idea
(trevornk) and the per-owner-dir idea (#129655, mheals / Diaspar4u) are what this keys on: the
daemon's own pid file under the runtime dir the CLI ran with.
2026-10-29 16:58:09 +05:30
kshitijk4poor
97bef249ac fix(local-runtime): the llama-server tree dies with its owner on POSIX too (orphans_after_30s 2 -> 0)
On Windows the router lives in a KILL_ON_JOB_CLOSE job, so an owner crash takes the router and its
multi-GB model children down with it. On macOS/Linux spawn_server was a plain Popen: SIGKILL or
OOM of the owner left the whole tree resident on launchd/systemd until the next boot's recovery
pass (#126631). The idle sweeper and the crash watchdog both live inside the owner, so nothing
that could unload the model survives it.

spawn_server(owned=True) is the POSIX counterpart of the job: the router leads its own process
group (llama.cpp's router spawns model children with posix_spawn and no setpgid, so they stay in
it) and the group goes to the per-process owner-death supervisor, which killpg()s it the moment
the owner dies, by any cause. stop() releases the group after it has terminated the tree. No
extra process per router: the supervisor is shared with every other owned child of the process.

Same goal as #126657 (liuhao1024, a per-owner psutil poller re-checking (pid, create_time) every
2 s), reached through the shared supervisor instead: measured +6.6 MB USS per owner there, one
shared ~0.5 MB sh here, and the reap is immediate instead of up to one poll late.
PR_SET_PDEATHSIG is not an option: it fires when the spawning THREAD exits, and the router is
spawned from short-lived threads (lr-on-demand-boot, watchdog restarts).
2026-10-29 16:58:09 +05:30
kshitijk4poor
d66b9cd9ce refactor(process): one owner-death supervisor per Hermes process, in sh, owned by process_identity
The parent-death supervisor that only stdio MCP servers could use (tools/mcp_death_supervisor.py
+ the client in tools/mcp_tool.py) becomes layer 4 of hermes_cli/process_identity.py, next to the
spawn ledger and the Windows job object, so every long-lived child family can use the same path
instead of shipping its own reaper. MCP's three call sites now call
process_identity.update_supervised_pgids; the protocol (register/unregister <pgid>, EOF = owner
died, TERM -> 3 s -> KILL, unsafe targets refused, replay on respawn, release when empty) is
unchanged and every existing contract test moves with it.

The supervisor itself is now POSIX sh (hermes_cli/process_supervisor.sh) instead of a second
CPython: it stays resident for the life of any Hermes process with a supervised child, and an
idle sh is 0.5 MB USS against 8.1 MB for the Python supervisor (Linux, py3.14, measured).
Malformed and over-long lines are skipped exactly as before; the only protocol difference is
that a line is no longer length-capped while being read (sh's read has no cap), which only a
writer inside Hermes could exploit.
2026-10-29 16:58:09 +05:30
kshitijk4poor
f398ff59b8 test(cli): pin the reader-first ordering in the unretrieved-future test
Assert the reader finished before the send raised, so a wrong ordering
fails the test instead of passing it vacuously. Restore the loop's previous
exception handler instead of clearing it.
2026-10-29 16:30:39 +05:30
kshitijk4poor
679ec082c8 refactor(cli): one builder for a turn the owner never saw; pin the unretrieved-future fix
The pre-submit notice and the never-sent submit return the same unadmitted
result. GatewayAgent._unadmitted now builds it for both: it gives the
/model --once pick back, writes no history row and sets admitted=False.
The notice path had nothing to give back, so behaviour there is unchanged.

New test: a send that raises after the reader has failed its request logs
no 'Future exception was never retrieved'. It fails without the
future.exception() call in rpc's finally. The comment on that line now
says what it is for.
2026-10-29 16:30:39 +05:30
kshitijk4poor
d72b65595e fix(cli): a closing socket refuses before the send, and an unsent prompt keeps its turn
Three fixes from review:

- A keepalive timeout fails the socket into CLOSING. websockets then waits
  up to close_timeout (10 s) for the peer before the reader ends. A send in
  that window is never written, but it used to block the caller for that
  long and then report DISCONNECTED. GatewayClient.rpc now refuses with
  NOT_SENT whenever the socket isn't OPEN. Live probe with a silent peer: it
  now answers in 0.0 s with NOT_SENT; the previous head took 5.4 s, reported
  DISCONNECTED and logged "Future exception was never retrieved".
- When prompt.submit gets NOT_SENT, the turn is handled like a pre-submit
  notice: the /model --once pick goes back, no history row is written, and
  the result carries admitted=False. "Nothing was sent" is then true for the
  resend too.
- rpc reads the exception of a future the reader failed while the send was
  raising, so asyncio no longer logs it as never retrieved.

The test fakes for GatewayClient sockets now carry `state = State.OPEN`,
which every real websockets connection has.
2026-10-29 16:30:39 +05:30
kshitijk4poor
7303b01fd6 fix(cli): a request after the gateway socket closed is reported as not sent
When the keepalive times out, the socket closes and GatewayClient's reader
ends before the dock's next poll. websockets refuses any later send on that
socket without writing it, so the frame never leaves. GatewayClient.rpc now
raises NOT_SENT once the reader has ended, instead of DISCONNECTED ("turn
outcome is unknown; do not resend"). A prompt.submit that hits this path
tells the user nothing was sent, so they know to send it again. A send that
fails while the reader is still alive stays DISCONNECTED, because the frame
may already have left.

NOT_SENT moves next to DISCONNECTED in gateway_client; gateway_connection
imports it, so gateway_queue's `str(exc) == NOT_SENT` check is unchanged.
2026-10-29 16:30:39 +05:30
Teknium
2a5aa2a406 refactor(cli): one copy of the gateway-disconnected text
The salvaged fix added a second copy of the "turn outcome is unknown" text in
gateway_client next to gateway_connection's DISCONNECTED. Keep the one
definition in gateway_client (the lower module) and import it into
gateway_connection, so the send-side, read-side and connection-loss errors
cannot drift apart.
2026-10-29 16:30:39 +05:30
Turgut Kural
7e7d9a043d fix(cli): a send on a dead gateway socket no longer kills the spinner thread
GatewayClient.rpc let websockets' ConnectionClosedError escape from send():
after a keepalive ping timeout the dock's subagent.list poll raised it past
callers that catch GatewayClientError, and the bare spinner loop died with it,
leaving the spinner and live-work dock frozen for the rest of the session.

rpc now reports a failed send as the same unknown-outcome GatewayClientError a
lost answer already gets, and the monitor tick skips a beat on a failure
instead of ending the thread that runs it.

(cherry picked from commit ea136305ac597dcd62bc569426321d9d601034aa)
(cherry picked from commit cedb79f9a691f9ef9b8f3d9c04fdfefb63d9fb94)
(cherry picked from commit f5c1b54199dc02e9654a6d11ba6ee5e0e2a84cc4)
2026-10-29 16:30:39 +05:30
Teknium
ef75bc7088 fix(plugins): quoted /proc redirects stay writes; own-module from-imports stop warning
Greptile on #146352: `printf x > "/proc/self/comm"` slipped past the write check because the
redirect form required an unquoted path, and `from plugins.memory.<name> import _db` still warned
because only the module part was matched against the plugin's own files. Both now covered, with
attack/false-positive twins red on the previous head.
2026-10-28 23:07:47 -07:00
Teknium
04cd9ac3fa fix(plugins): bound the /proc write check, see r+/rb+/O_WRONLY writes, drop the raw env copy
Independent review: the open(...)[wax+] branch of the /proc write check went quadratic on long
lines with many open( and no ). Bound the argument scan to 300 chars, require a quoted mode, and
treat r+/rb+ and os.open O_WRONLY/O_RDWR as writes. The bytecode ls-files call no longer passes a
raw os.environ copy (spawn-env guard).
2026-10-28 23:07:47 -07:00
Teknium
0040f02b5c fix(plugins): clear catalog sweep 1028 scanner false positives and close three validator gaps
Install scanner (tools/plugin_guard*, PLUGIN_SCANNER_VERSION bumped once):
- hardcoded_secret: a PostHog project key (phc_, write-only ingest key) joins the
  Google installed-app secret as a public client key -> high (caution), only
  when every matched literal on the line has a public prefix (telesec
  telemetry.py:27 was dangerous). phx_ personal keys and any other token stay
  critical.
- proc_access: reads of /proc/self|<pid>/{cgroup,mountinfo,stat,status,...}
  (container placement, pid start time) land at low instead of high
  (hermes-lcm-x cpu_capacity.py was caution). environ, cmdline, mem, maps, fd,
  root/cwd, ns, bare /proc/self, any unlisted leaf and any write keep high.
  Generalises #144304's cgroup/mountinfo allowance and keeps the finding
  visible instead of dropping it.
- bytecode_file: a committed .pyc/.pyo (git ls-files; plus any bytecode outside
  __pycache__) is a high structural finding, the binary_file tier (rule 17;
  hermes-emotion shipped tests/__pycache__/*.pyc and scanned safe). Untracked
  caches the validate run writes are not flagged.

Validator (hermes plugins validate, warnings only):
- private imports: gateway.session_context.get_session_env is the documented
  route (plugins/index.md) and a plugin's fallback import of its own install
  path (plugins.memory.openltm._db) is not a core import.
- new warning for private-method calls on core handles (SessionDB, AIAgent,
  GatewayRunner, PluginContext) the plugin does not define itself
  (opencode-sync db._execute_write, runner._evict_cached_agent).
- desktop surface review warning for raw window.hermesDesktop calls and app
  markup selectors ([data-slot], [data-tree-*], [data-pane-host]) in CSS text
  or closest() (squad-hub, novel-reader, search-sources).
2026-10-28 23:07:47 -07:00
Sahil Vishnalya
1bb5b3d67b fix(plugins): allow read-only /proc/self/cgroup and mountinfo in plugin guard
Container CPU-quota detection needs the process's cgroup membership and mount layout, and language runtimes read them for container resource discovery. proc_access flagged the plain reads as high, so a plugin that sizes local work inside a container scanned CAUTION and unattended updates stopped (#144123).

Drop the finding only when every /proc path on the (logical) line is one of those two reads: a write, any other proc path or a bare /proc/self keeps it. Scanner version bumped so quarantined pins are re-scanned.

(cherry picked from commit 481c5ca3bfa9c4c68547144b141a2f2acd8afc48)
2026-10-28 23:07:47 -07:00
Teknium
2f5c7e89b7 test(codex): the full-picker case leaves no background usage refresh for a later case to record
build_model_options_payload() spawns a daemon account-usage refresh that sends the
case's ChatGPT JWT through httpx.Client after the test returns; under CI load it
landed inside test_image_request_goes_to_the_pool_entry_gateway's patched client and
added chatgpt.com to its recorder. Stub the refresh like the other unrelated metadata
sources and assert no background worker attempts HTTP.
2026-10-28 23:00:54 -07:00
Tommy Liu
6dcf8d2fb3 docs(providers): pin the Modular plugin to 6a80b25
The plugin now serves DeepSeek V4.1 Flash under its new id,
deepseek/deepseek-v4.1-flash-1017.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 23:00:18 -07:00
Tommy Liu
7d6877ddb9 docs(providers): add Modular model-provider plugin to catalog
Adds a catalog entry for the standalone Modular Cloud model-provider
plugin (tommyjtl/hermes-modular-provider), pinned to its release commit,
and maps the commit email to its GitHub login.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 23:00:18 -07:00
Teknium
acaf16c4ce chore: map contributor email for dbrosnan 2026-10-28 22:59:45 -07:00
Drew Brosnan
30d33275ce feat(plugin-catalog): pin signal-notify to v1.0.0 release 2026-10-28 22:59:45 -07:00
Drew Brosnan
b776dee3ba feat(plugin-catalog): add signal-notify 2026-10-28 22:59:45 -07:00
Teknium
8ac58efc2a chore: map contributor email for lgc2333 2026-10-28 22:59:12 -07:00
Teknium
40f28097c3 chore(catalog): review disclosure for transcription-dashscope 2026-10-28 22:59:12 -07:00
LgCuwukii
13fa2ff02a feat(plugin-catalog): add transcription-dashscope
DashScope (Qwen AI Platform) speech-to-text provider, pinned to
lgc2333/hermes-plugin-transcription-dashscope at fe83a51 (v0.1.0).
2026-10-28 22:59:12 -07:00
Teknium
294a8f1ab4 chore: map contributor email for shuruheel 2026-10-28 22:58:39 -07:00
Teknium
56c0553c9e chore(catalog): review disclosure for mindgraph 2026-10-28 22:58:39 -07:00
Shan Rizvi
3c368d3ea8 plugin-catalog: bump mindgraph to 1.0.0
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 22:58:39 -07:00
Teknium
c8d0c1dd08 chore: map contributor email for g3org3yo 2026-10-28 22:58:02 -07:00
Georgios Kaukas
53ad20e1da catalog: add perf-hud entry
Adds the Perf HUD plugin (v1.0.0, pinned to
bb97f8f73175a22b75f21204cf9fd4394f18077b): a status-bar chip with
core-compatible TPS and a statistics popover with TTFT, LLM calls,
tokens, cache hit rate, tool time, session duration and optional local
history. Observer hooks only; no core changes, no network requests, no
stored content.
2026-10-28 22:58:02 -07:00