Commit Graph

10 Commits

Author SHA1 Message Date
unsupportedpastels
dfe5b10677 fix(gateway): compare a managed worker's birth by its kernel start on Linux
On Linux psutil's create_time() is the cached /proc/<pid>/stat start ticks
plus boot_time(), and psutil 7.2.2 re-reads /proc/stat btime on every call.
WSL2 re-anchors btime after host sleep, so the owner's read of a live
worker's birth drifted from the one the worker reported in its hello, and
the exact-equality fences (reservation, worker.adopt/persist, delegation
dispatch, the launcher signal and the Kanban owner receipt) refused it:
every Kanban card, cron run and subagent ended permission_denied.

worker_birth() reads the kernel start ticks since boot
(create_time(monotonic=True)) on Linux and keeps process_birth() elsewhere;
every managed-worker identity fence now uses it. The spawn ledger keeps
process_birth() so its persisted epoch births still match after an update.
An owner_admitted receipt written before this change reads as another
process: its reclaim pauses, the fail-safe direction.

Refs #143547

Co-authored-by: Sebastian Hänisch <5960303+TKCen@users.noreply.github.com>
2026-10-25 19:25:17 -04:00
Teknium
bf2b3713ab fix(managed-worker): delegate_task works in Kanban workers through owner-reserved children
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
2026-10-20 03:22:11 -07:00
Teknium
ffbeb735f1 fix(gateway): compare a managed worker's birth by its kernel start on macOS
On macOS psutil shifts create_time() by abs(INIT_BOOT_TIME - boot_time()),
using a boot-time reference frozen when psutil was imported in the
calling process. After a clock step (NTP, sleep/wake) a long-lived
gateway owner reads a different birth for a fresh worker than the worker
reports itself, so verify_worker_identity's exact match refused every
managed worker with permission_denied until a gateway restart.

hermes_cli.process_identity.process_birth reads the unadjusted kernel
start (create_time(monotonic=True)) on macOS and plain create_time()
elsewhere (Linux and Windows apply no per-process reference). Every site
that writes or checks a worker birth now uses it: the worker's hello,
the reservation, the worker.adopt claim, the delegation dispatch check,
the verified-interpreter signal, and the Kanban owner binding with its
reclaim check. The match stays exact, so a forged birth is still refused.

#140612 undoes the shift arithmetically (birth - diff). psutil applies
abs(diff), so for a backward step that doubles the error instead of
removing it, and the other birth sites stay exact on the drifting value.
The new test emulates both step directions on every platform.

Refs #134889 (KB-6)
Refs #140580
Refs #140719
2026-10-18 03:24:13 -07:00
Teknium
8376dc7614 fix(gateway): worker.register accepts only the owner's launched worker
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
2026-10-11 19:31:35 -07:00
Teknium
6f86a36cc1 fix(gateway): a retired authority refuses its own mutators and worker writes
b9a7337821f fenced cron and the Bot relay verbs on a retired authority
(require_serving). The authority's own mutators reached through a stale
connection (submit, cancel_queued, resolve_unknown, mutate, attach) all pass
SessionAuthority.authorize first, and a managed worker's adopt/persist goes
through worker_request: until a successor runs begin_runtime_epoch the retired
epoch still passes the store fence, so each of those could still commit into
the home the profile released. authorize() and worker_request() now call
require_serving first (runtime_retired). `retired` is initialised in __init__.

Also: test doubles of the authority used by the retire/shutdown tests gain the
`adopted` map stop_authority_turns now reads (beea566de7); production
authorities always carry it.

Test: test_retired_authority_refuses_writes_before_successor_epoch gains
authority.cancel_queued, authority.submit and worker.adopt rows; all three
fail on the previous head.

Review: andrexibiza 5479692359 P1.6, andrexibiza 5480238075 #4 (retired-authority-mutator-fence)
2026-10-10 22:53:35 -07:00
David Dudok de Wit
e32a886e1d fix(worker): retain persistence and ownership through physical shutdown
Keep reserved workers able to persist during drain, join actual in-process writers before releasing a profile, and reap children created after cancelled process acquisition. Reopening a worker outbox reconciles its pending receipt; managed results retain per-turn usage and bounded live tool details.

This commit contains the physical-worker foundation only. Mutation-task and Bot mailbox lifetime tracking are separate follow-ups. The existing zero-second restart drain default is unchanged.

Validation: scripts/run_tests.sh -j 4 across 10 worker/runtime files: 26 passed, 1 POSIX-only skip on native Windows. Includes a real managed child completing its durable receipt during a configured restart drain. The unchanged upstream one-second retirement test missed its deadline once under parallel load and passed the runner retry; an isolated rerun passed both cases without retries. Logs: split-W-tests.log, split-W-retirement-rerun.log.

Review-source: helix4u, https://github.com/NousResearch/hermes-agent/pull/106742#issuecomment-6024687448
Review-source: greptile-apps, https://github.com/NousResearch/hermes-agent/pull/106742#discussion_r4211047305
Review-source: greptile-apps, https://github.com/NousResearch/hermes-agent/pull/106742#discussion_r4211047387
Review-source: greptile-apps, https://github.com/NousResearch/hermes-agent/pull/106742#discussion_r4213427126
Review-source: dokterdok, https://github.com/NousResearch/hermes-agent/pull/106742#discussion_r4211144039
Source-base: NousResearch/hermes-agent#106742 at 0b815190b2
(cherry picked from commit 6156b21c5e3fa5e9295a13d5e02caa9b959ada82)
2026-10-08 09:10:26 -07:00
Teknium
58d8b41ee3 fix(gateway): messages queued behind a running worker are acknowledged and run when it ends
`claim_session_input` returns None both for an empty FIFO and for one whose
head is blocked by a live `registered`/`running` worker execution. The drain
treated both as "done" and exited without `_pause`, so a messaging adapter's
delivery waiter (`admit_message`, no timeout) stayed parked on a turn that
could not run, breaking `_pause`'s invariant. When the worker later sent its
durable `execution.finish`, nothing called `_schedule`, so the queued input sat
until an unrelated submit or cancel happened.

The drain now tells the two apart: it read a queued head, so a None claim
means blocked, not empty. It pauses with `session_busy`: the waiter is
released with a transient "saved, will be answered when the running work
finishes" notice (one per pause episode), and the row stays queued. The
worker transport's `execution.finish` calls the new
`SessionAuthority.wake_after_worker`, which restarts the drain for the
logical owner (and for the physical id the worker reports, when that is
served); the row then runs and is delivered through the adapter like any
paused-then-resumed input.

`claim_session_input` keeps its store contract (None, not an error, while a
worker is live), so the blessed blocked-claim row in
tests/hermes_state/test_ledger_delete_consistency.py is unchanged.

Review: https://github.com/NousResearch/hermes-agent/pull/106742 (@itsflownium MAJOR-3)
2026-10-08 01:39:21 -07:00
Teknium
6c57ad37c3 feat: compose worker compression lifecycle and delegation persistence 2026-09-08 17:53:19 -07:00
Teknium
e7cd5f9380 fix: attenuate worker reconnect tickets to execution operations 2026-09-08 14:23:12 -07:00
Teknium
9d7d7e2abd feat: authenticate live worker persistence and explicit restart adoption 2026-09-08 14:23:12 -07:00