The salvaged commit raised the managed worker's owner-link open timeout from 5 s to 60 s
(with a HERMES_WORKER_RPC_OPEN_TIMEOUT override) and retried a timed-out handshake three
times. Those retries cannot succeed against a real owner: WorkerRPC._connection mints ONE
worker-adoption ticket and every attempt resent it, while the gateway's bootstrap tickets
are single-use and expire after 30 s (gateway/runtime_bootstrap.py TTL_SECONDS, redeem()
deletes the entry). An attempt past 30 s, or any retry, is refused, and the same path
serves every idle redial during a turn, so a failing redial now took about 3 minutes
instead of 5 s while holding WorkerRPC.lock. The env knob also went against the
repo's no-new-HERMES_*-config rule.
The lost-worker disposition (worker_lost event, settled-admission reclaim) does not depend
on the handshake budget: a worker that dies in worker.adopt is now booked within one tick
either way. Sizing the handshake needs a fresh ticket per attempt and a budget within the
ticket TTL, which is its own change.
A managed worker that dies in the worker.adopt handshake writes no
worker_bound/worker_result: the gateway logged "Managed worker lost" and
returned, nothing failed the run, and the card said "running" for 49
minutes on a corpse (2026-10-22, t_f5fad63f, run 730: claim_expires 2067 s
past, last_heartbeat_at NULL, consecutive_failures 0).
D1 detection without disposition: gateway/session_kanban.record_worker_loss
writes a run-scoped worker_lost event on the board (dropped when the card
moved past that run) and session_managed_worker calls it on every loss
except a deliberate stop / stale generation.
D2 an elapsed claim lock read as "still running":
- owner_attempt_provably_over treats a SETTLED owner admission as proof the
attempt ended, instead of demanding the owner PROCESS be gone (the owner
is the live gateway, alive by design) - the reason every reclaim path
declined for 49 minutes;
- the reclaim's kill step reads a bare OSError on an absent pid as Windows
does (WinError 87), so "already gone" no longer means "termination not
proven";
- reclaims/reaps name the loss in the run error via owner_attempt_note;
- a loss charges consecutive_failures like any other crash (A3), so the
failure_limit breaker covers this class.
D3 adopt handshake budget: 60 s default, HERMES_WORKER_RPC_OPEN_TIMEOUT
override, and a TimeoutError is retried with backoff (auth/protocol errors
never are).
Tests: tests/hermes_cli/test_kanban_managed_worker_loss.py (A1-A3, D1
write side, kill-step semantics) and tests/agent/test_worker_rpc_adopt_timeout.py
(A4). 16 passed under the production interpreter.
The worker store validated a tools[] pin as exactly {version, tools}, so a pin
carrying delegation_backend raised invalid_params and left the worker's store
failed for the rest of the turn (every managed-worker test timed out).
Since #106742 every Kanban card runs in a gateway managed worker, and
ef52a09a55 removed the delegation toolset there: a delegated child needs
its own owner-registered execution (review r4224751560 / r4230769955), and
_open_child_session_db refused with worker_child_registration_required.
The rule stays; the missing owner side is built:
- child.reserve (gateway/session_worker_child.py): a worker asks on its own
fenced receipt stream. The owner verifies the parent's claim, mints the
child's session row (source subagent, parent lineage, parent profile,
_delegate_from marker) and a kind='child' execution bound to the parent's
verified pid/birth, the worker's fresh secret and the connection
principal, under the parent's id prefix. Caps come from the root
session's frozen policy (delegation.max_concurrent_children,
max_spawn_depth); a refusal or draining owner is a receipt, so the
parent's journal never sticks.
- ChildSessionStore (agent/runtime_session_child.py): the child persists
through ordinary worker.persist under its own claim, writes only its own
row, never binds the process delegation ledger, finishes on close.
- Retirement: every terminal transition of an execution (finish, loss,
settlement) retires its live children and ends their rows; an owner
restart retires old-epoch children (never adoptable) while the root alone
becomes unknown.
WORKER_DISABLED_TOOLSETS is gone because the only child path in a worker
now goes through the reservation.
Fixes#141793
Relay drives Hermes' provider and tool callbacks synchronously on its
private asyncio loop. In a managed worker, _touch_activity inside those
callbacks reached RuntimeSessionStore -> WorkerRPC on that loop, and the
#139472 guard refused it (synchronous_rpc_on_event_loop). The refusal is
sticky on the store, so later append_message / finalize writes of the
turn failed the same way and the worker died as managed_worker_failed.
The reporter's caller diagnostic on #139029 names two stacks:
relay_llm.run_callback -> interruptible_api_call -> _emit_wait_notice ->
_touch_activity, and concurrent tool dispatch -> _begin_tool_execution ->
_touch_activity. Both end in _persist_session_activity_if_due.
call_off_event_loop() (runtime_session_store) runs a synchronous write on
a one-shot worker thread when the current thread is running a loop, with
the context copied and errors re-raised. The callback already blocks that
loop, so waiting costs it nothing. The guard is unchanged. Callers:
- _persist_session_activity_if_due (both reported stacks)
- _reset_activity_labels_after_turn (same mixin, same shape)
- record_aux_usage: a sync auxiliary call inside a managed tool callback
(the async aux path already hops with asyncio.to_thread)
Tests drive the real Relay pipeline (relay_llm.execute,
relay_tools.execute), the real RuntimeSessionStore and the real guard.
Only the owner's socket is replaced.
Refs #139029
Refs #134889 (KB-2)
Refs #141321
An elevated Hermes (install, `hermes update` as admin, a gateway started from an
admin prompt) creating a dir with mode=0o700 gets CPython's protected
SYSTEM + Administrators + OWNER RIGHTS DACL, owned by Administrators. The same
user's non-elevated Desktop/gateway/CLI then gets WinError 5 inside it (#139845).
- hermes_dir_acl.make_user_dir: Path.mkdir that, only when the process is
elevated on Windows, adds an inheriting full-control ACE for the token's user
SID to every dir it created and to an existing leaf (repairs a dir an earlier
elevated run left). No-op off Windows / unelevated. Routed through it: the
gateway lock dir (scoped token locks, host rendezvous, update host
obligation), bot mailbox, gateway.lock homes, pending_messages, media/attachment
roots, process logs, spill dirs, vault, outbox, backups, home skeleton and
mkdir_under_hermes_home (logs).
- W2: acquire_scoped_lock raises ScopedLockDirUnusable when this token may not
use gateway-locks (or read a stale lock in it), logged WARNING once per dir with
the repair (`icacls DIR /reset /t`). _acquire_platform_lock parks the adapter
as non-retryable `lock_dir_unusable` naming the dir and the fix, instead of a
raw PermissionError that Telegram retried forever.
- Builds on @KoNit-K's update-time ACL repair (#139870), which re-grants the
whole home after an elevated update.
No Windows host was available: the ACL behavior is covered by
tests/test_hermes_dir_acl_windows.py (Windows CI) and needs a live retest.
Refs #134889 (W8, W2)
Refs #139845
Refs #140337
An owner close landing after the idle check (reader.is_alive()) but before ws.send() made send itself raise ConnectionClosed, and the caller got an outcome-unknown error for a request that never left. websockets 15 raises ConnectionClosed from send only before a complete frame is written (closed on entry, or the socket write failed), so the call now drops the link, redials with a fresh ticket and sends once more. Any error after a successful send (reply wait, timeout, mid-flight close) still drops the link and propagates unchanged, never resent; a failing resend is not retried again.
Refs #134889 (KB-3)
Refs #139162
Refs #139011
Code-health follow-up to the owner-connection reader: the reconnect test
waits for the reader thread to exit instead of sleeping; the reader's
catch-all (handed to the calling thread, which raises it) and the flood
fixture's 5 ms spacing (separate broadcasts are the behaviour under test)
carry reviewed health waivers.
Refs #134889 (KB-3)
Refs #139162
Refs #139011
The retained owner WebSocket was only read during a call. The owner
registers every worker connection as a live transport and broadcasts
sessions.changed to it, so a worker busy in a model call or tool piled up
more than websockets' 16-frame receive high-water mark, the library paused
socket reads, and pings and the close handshake stalled with them. The
next persistence call was then sent into a connection the owner was
already closing and failed with an unknown outcome, which the store
latches. Separately, the default 20 s client keepalive ran its own pong
deadline, so a short owner stall could close the connection inside a
call's 20 s receipt budget.
A reader thread now owns the socket for its lifetime: it discards pushed
events as they arrive and hands the reply for the one outstanding request
id (or the close exception) to the waiting caller. ping_interval=None
leaves the per-call receipt budget and the observed close as the only
liveness checks. Buffering stays bounded (library queue, at most one reply
plus a close in the hand-off queue); calls stay serialized under the lock
with per-request ids; an idle close observed before a send still redials
with a fresh ticket; any error after a send drops the connection and
propagates without a resend. Server checks still run per request.
Alternatives not taken: stopping broadcasts to worker connections would
need a new transport rule in the owner (it does not tell worker
connections apart today) and still leaves the client keepalive; an idle
timeout would add a redial per quiet stretch and still pause reads inside
the window.
Refs #134889 (KB-3)
Refs #139162
Refs #139011
WorkerRPC dialed a fresh WebSocket for every persistence call: a new
discovery, identify, single-use worker-adoption ticket and WS accept on
the owner loop each time, so a busy worker multiplied every owner stall
into owner_unavailable failures.
Keep one authenticated connection per WorkerRPC. It is discovered,
identified (self-RPC guard) and ticketed on connect exactly as each
call was; requests stay serialized by the existing lock and are now
correlated by an increasing id. Events the owner broadcast between
calls are drained before a send, which also surfaces a close the owner
sent while idle, so that case redials before anything is written. Any
error once a request may have been sent drops the connection and
propagates unchanged (ConnectionClosed / worker_receipt_timeout); it is
never resent, so the store latches it and its journal replays the
same sequence as before. No server or protocol change.
Refs #134889 (KB-3)
Refs #139162
Refs #139011
A managed worker that reaches the synchronous persistence RPC on a thread
with a running event loop gets WorkerPersistenceError
('synchronous_rpc_on_event_loop'), which the store keeps as a sticky
failure. When a best-effort writer (aux usage, the tools pin) swallows
that first raise at debug, the logs only show the later sticky failures
(append_message, flush_token_counts, turn.cleanup) and never the code
that tripped the guard.
The guard stays as it is. Before it raises, it now logs a WARNING with
the RPC method, the thread name and a module:function:line summary of the
frames above the store. The store's own frames are left out, and no
locals or argument values are logged.
A static pass over the worker's loop owners did not confirm a trigger,
so this commit only adds the diagnostic. Checked: async tool handlers via
_run_async, async aux calls (accounting is already off-loop), MCP
sampling and list_changed, the periodic lease/liveness scheduler, the
process registry, deadline helpers and smart approvals.
Refs #139029
Refs #134889 (KB-2)
Refs #139162
Main's onboarding run record (agent/onboarding_record.py) calls SessionDB.update_conversation_model_
config_value and session_ids_with_model_config_key on the agent's session_db; a managed worker's agent
gets a RuntimeSessionStore there, which lacked both (release run 38569922181:
test_store_offers_every_core_session_db_call_with_its_keywords). The worker owns exactly its session
row: the read-modify-write patches that row through the owner (None removes the key, as on SessionDB),
and the key scan answers with its own session.
Mechanism: worker.register needed only session:control, which every default
interactive ticket carries, so any local client could insert a 'registered'
compute execution for a session. Its pid/birth live only inside the hashed
adoption_digest, nothing in the live owner reaps the row, and while it stays
registered claim_session_input returns None: the drain pauses session_busy and
API/webhook/Bot observers wait on queued work until a restart turns the row
unknown (then the session refuses claims until a reset). The repo has no
interactive caller; managed workers reserve through the private
reserve_admission_worker path.
Fix (maintainer ruling: restrict to the managed worker's own launch, fail
closed): register now requires the worker-adoption capability (worker:adopt),
the same grant adopt/persist use, and the registrant pid must be this owner's
child (at most MAX_LAUNCHER_HOPS launchers below it). The worker RPC client
mints a worker-adoption ticket for register too. No new grant type.
Red on r13-base2: tests/gateway/test_worker_register_restriction.py (real
SessionAuthority + SQLite, real child process): an interactive ticket
registered a row; after the fix it and a foreign same-user pid are refused and
the owner's own child still registers.
Review: ahrazzle B1-14
A managed worker's AIAgent holds a RuntimeSessionStore as its session_db. The store is new
in this PR and was built call by call, so reviewers found the gaps one at a time (the lease
refresh's patience_s keyword, d93039f5b4a). A mechanical sweep of every <x>._session_db /
session_db / lease-facade db call in run_agent.py and agent/*.py against the store found two
more SessionDB methods the store lacked:
- latest_conversation_role: _close_durable_failed_turn's idempotence probe. The
AttributeError was swallowed by its best-effort guard, so a failed managed turn never got
its Hermes-authored boundary and the next prompt merged into the failed request.
- get_message_role: in-place compaction's held-row liveness checks
(held_archive_watermark, the absorbed-row tail count). The AttributeError aborted the
in-place commit, so a managed worker's in-place compaction always rolled back.
Both are closed, read-only receipt operations on the owner's transaction
(session.tail_role, session.row_role), scoped to the worker's own transcript like every
other worker read.
Test: tests/agent/test_runtime_session_store_surface_parity.py parametrizes over every core
call site (fails on r11-base for get_message_role, latest_conversation_role and
refresh_session_turn_lease), plus an owner-parity check of the two reads.
Review: Adolanium reg-1 (class sweep)
(cherry picked from commit 4e7b4ff8cfc23a01c6dc98f33fca64cee626b423)
DurableTurnLease.refresh_tick renews through the agent's session_db with
patience_s=min(write patience, remaining authority). In a managed worker that
session_db is RuntimeSessionStore, whose refresh_session_turn_lease had no
patience_s keyword, so the first renewal (after refresh_interval, 60s) raised
TypeError, the refresher treated it as a non-lock failure and interrupted the
turn with "Session turn lease could not be refreshed". Every managed-worker
turn longer than one refresh interval died.
Accept patience_s like try_acquire_session_turn_lease already does: the RPC
renewal is one gateway-side write, so the local write-lock patience does not
apply; the payload sent to the gateway is unchanged.
Test (red on r11-base: TypeError -> interrupt):
tests/agent/test_runtime_session_store_lease_refresh.py::test_managed_worker_turn_survives_lease_refresh_tick
Review: Adolanium reg-1
(cherry picked from commit d93039f5b4a746af4c031e08833daa067dbc0895)
RuntimeSessionStore refused any on-disk journal whose scope differed from
the constructor scope, before adopt() could ever see the authenticated
replacement assignment. After owner replacement a lost-ACK receipt
(sequence 1) therefore stayed stranded: the old epoch was fenced
(stale_epoch) and the verified new epoch was refused (outbox_scope_mismatch).
The constructor now takes the separately authenticated worker.adopt result
(adopted=). A differing journal is reconciled only when that proof names the
same execution/generation/target and the requested epoch, every other scope
field is identical, the epoch only moves forward, and a target change is
explained by a pending compression.publish. The pending entries replay
under the journal's own target with the adopted epoch, so the owner resolves
the original receipt (exact digest) instead of writing a second one, and the
constructor then requires the replayed scope to equal the adopted scope.
Without a matching proof the outbox is refused exactly as before.
agent.managed_worker.execute passes the adoption it already verified.
Review: https://github.com/NousResearch/hermes-agent/pull/106742#discussion_r4230769936
(cherry picked from commit 7995f199993375ec1b99af16da51f2412ebf4590)
The canonical owner dial (api_origin -> ws(s)://.../api/ws plus the
['hermes-gateway-v1', 'hermes-gateway-ticket.<ticket>'] subprotocol pair)
was spelled out in agent/runtime_session_store.py (WorkerRPC),
hermes_cli/gateway_client.py (connect_gateway), gateway/session_a2a.py
(forward_to_owner), and also tools/bot_live_delivery.py and
ui-tui/scripts/gateway_bootstrap.py.
hermes_cli.gateway_client already owns the ticket mint (_session_ticket) and the
viewer client, so it now owns gateway_ws_target(endpoint, ticket) and
GATEWAY_WS_PROTOCOL (re-exported from gateway.session_contract's
CANONICAL_GATEWAY_PROTOCOL, a dependency-free module). Every caller uses it and
checks the negotiated subprotocol against the constant. Same URL, same
subprotocols, same proxy=None / timeouts at each call site.
Review: https://github.com/NousResearch/hermes-agent/pull/106742#pullrequestreview-5456384314
Three hand-rolled temp+fsync+rename / directory-fsync copies duplicated
utils.atomic_write_bytes / utils.fsync_directory and lost their behaviour:
the Windows contended-rename retry, the EXDEV/EBUSY copy fallback for
bind-mounted or cross-device dirs, and symlink-preserving replace.
- agent/runtime_session_store.py _save: atomic_write_bytes(mode=0o600,
fsync_dir=True, tmp_prefix='.pending-'). Same owner-only bits (mkstemp 0600
fchmod'd before the rename) and the same file + directory-entry fsync.
- gateway/hosted_room_attachments.py _write_blob: atomic_write_bytes(mode=0o600,
fsync_dir=True, tmp_prefix='.tmp-'); the orphan sweep still reclaims the
'.tmp-' staging names after a crash.
- gateway/session_ingress_media.py: the private _sync_directory -> utils.fsync_directory.
Behaviour note: a failing directory fsync is now best-effort in all three
(utils policy; the file fsync and the rename still raise), matching what
_write_blob already did.
Red/green: test_outbox_journal_survives_a_cross_device_rename fails on the
parent (OSError EXDEV from the bare os.replace) and passes here.
Review: https://github.com/NousResearch/hermes-agent/pull/106742#pullrequestreview-5456384314
WorkerRPC dialed the owner's loopback /api/ws with the websockets
default proxy=True, so a managed worker that inherited HTTPS_PROXY (a
single-profile gateway passes its environment through unchanged) sent
worker.adopt to the proxy. A proxy that cannot reach 127.0.0.1 refused
it, the child failed before its first frame and the admission was left
unknown.
The dial now passes proxy=None, the same rule connect_gateway applies to
the same endpoint. Proven with a real refusing HTTP proxy and a real
loopback websockets owner. ALL_PROXY alone is not read by websockets, so
it never affected this dial.
Review: https://github.com/NousResearch/hermes-agent/pull/106742#discussion_r4213739424
Merge #10 brought main's transcript row identity (DB_ROW_SNAPSHOT digest,
CANONICAL_ROW adoption, stamped timestamp), which main mutates onto the
caller's message dicts in place. The owner's worker receipts still returned
the retired _canonical_content key, so an owner-run worker never learned an
adopted row and its next flush was refused for the new keys.
Receipts now carry every row-state key (None = the owner popped it, so a stale
adoption is cleared worker-side) and the worker whitelist accepts them.
Also aligns two suites with main: bulk delete reports skipped_active, and the
install-launcher tests target _hermes_cli (the DM delivery argv's launcher)
since this branch has no local bot-chat delivery lane.
Main's footgun gate now requires utf-8-sig for reads; the runtime session
journal, scheduler authority journal, group-control metadata and --query-file
reads were still plain utf-8.
- busy_input_mode over the durable FIFO (run_inbound._hm_busy_preempt): a follow-up during a running
turn still steers into it, redirects it, or ends it before admission; before, every messaging
follow-up was queued behind a turn that could hang for its whole request timeout (chaos cell
busy_interrupt_during_provider_hang: no answer in 15 s).
- Native provenance binds a credential-less plugin platform by platform + owning profile instead
of refusing it as not_found (every turn on the chaos fake platform failed RuntimeStoreError).
- Worker tools[] pin follows main's {version, tools} shape (d956f0ae57): the owner verb stores it
content-addressed like SessionDB.update_session_tool_names, and worker session reads resolve it.
- Durable webhook destination accepts main's `mirror`/`route` delivery keys (11fb429f49); the
route-test authority fixture pins a single default-profile runner.
- Desktop: the REST bridge's `connection` was shadowed by a block-scoped const, so the profile
preference hook read `undefined.mode` after every request; the core E2E process census
recognises `gateway run` backends (the app attaches through `gateway ensure` here); canonical
group labels for fr/de/es; the #119569 reducer test uses the canonical admission receipt.
The worker session-store facade had no update_session_tool_names, so
persist_agent_tool_names swallowed the AttributeError and left
sessions.tool_names NULL; the next fresh worker re-probed check_fns from
current config and forked the cached tools prefix. The facade now persists
the pin through a closed 'session.tools' receipt operation and a rebuilt
worker reads it back from the same row.
Finding: F26.
R3: `hermes -p <sec> chat`, `gateway ensure --json`, Desktop ensure, ACP attach and
WorkerRPC probed only `profiles/<sec>/gateway.sock*`. A served secondary has no socket
of its own — the multiplexer holds its gateway.lock — so discovery reported
`starting/deadline` forever and `ensure` tried to spawn a competing per-profile daemon.
`discover_gateway_endpoint` now falls through to the default root's control socket
when the profile's own is absent: the multiplexer's `identify` lists the home under
`served_profiles`, so `_endpoint(payload, home)` yields a ready endpoint whose
`profile_id` is the secondary's home and whose new `control_home` is the root.
`_session_ticket` mints against `control_home`, so the ticket is bound to the
secondary and redeemed by the multiplexer against its served set; `WorkerRPC` follows
the same discovery. `ensure_gateway_runtime` treats a starting multiplexer as the
pending owner of its named profiles instead of spawning a second gateway.
Only the live multiplexer's descriptor proves service (never a held lock alone); a
root that does not list the profile keeps the previous absent/starting verdict.