Commit Graph

6 Commits

Author SHA1 Message Date
Teknium
1f91fb386a fix(managed-worker): delegated children build, close and settle off Relay's loop
Review follow-up for #141944.

- The whole child store hops off a running loop, not only child.reserve:
  the child is built, run and closed inside delegate_task's callback, and
  its constructor already reads the store (ContextCompressor
  .bind_session_state). Under NeMo Relay that tripped the sticky
  synchronous_rpc_on_event_loop refusal and every child came back
  status=error, api_calls=0.
- A child that finishes itself (early close after a failed constructor or a
  refused sibling) ends its own session row; parent retirement and restart
  only select live children, so that row stayed open forever.
- session.create on an owner-reserved child merges its constructor facts
  (max_iterations, reasoning_config, ...) beside the _delegate_from marker
  instead of losing them to the keep-existing upsert.
- Descendant lookups use a primary-key range instead of substr(), so a
  no-child finish is one index probe, not a table scan.
- Invariant tests: depth refusal, child profile_name == parent's, a forged
  parent claim refused on the request path, a draining refusal receipt,
  mid-batch refusal closes built siblings, an early store close settles the
  child, constructor facts persisted, and a real-daemon Relay leg.
2026-10-20 03:22:11 -07: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
6be00dde24 fix(state): every terminal worker path compacts its full-history read receipts
N19 made execution.finish and admission settlement shrink an execution's
read receipts (compression.history stores the whole transcript, a context
read a full session row) once the execution is terminal. Two other paths
make an execution terminal without that step: lose_admission_worker (a
managed worker lost mid-turn) and discard_orphan_workers_on_reset (a reset
revoking unlinked unknown compute). Settlement's _retire_admission_workers
then skips them because it only compacts rows still not terminal, so each
lost or discarded worker kept one full transcript copy in worker_receipts
indefinitely.

Both paths now call compact_terminal_receipts for the execution in the same
transaction that marks it terminal.

Tests (red on r11-base: 4154-byte receipt kept):
tests/gateway/test_lost_worker_receipt_compaction.py::test_lost_admission_worker_compacts_its_history_receipt
tests/gateway/test_lost_worker_receipt_compaction.py::test_reset_discarded_orphan_worker_compacts_its_history_receipt

Review: dokterdok N41
(cherry picked from commit 2f57d968428a3a12b997ad95e07f7fcc76a76adf)
2026-10-10 22:49:18 -07:00
Teknium
1b9362e042 fix(state): drop a terminal managed worker's full-history read receipts
Every managed turn starts with a compression.history read, and
apply_worker_receipt stored each receipt's full result_json. Nothing removed
worker_receipts for a live session (only retire_terminal_receipts, at delete),
so each turn left a full-transcript copy behind: 22x the transcript at 40
turns, ~1.1 GB at 1,000 (quadratic state.db growth) for every managed session
(safe-mode/bypass, Kanban, custom-provider opt-in).

In the transaction that makes an execution terminal (execution.finish, or
settlement/cancel closing it via _retire_admission_workers) its read receipts
(results carrying `messages` or a full `session` row) shrink to a
{"retired": true} marker. payload_digest stays, so a late duplicate with other
content still conflicts (admission_conflict); an exact late replay of a
retired read is refused stale_generation, as after retirement. Mutation
acknowledgements (counts, row annotations, worker_assignment) and the
execution.finish receipt stay replayable.

Review: https://github.com/NousResearch/hermes-agent/pull/106742#pullrequestreview-5475590057
2026-10-10 05:52:02 -07:00
Teknium
dcbcefc57d perf(state): index worker_executions(session_id,status) and probe a lineage in one query
b31ed5232056 made worker exclusion lineage-wide, which is correct. But `worker_states` ran one
`SELECT ... WHERE session_id=?` per lineage row, and `worker_executions` had no session index, so
each probe scanned the whole table. That happened inside BEGIN IMMEDIATE on claim/register/reset.
Terminal rows are kept until retirement, so the table only grows.

- SCHEMA_SQL: `CREATE INDEX IF NOT EXISTS idx_worker_executions_session_status ON
  worker_executions(session_id, status)`. It is idempotent and created on every open, so existing
  stores get it on their next open with no version bump. The table and its columns predate this
  index, so it stays in SCHEMA_SQL, not DEFERRED_INDEX_SQL.
- `worker_states`: one `IN (SELECT value FROM json_each(?))` probe for the whole lineage (no
  bound-parameter limit on long chains), restricted to the live statuses.

dA2 probe (perf_probe.py, compression chain of N rows, M terminal worker rows), r5-picked -> fix:
  N=400 M=50k: 592 ms -> 5.2 ms
  N=100 M=20k:  44 ms -> 1.2 ms
  N=10  M=50k:  13 ms -> 0.9 ms

Test: tests/hermes_state/test_worker_lineage_index.py drops the index (an older store), reopens
twice (migration plus an idempotent no-op), then checks that a 3-row lineage costs exactly one
probe and that the plan uses the index. It fails on r5-picked (3 probes) and passes after.

Follow-up to b31ed5232056 (#135061)

Review: https://github.com/NousResearch/hermes-agent/pull/135061
2026-10-08 12:07:00 -07:00
David Dudok de Wit
dbd772ba43 fix(state): exclude workers across the complete conversation lineage
A worker on a physical transcript fences its logical FIFO and second registrations. Explicit reset revokes only unlinked unknown workers, preserving live and admission-linked fences.

Reported-by: itsflownium (https://github.com/NousResearch/hermes-agent/pull/106742#issuecomment-6050777316)

Validation: tests/hermes_state/test_worker_lineage_exclusion.py, tests/gateway/test_unknown_resolution_physical_worker.py

Implementation and additional regression probes were AI-assisted with GPT-6 Astra.

(cherry picked from commit b31ed5232056100c55568d67a0c8ab6426886d4f)
2026-10-08 09:10:26 -07:00