Commit Graph
4841 Commits
Author SHA1 Message Date
teknium1 2afb405337 fix(approval): withdraw the queue entry when no client can answer; commit choices under the lock
Why: for an old WebSocket client that never advertised server→client requests,
send_async already failed fast (on_result(None)) but _emit_approval_request ignored
it, so the approval wait — owned by tools.approval's queue, not server_requests —
still idled for the whole approvals.timeout (300s) with no prompt anywhere. The
same held for a -32601 error frame. on_result(None) now withdraws the queue entry
(withdraw_gateway_approval: cancelled cause, never a user deny) so
_await_gateway_decision returns at once; the agent sees a withdrawn prompt.

resolve_gateway_approval committed entry.result/reason/event.set() AFTER
releasing _lock, so _drop_entry (which reads result and leaves the queue under
the lock) could still pop-and-lose a choice the client was acked for. Every
committer (resolve, clear_session, unregister_gateway_notify) now commits inside
the same critical section that pops the entry, which is what _drop_entry's
docstring promised.

_drop_entry mapped a withdrawn wait to settle("set") — the raw poll-state token
went out as the request.cancel reason. It is now session_closed, and a choice
from another surface is resolved (both RequestCancelReason values).

Tests: restore test_server_request_error_response_fails_fast (an error frame
settles send() to None promptly); the approval fail-fast probe from the review
(silent WS peer, timeout 3 -> was 3.2s, now immediate); a lock-instrumented
resolve test; a settle-reason test. The test_protocol `server` fixture imports
server_requests before its sys.modules patch window so the module server.py binds
its sinks on is the one tests import — the PR's fail-fast test only passed in a
full-file run before (order dependency).

Part of #112548
2026-09-17 09:04:38 -07:00
teknium1 f9d178f78e fix(tui_gateway): old app builds no longer stall the agent on clarify/approval; late approval choices count
Item 2 of #112548: a Desktop/dashboard build that predates server→client
requests has no response path, so every clarify/approval/sudo/secret/vault/
connection/bridge request sat for the full deadline (clarify: 300s). Only the
tour probed. Clients now advertise once per connection
(`client.capabilities {server_requests: true}`, sent by the shared TypeScript
channel on `gateway.ready`); `send()` / `send_async()` return the
error-response shape (None) at once when every WebSocket peer of the session
is a build that never advertised. Sessions with no client attached still wait
so the reconnect replay (`open_requests`) keeps working; the stdio TUI ships
with the backend and is not gated. The advertisement is dropped on disconnect.

Reviewer minors from #113227:
- tools/approval_gateway_wait.py: the verdict is the choice committed under
  the approval lock while leaving the queue, so an /approve that lands after
  the deadline check but before the entry is dropped is an answer, not a
  timeout (the client was already acked "ok").
- tests/tui_gateway/test_protocol.py: the error-fails-fast test that only
  restated pre-existing behaviour is replaced by the two capability
  invariants (never advertised → fails fast; advertised → frame written,
  waits, forgotten on disconnect).
- server_requests.send try/finally around event.wait already landed on main
  (4371ed34a9); nothing to change.

Docs: programmatic-integration.md (advertise once per connection; method
list), tui_gateway/AGENTS.md; contracts regenerated.
2026-09-17 09:04:38 -07:00
teknium1 87f29fb1b9 fix(vision): reserve the per-image embed slot atomically
repeat_refusal checked the counter and record_embed incremented it in separate
lock sections, so a concurrent tool batch on the same image (the incident issued
4 at once) all passed a check taken before any of them recorded and the cap of 3
let 6 embeds through. Reserve the slot inside the check's lock section and
release it when the embed then fails.
2026-09-17 09:02:55 -07:00
teknium1 ed7eb5685a docs(vision): document vision.embed_target_bytes and vision.max_calls_per_image
User-visible knobs need a home: the Vision feature page explains why native embeds ride
the session and what each key does (subagent-only default cap, clamp range), the
configuration reference points at it next to auxiliary.vision so the two sections are
not confused, cli-config.yaml.example carries the commented block, and tools/AGENTS.md
names vision_tools_history_budget.py as the single owner of embed-cost policy.
2026-09-17 09:02:55 -07:00
abc56351aa fix(vision): delegated subagents stop re-loading the same image on the native fast path
A delegate_task child asked to transcribe five screenshots called vision_analyze 158
times on those files (full loads alternating with region crops) until its provider
quota ran out; every native load bakes the image into history and is re-sent on each
later API call, and nothing refused the repeat (#112095).

tools/vision_tools_history_budget.py now keeps a per-(session id, resolved source)
embed counter. Region crops share their file's key. When the cap is reached
_vision_analyze_native returns a tool error that says the image has already been loaded
N times and to answer from what is visible or ask the user, instead of another embed.
Only successful embeds count, so a failed read never eats the budget.

Default: `vision.max_calls_per_image` unset caps only delegated subagents
(agent.delegation_context.is_delegated_child_process_context) at 3 — they run
unattended and CLI /steer targets the parent — while the main agent stays unlimited;
an explicit value applies everywhere and 0 means unlimited.

Co-authored-by: Evi Nova <66773372+Tranquil-Flow@users.noreply.github.com>
Co-authored-by: gumclaw <gumclaw@gumroad.com>
2026-09-17 09:02:55 -07:00
Mohamad Kanso f37336522b feat(vision): vision.embed_target_bytes replaces the hardcoded 256 KB native embed budget
The native vision_analyze fast path (and the browser screenshot twins) downscaled every
embed to a fixed _EMBED_TARGET_BYTES = 256 KB. That is fine for photos but turns a
1080x2340 phone screenshot of a table into 540x1170, which the model then reads as
"unreadable" and re-requests (#112095).

The budget is now `vision.embed_target_bytes` in config.yaml (default unchanged: 256 KB,
clamped to 64 KiB..4 MiB so one setting cannot make every later request a multi-megabyte
resend), resolved in the new topical sibling tools/vision_tools_history_budget.py and read
by vision_analyze, browser_vision and browser_exec screenshots alike.

Ported from #112947 by @MohamadKanso (resolver + clamp), relocated out of the facade.
2026-09-17 09:02:55 -07:00
teknium1 0a3b74379f fix(tools): core-tool drop warns only after the probe had admitted it
The live pass on a stock home counted 13 new WARNINGs per process: every
unconfigured core-gated tool (browser, image_gen, HA) warned on its first
probe. The actionable case is a core tool that was available earlier in
this process and then got dropped; never-configured stays INFO.
2026-09-17 08:53:48 -07:00
teknium1 4e41ab0979 fix(tools): warn once when a check_fn drops a core tool; reject a mistyped catalog_provider
Issue #112649 atom 4: a core (`_HERMES_CORE_TOOLS`) tool whose check_fn returns
False leaves neither the schema nor the tool_search catalog (it is not
deferrable), so the model's "no such tool" is accurate and nothing in the log
points at the probe. ae5666f7fc made the False verdict INFO for optional,
unconfigured toolsets — that stays; the core-tool drop is now a WARNING that
names the dropped tool(s), once per probe per process (the 30 s TTL re-probe
would otherwise re-warn every turn), reset by invalidate_check_fn_cache().

Review minor: `catalog_provider: deepsek` was accepted silently and the typo
leaked into ModelInfo.provider_id. An alias that is neither a Hermes provider
id nor a models.dev id (loaded catalog, no network) now warns once, mirroring
the unknown-key warning, and the row keeps its own slug.
2026-09-17 08:53:48 -07:00
teknium1 019a34346c test: prove a self-reaping supervisor's child is never signalled by the registry
Adds the real-process invariant behind the parent-first teardown salvaged from
#111603 (#111598): a bash supervisor that reaps its own child on SIGTERM must
receive the only SIGTERM and exit 0, with the child never signalled by the
registry. Red on origin/main (the child logged a registry TERM before the parent
and the parent's own kill found no such process); green on the salvaged head.

Documents the teardown order in tools/AGENTS.md, including why scope teardown
(_stop_systemd_unit) never precedes the PID signal for a live parent — the
issue's cgroup-split concern (Electron migrating only the browser PID into its
own scope) cannot make the registry stop the scope first.
2026-09-17 08:52:27 -07:00
KoNit-K 039165a3d4 fix(process): grace host PID tree teardown 2026-09-17 08:52:27 -07:00
teknium1 66a91b7ce8 fix(cron): a server parked on a permanent error blocks the job again; warn once per outage
The reconnecting exemption keyed only on `_ever_connected`, so a server that
connected once and then parked on a PERMANENT error (revoked credentials,
endpoint gone: `_park_and_rearm('from parked state (permanent error)')`) looked
identical to a router-reboot park. Its self-probe fails the same way every
interval, so the job ran tool-less on every tick forever with only a gateway
WARNING and never received the one-shot blocked_config alert it used to get.

Record the revival reason `_park` was given on MCPServerTask (`_park_reason`,
cleared when a session proves healthy) and have `mcp_server_reconnecting`
return False for a permanent-error park, restoring the block and its alert.
Transient parks (network blip, rapid-drop budget exhausted) still return True.

Also dedupe the exemption's WARNING per job+server for the length of one
outage, like the one-shot blocked_config alert, instead of logging every tick;
the entry drops once the server resolves tools again so the next outage warns.
2026-09-17 08:51:30 -07:00
teknium1 6924cc66fb fix(cron): run a job whose enabled_toolsets MCP server is only reconnecting, instead of blocking it
A cron job naming an MCP server in its enabled_toolsets was hard-blocked
(blocked_config, one-shot alert, no LLM call) whenever that server resolved
to zero tools — including the minute a router reboot or DNS blip left an
otherwise healthy server parked and self-probing. The preflight could not
tell "the network blinked" from "wrong name / other profile's server", and
the job lost a whole tick to a transient outage the MCP layer was already
recovering from on its own (#112871).

The MCP run task keeps that distinction: a server that connected once in
this process (_ever_connected) and is currently sessionless with a live
task is degraded/parked and will revive. tools.mcp_tool_discovery grows a
read-only mcp_server_reconnecting(name) predicate on that state (resolved
through the profile's own or adopted connection key, never connecting),
and _empty_requested_mcp_toolsets skips such servers with a WARNING that
names them — the job runs with whatever tools did resolve, as the reporter
asked. A server that never connected for this profile keeps the block,
which is the misconfiguration case #109050 built the check for. The
blocked reason now says "never connected for this profile" so the
remaining block reads as what it is.

Docs: the pre-dispatch validation section lists the MCP check and the
reconnecting exemption.
2026-09-17 08:51:30 -07:00
kshitijk4poor f1df0aa01b fix(mcp): an idle stdio server is proven only after a full default interval
The no-keepalive proof branch ran on ANY timeout wake. With idle_timeout_seconds=60 the wait is min(180, 60); an overlapping RPC hides the recycle deadline so _recycle_if_due() is False and the session was marked proven after 60 s, clearing the #62212 rapid-drop budget early. Fix a proof_at deadline before the loop and gate the branch on it; the unproven timeout is the remaining distance to proof_at. Tests: the stdio test now shows the first (idle-limit) wake does not prove; the interval test covers an explicit keepalive_interval on stdio.
2026-09-17 21:18:03 +05:30
kshitijk4poor 77779fe642 refactor(mcp): lifecycle loop reads its inputs once and stops re-deriving the recycle predicate
WHAT: `_wait_for_lifecycle_event` hoists `is_http = self._is_http()` (it only
reads the immutable `"url" in self._config`) and reads `keepalive_interval`
from the config once instead of `in` + `.get()`. The one-shot RPC-idle waiter
is now spawned on `not is_http and self._rpc_lock.locked()` alone, dropping
the inline `_idle_timeout_seconds is not None or _max_lifetime_seconds is not
None` clause. The waiter list is built by one comprehension per iteration
(rpc_idle_task changes between iterations) and the `finally` reuses the last
value; `_cancel_waiters` already skips done tasks. The docstring folds the
#17003 keepalive paragraph into the first paragraph instead of describing the
keepalive twice.

WHY: the dropped clause was the inverse of
`MCPServerHealthMixin._stdio_recycle_deadlines` re-derived by reaching into
health-mixin attributes. Without it, a stdio server with no limits and an
active RPC spawns one trivially-completing waiter per RPC; on lock release
the loop takes one extra iteration where `_recycle_if_due()` is False and
`_next_stdio_recycle_deadline()` is None, so it simply recomputes the timeout
and waits again — harmless.
2026-09-17 21:18:03 +05:30
kshitijk4poor 3ceb40fc77 fix(mcp): an idle stdio server still proves its session without a keepalive ping
After the stdio keepalive default became None, the lifecycle loop's
`if keepalive_interval is None: continue` skipped the only idle path to
`_mark_session_proven()`. `_session_proven` is otherwise set only on a
tool-call success or a suspect health-check pass, and each new session
resets it, so an idle default-config stdio server never became proven:
every later child death/reconnect charged the rapid-drop budget that a
180 s idle survival used to clear (#62212 regression).

While the session is unproven, keep the `asyncio.wait` timeout at
`_DEFAULT_KEEPALIVE_INTERVAL` for stdio too; when it fires with the child
still alive, mark the session proven without pinging. Once proven the
stdio timeout returns to None, so a healthy idle pipe is never probed.
Shutdown/reconnect precedence and the rpc_idle waiter are untouched.

Test: `_captured_interval` now runs two lifecycle cycles (first times
out, second shuts down) through a shared helper so the stdio test asserts
timeouts [180, None], zero pings and `_session_proven` set, instead of
copy-pasting the fake `asyncio.wait`. Docstring/comment updated to the
new rule.
2026-09-17 21:18:03 +05:30
fangliquanflq 9ff0459ac8 fix(mcp): wake recycle deadlines after active RPCs 2026-09-17 21:18:03 +05:30
fangliquanflq 967bbf25d5 fix(mcp): avoid default keepalive on stdio servers 2026-09-17 21:18:03 +05:30
kshitijk4poor 6e7dad7608 test(tools): overwriting the database file itself is still refused as binary
The test trim dropped the headline case: text written over an EXISTING .db. Sidecar paths return at is_sqlite_sidecar before the overwrite branch, so a mutant that drops has_binary_extension from the overwrite condition survived every remaining test. Add a third parametrize case that targets the held-open WAL database file itself and asserts the binary refusal with bytes unchanged.

Same commit: the _check_binary_document_write docstring now names SQLite sidecars (always) and every BINARY_EXTENSIONS suffix (on overwrite), and the suffix is computed once at the top instead of three times.
2026-09-17 21:17:26 +05:30
kshitijk4poor c6f3a3cf24 refactor(tools): one suffix helper for the binary-extension checks; drop the dead .db3 member
_has_extension_in and is_sqlite_sidecar each re-implemented the same
rfind('.') / -1 / .lower() suffix extraction, and the write guard used a
third spelling (filepath[filepath.rfind("."):]) for its refusal messages
next to os.path.splitext in the overwrite branch. Add _lower_suffix()
("" when no dot) and route both predicates through it; the write guard
now uses os.path.splitext for every message's displayed extension.

_SQLITE_EXTENSIONS was `{.db,.sqlite,.sqlite3,.db3} & BINARY_EXTENSIONS`,
which silently dropped .db3 (not a binary extension anywhere in the
codebase, so `x.db3-wal` was never a sidecar). Spell the set as the three
members that actually take effect and assert the subset invariant instead
of hiding it behind an intersection. Behaviour is unchanged.
2026-09-17 21:17:26 +05:30
kshitijk4poor a3967ddbc0 fix(tools): sandbox read paths recognise SQLite sidecars as binary
file_operations.py checked `os.path.splitext(path)[1].lower() in
BINARY_EXTENSIONS` at five sites, so a `.db-wal` / `.sqlite3-shm` sidecar
(final suffix never in the set) was read and edited as text in the sandbox
paths. Route all five through has_binary_extension(), which strips the
sidecar marker. Behaviour is otherwise identical: same lower-cased final
suffix membership (rfind vs splitext differ only on leading-dot basenames
like `.bashrc`, which are in neither set). binary_extensions imports nothing
from tools, so no cycle.
2026-09-17 21:17:26 +05:30
kshitijk4poor d219e5755a fix(tools): a SQLite sidecar path is refused even when no sidecar file exists yet
The refactor that moved sidecar detection into binary_extensions dropped the
contributor's unconditional refusal for the db family and made every binary
extension a plain overwrite guard. That is right for the MAIN .db/.sqlite
(text fixtures named *.db exist), but a -wal/-shm/-journal path is never a
legitimate text target: a checkpointed database has no sidecar on disk, so
write_file("kanban.db-wal", text) silently dropped a garbage WAL next to a
live database.

Add is_sqlite_sidecar(path) and refuse such paths in
_check_binary_document_write regardless of is_file(). Scope the marker
stripping in _has_extension_in to SQLite suffixes so report.docx-wal no
longer counts as an opaque document. Hoist the duplicated is_pdf_path call.
Parametrize the write_file WAL test over sidecar existing/absent.
2026-09-17 21:17:26 +05:30
kshitijk4poor 9b7e24bccf refactor(tools): recognise SQLite sidecars in binary_extensions, drop write-guard regex
Move the .db-wal/-shm/-journal detection from a write-guard-local regex
into tools/binary_extensions._has_extension_in so has_binary_extension
(read guard AND write guard) agree: a sidecar counts as its database's
extension. read_file now refuses sidecars instead of returning lossy
text, which also gives write_file the no-baseline overwrite refusal.

Behaviour change vs the contributor's commit: creating a NEW .db /
.sqlite file via write_file stays allowed (main allows it and text
fixtures named *.db exist) — only overwriting an existing binary is
refused. The generic has_binary_extension overwrite branch is kept and
merged with the PDF branch because patch has no full-read baseline
check: on main, patch on an existing .db with a matching old_string
rewrites the header in place.

Tests folded into the existing guard test classes (one write_file, one
patch refusal on a real WAL sidecar); the PR's 12-test file and its
private-regex assertions are dropped.
2026-09-17 21:17:26 +05:30
Martin Mogis be79102ed8 fix(tools): refuse text writes into database files and binary overwrites
The text tools' read->modify->write round-trip re-encodes binary bytes
lossily: the terminal transport decodes stdout with errors=replace, so
a patch on a SQLite database reads mojibake and writes it back, silently
destroying the file (observed in the wild: a kanban board DB lost 550k
bytes / 26 days of history this way on 2026-09-15).

read_file already refuses to display binary files (extension + byte
sniffing), but write_file/patch had no write-side equivalent, and
patch_replace reads via plain cat so the read-side guard never fires
for it.

Guard rules (extends _check_binary_document_write, the existing
binary-document write guard):

- .db/.sqlite/.sqlite3 and their -wal/-shm/-journal sidecars: ALWAYS
  refused (even new-file creation) — plain text can never be a valid
  database, mirroring the opaque-document rule. The sidecars need a
  basename regex because os.path.splitext('x.db-wal') yields '.db-wal',
  which is not in BINARY_EXTENSIONS.
- Other BINARY_EXTENSIONS (.png, .zip, ...): refused when OVERWRITING an
  existing file, mirroring the existing .pdf-overwrite rule — the model
  can only have read mojibake, so writing back destroys it. Creating a
  NEW file with such an extension stays allowed.

Tests: new test_binary_db_write_guard.py covers the regex (main names,
sidecars, non-db names), the guard function, and the write_file/patch
tool paths against real SQLite files (integrity_check still ok, bytes
untouched). 29 new+existing guard tests pass; file-tools/patch suites
green (196 tests).
2026-09-17 21:17:26 +05:30
teknium1 0bd85d314c fix(skills): keep absorbed_into in the delete shape; decide every patch shape miss pre-effect
The per-action schema made the delete branch `additionalProperties: false`
with no `absorbed_into`, so a schema-validating or grammar-constrained
backend could no longer emit the curator's consolidation delete and
`_curator_consolidation_delete_guard` fail-closed every consolidation.
Advertise `absorbed_into` on the delete branch and cover the batch path
that forwards it to the guard.

Also fold the two remaining patch shape checks (missing new_string,
content mixed with old_string/new_string) into `_op_shape_error`, so a
batch rejects them before applying any sibling instead of creating op[0]
and rolling it back. Drop the stale `edit` vocabulary from skills.md:440
and the curator prompt, and move the schema-diet test helpers above the
`__main__` guard.
2026-09-17 08:47:01 -07:00
teknium1 75a0649a18 fix(skills): skill_manage advertises one shape per action; a misfiled text slot fails before any op applies
The operations[] item schema was one flat object with four coexisting text
slots (content / new_string / file_content / file_path). A 27B local model
that had just used write_file's file_content kept emitting it on create and
patch ops; the call validated against the advertised schema, the handler
failed on "content is required", and the whole batch rolled back — eight
identical retries until the tool-loop guardrail tripped (#112677).

- items is now an anyOf of self-contained per-action op objects (create,
  patch targeted, patch full-rewrite, write_file, remove_file, delete), each
  with additionalProperties: false. The wire shape of a correct call is
  unchanged (still a flat op with name/action/...), so transcripts, staging
  and replay are untouched; grammar-constrained backends can no longer emit
  another action's slot, and schema-validating providers reject it up front.
  Nested (non-top-level) anyOf survives every sanitizer (schema_sanitizer,
  Gemini legacy translator). Cost: parameters JSON 1352 -> 2414 bytes.
- _validate_batch_ops runs the per-op argument-shape check (_op_shape_error)
  before any op is applied, so a misfiled op[1] no longer applies op[0] and
  then rolls the batch back; the error carries the same misplaced-key hint.
- The hint is attached to argument-shape misses only: a patch whose real
  problem is an unmatched old_string is no longer told to "move that text to
  'content' (full rewrite)", the escape the patch error itself warns against.
- Shape tables (_REQUIRED_ARGS, text-slot maps, _misplaced_text_hint,
  _op_shape_error) move out of the facade into skill_manager_batch.py, the
  op-validation sibling; _patch_skill shares the old_string guidance text.
- Docs: skills.md Actions table states the one-slot-per-action contract.
2026-09-17 08:47:01 -07:00
kshitijk4poorandTranquil-Flow 4eff83cdec fix(approval): deobfuscate every command word in one detection variant (#113535)
_command_detection_variants yielded one FULL-LENGTH variant per quoted or
escaped command word. A heredoc body of quoted lines ("key": "value", …) is
hundreds of quoted command words, so both detection passes scanned
O(words * len) characters: on a 16 KB / 460-line command the hardline pass
alone took 7.8 s and the dangerous pass 15 s even with the launchctl lookahead
anchored (33 KB: 36 s hardline), all while holding the GIL on the gateway loop.

Build a single variant with every command word deobfuscated instead. The
obfuscation catch ($(echo rm), r''m, ${0/x/r}m …) is unchanged — the same
deobfuscated words appear, in one string — and the variant count on the
issue's input drops from 923 to 4 (36 s -> 0.26 s hardline, verdict
unchanged). detect_hardline_command needs no bound and keeps its YOLO
semantics: a benign heredoc is neither blocked nor prompted.

Root cause identified in #113943 by @Tranquil-Flow (variant explosion as the
second compounding factor); its cumulative-work budget is superseded by
removing the explosion.

Co-authored-by: Tranquil-Flow <66773372+Tranquil-Flow@users.noreply.github.com>
2026-09-17 20:38:43 +05:30
Hermes Patch Audit ea870b4d3e fix(approval): anchor launchctl lookaheads to prevent GIL starvation 2026-09-17 20:38:43 +05:30
teknium1 e3507ef2ce feat(lazy_deps): install_specs takes constraints and dry_run
Plugin dependency installs need two things the shared installer ladder did not
expose: a constraints file (so a plugin can never move a core pin) and a dry run
(so a conflict can be detected before anything is written). Both are threaded
through _venv_pip_install; the durable-target path keeps its own core
constraints and a dry run skips syspath activation and bytecode warming.
2026-09-17 00:11:27 -07:00
98745df3b9 fix(serve): hold work admission through cooperative retirement
Fence accepted RPCs, side agents, continuations, delegation and cron before issuing process-bound retirement permits.

Co-authored-by: chelsealong <chelsealong@126.com>
Co-authored-by: Mark Sheppard <mark@orchardstreetpress.com>
2026-09-17 00:34:50 -05:00
Austin Pickett 3eface06f7 fix(serve): expose turn_in_flight as an idle proof for pooled backends
The Desktop pool caps local `hermes serve` children and holds each child's
slot lease for its lifetime. Its renderer refreshes lastActiveAt every 60s
for every open socket, so a bot-tile-pinned resident is keepalive-fresh
forever: occupied is not busy, and the pool cannot tell the difference. The
renderer's own turn bookkeeping cannot see cron fires (HERMES_DESKTOP=1 runs
the in-process ticker), messaging turns served by a pooled backend, or a
session blocked on an approval, so it is not a safe proof either.

Add `GET /api/health/idle` (token-gated; whether a turn is running is
activity recon, unlike the public liveness route) returning
`idle: true|false|null` from `hermes_cli/web_server_idle_proof.py`. It
reuses the SSH idle-exit primitive `turn_in_flight()` (running gateway
sessions + running cron jobs) and adds the human-input ledgers: open
server->client requests (`server_requests.open_request_count`) and queued
gateway approvals (`approval.pending_gateway_approval_count`). Any ledger
that cannot be read yields `null`, which the Desktop treats as busy.

Tests: unit invariants over the fail-closed table and the real ledgers, and
a live test that boots three desktop-shaped children (HERMES_DESKTOP=1,
per-child HERMES_HOME, port 0), holds one busy in the cron running-job
ledger, and probes all three over HTTP. RED on base: every child 404s.
2026-09-17 00:34:50 -05:00
teknium1 58c6f6fa20 fix(bot-mode): a renamed primary signs with its friendly name; docs the message_agent target forms
Folds the backend half of #113396 (#89720) into this branch so there is ONE
friendly-name resolver: `_display_name` reads the Bot Mode title, then the
profile.yaml `display_name` written by `hermes profile rename` (the Desktop's
botFriendlyNames order), then the @handle — so the renamed primary signs
`Maia (@hermes)` instead of `hermes (@hermes)`. Reaching it by `maia` /
`@maia` already works through `_resolve_local_name`, which stays the single
resolver (fail-closed on ambiguity, punctuated names accepted).

`local_alias_map` docstring now states what the code does: an exact folder
id wins by design; a friendly name colliding with another folder id never
steals it, and ambiguity is only between friendly names.

Docs: the Direct-messages bullet lists the accepted target forms (profile
name, friendly name, Desktop @-slug) and the fail-closed ambiguity rule.

Review follow-up for #113410 / #113396.
2026-09-16 22:25:33 -07:00
teknium1 002df670f8 fix(bot-mode): message_agent resolves friendly names and Desktop @-slugs to folder ids
message_agent keyed local targets on the profile FOLDER id only, while the Desktop
autocompletes the bot's friendly name (profile.yaml display_name, or the Bot Mode
title) as its @-slug. "@scribe" for folder `writer`, or "Dr. Foo" for folder `foo`,
came back "No teammate named …" (a punctuated name was even "Invalid target"), and
the model went hunting for the teammate under ~/.hermes/profiles/ instead.

- tools/bot_mode_probe.py: alias_forms() mirrors the Desktop's mentionNameForms
  (slug + collapsed, reserved tokens dropped); local_alias_map() builds
  form → {folder ids} from every local profile's display_name / title.
- tools/bot_mode_dm.py::_resolve_local_name: exact folder id first, then a unique
  alias; two bots sharing a friendly name fail closed (never the one that sorts
  first). The handle-shape check no longer rejects a friendly name that resolves.
- The protocol roster line leads with a display_name that differs from the folder
  id and title, so an untagged "talk to Scribe" maps to `@writer` from the prompt.

Closes #100671
2026-09-16 22:25:33 -07:00
Finn763 e4ccfc16fc fix(tools): restore executor allowlist on message_agent inject success
ensure_message_agent_tool() returned True on the schema-present branch without
re-adding message_agent to agent.valid_tool_names. A long-lived Bot Chat whose
tool surface was rebuilt (compaction / MCP refresh republishes the allowlist from
the registry snapshot, which never contains the injected tool) then advertised
message_agent while the executor rejected every call, and the model fell back to
hermes -p shellouts that time out. Success now means both halves hold.

Re-applied onto the current any()-shaped gate; semantic change and test are the
contributor's (#96109).

Closes #96105
2026-09-16 22:25:33 -07:00
Konstantin Khlopkov 4f03ed9e6d fix(tools): keep the default profile roster entry pointing at the root home
A stray profiles/default/ directory shadowed the reserved root-home entry when
the roster was collapsed into a dict (last-key-wins), sending bot-mode DMs to a
lifeless profiles/default/state.db. Skip the reserved name in the scan, matching
the container_boot precedent.

Fixes #108564
2026-09-16 22:25:33 -07:00
KoNit-K a48debd368 fix(tools): redact vault values from browser exec output 2026-09-16 17:57:22 -07:00
teknium1 1a1b114343 fix: fail soft to guards-on when the terminal env registry lookup raises
_should_skip_container_guards documented fail-soft (unknown or raising
backend keeps the guards on) but only provider_flag's inner lookups were
covered: a raising registry.get_provider propagated out of the approval
predicate instead of defaulting to guards-on. Wrap the lookup so any
exception means "not isolated enough" and the dangerous-command prompts
stay in place.

Review follow-up on #113257.
2026-09-16 17:56:58 -07:00
teknium1 9e232a7ff5 fix(approval): resolve the plugin classification lazily inside the guard predicate
Keep tools/approval.py free of a module-level import from agent/ (every other
agent import in this module is late, and the sibling provider_flag callers in
tools/env_probe.py and tools/skills_tool_setup.py import inside the function),
and coerce the provider attribute to bool so a truthy non-bool declaration
cannot leak into the approval decision.
2026-09-16 17:56:58 -07:00
KoNit-K 3fc1a184f8 fix(approval): honor plugin container guard classification 2026-09-16 17:56:58 -07:00
teknium1 2370a63079 fix: drop env_type from the builders' signature comment
The dispatcher no longer passes env_type to the built-in environment
builders (that was the TypeError this PR fixes); only the plugin-registry
fallback receives it. The comment still listed it, which reintroduces the
confusion the fix removed.

Review follow-up on #113250.
2026-09-16 17:56:08 -07:00
KoNit-K 4a78de2805 fix(tools): avoid duplicate sandbox env type dispatch 2026-09-16 17:56:08 -07:00
teknium1 27ad6f5602 fix(tools): heredoc-pipe guard sees through fd redirects around the pipe
Two fd-redirection spellings of the exact class 260f3e79fff70 closes still
reached a bare shell unscanned, while real bash executes the body in each:

- `cat <<EOF 2>&1 | bash` (and `&>/dev/null | bash`): `_pipeline_end` read
  the `&` of the fd-dup as a top-level list operator and ended the pipeline
  walk before `bash`, so the consumer was never a candidate.
- `cat <<EOF | bash 2>/dev/null` / `| bash 2>&1`: `_read_shell_word` stops
  at `>`, so the fd number `2` came back as a word of its own and
  `_executes_heredoc_body` took it for a script operand ("bash 2" runs a
  script named 2), so the shell was not bare.

`_pipeline_end` now skips a `&` glued to a redirect angle bracket (`>&`,
`<&`, `&>`), and `_shell_words_at` treats an all-digit word immediately
followed by `<`/`>` as the fd prefix of that redirection and stops there,
exactly as it already stops at a bare `>`. `nice` joins the wrapper table
(`| nice bash` was allowed; same one-entry mechanism as nohup/setsid).

Controls unchanged: `| bash >/dev/null` blocked, `| bash run.sh 2>/dev/null`
and `cat <<EOF > notes.md` allowed. The new parametrized test fails on the
previous guard for the four evading shapes and passes on this one.
2026-09-16 17:55:07 -07:00
teknium1andbeardthelion c796e68e81 fix(tools): self-repo guard scans heredoc bodies piped into a bare shell
`cat <<'EOF' | bash` (and `| sh`, `| sudo bash`, `| bash -s`, `| (bash)`,
`| { bash; }`, `|& bash`, `| tee f | bash`, `cat <<EOF |` + consumer after
the terminator, `\`-joined lines) walked around the running-checkout guard:
`_heredoc_specs` decided "does a shell execute this body" from the text
BEFORE the `<<` opener only, so a shell downstream of the pipe never counted
and the body was masked as data before `_find_mutation` walked the command.
A `git checkout`/`reset --hard` in such a body rewrote the live checkout.

The consumer is now decided on the MASKED command (bodies blanked, so the
text is the structure the shell parses): `_pipeline_end` walks the opener's
pipeline with quote/escape state to the first list operator or bare newline
at its nesting level — newlines right after `|` continue it, `)`/`}` closing
the owner's own group end it unless a pipe follows — and every command start
in that span (pipe segments, and the groups/substitutions inside them, all
inherit the pipe as stdin) is checked with the bare-shell predicate.
`_join_continued_line` folds backslash-newline before opener detection, as
the shell does, so `bash \` + `<<EOF` and `cat <<EOF | \` + `bash` read as one
command line. `_shell_words_at` stops at a trailing `# comment` so `bash #
note` is still a bare shell.

Real-bash ground truth drove the shapes: `cat <<EOF |` followed by a newline
makes the NEXT LINE the heredoc body (the consumer comes after the terminator
or the pipeline is a syntax error), which is why the consumer walk runs over
the masked command rather than per physical line. `&&`/`||`/`;`/newline end
the pipeline, so `cat <<EOF && bash`, `| grep x`, `| bash -c 'cmd'`,
`| bash run.sh`, `| python3`, `| xargs` stay data.

Reported and analysed in #112441; supersedes the approach in #112442.

Co-authored-by: beardthelion <56458543+beardthelion@users.noreply.github.com>
2026-09-16 17:55:07 -07:00
teknium1 b3aef45987 fix(clarify): batch result carries the surface's no-answer notice; trim tests
Follow-up to the #112725 salvage. When a gateway clarify batch stops at an
unanswered question, the batch payload only said `timed_out: true` with blank
answers — so a card the platform REJECTED ("[clarify prompt could not be
delivered]") read exactly like a user who walked away, which is the misreport
#112684 describes ("a timeout must not be presented as user inactivity when the
prompt was never delivered").

- gateway/run_turn_runner.py::_clarify_batch_sync: the unanswered question's
  own response text rides along as `notice`.
- tools/clarify_tool.py::_run_batch/_batch_result: pass `notice` through into
  the result JSON beside `timed_out` (only when present); schema description
  mentions it. CLI/TUI batch callbacks send no notice -> byte-identical output.
- tests: fold the single-question re-arm pin into the existing bracket-answer
  test (<=2 new tests), parametrize the end-to-end test over an undeliverable
  Telegram-shaped adapter so the delivery sentinel is pinned as `notice`.
- docs: tools-reference.md describes `notice`.

Part of #112684
2026-09-16 17:47:50 -07:00
Kevin Rajan 010a45097e fix(web): per-capability backend key no longer reroutes the other capability
Fixes #113017. _get_backend() treated any web selection — including
per-capability keys (web.search_backend / web.extract_backend) — as a stored
shared selection and short-circuited to firecrawl with no ladder. Setting only
web.extract_backend therefore silently rerouted web_search off autodetect.
The no-ladder firecrawl branch now requires a shared selection
(read_selection: use_gateway); per-capability keys name only their own
capability, and the other keeps its normal cascade.

Test: new tests/tools/test_web_backend_capability_isolation.py — red on base
(search resolved to firecrawl), green after fix; managed use_gateway still
resolves firecrawl with no ladder.
2026-09-16 17:43:40 -07:00
teknium1 5457c48df2 fix: bound the index-miss fallback and skip it under provider filters and index timeouts
Review of the fallback pass added in the previous commit found three ways it
could burn the search budget without ever being able to return anything:

- A provider filter (`--source nvidia`) selects like "all", so an index miss
  fanned out to skills.sh/ClawHub/LobeHub/well-known whose results carry no
  `extra.provider` and were then all cut by `_filter_results_by_provider` —
  four guaranteed-empty network calls and, with ClawHub slow, the whole 30 s
  budget. `_index_miss_fallback_sources` now takes the provider filter and
  returns [] when one is active.
- The fallback ran until the shared `overall_timeout` deadline, so any
  unfiltered miss (a typo) stalled CLI/TUI/dashboard for the callers' full 30 s
  whenever ClawHub (documented here as taking minutes) was slow, where the
  index alone answered instantly. The pass now gets its own budget,
  `min(remaining, _INDEX_MISS_FALLBACK_BUDGET=8 s)`.
- `if source_counts.get("hermes-index")` treated an index that TIMED OUT (key
  absent) as a miss, so the fallback fired with no budget left and `_fan_out`
  appended every fallback registry to `timed_out_ids` without calling it —
  the dashboard then blamed skills.sh/ClawHub/LobeHub falsely. Fallback now
  requires the index to have completed with zero results (`== 0`).

One invariant test per major, each red on the previous commit (the budget
test stalls 5 s there; the provider test makes registry calls there).
Docs paragraph updated to state the 8 s cap and the provider-filter carve-out.
2026-09-16 17:43:11 -07:00
teknium1andKoNit-K 13dcfc112b fix(skills): hub search falls back to the registries when the index has no match
`hermes skills search <q>`, the TUI gateway search and the dashboard
`/api/skills/hub/search` all returned zero results for a skill that is live
on skills.sh but not yet in the cached centralized index: with an available
index `_select_active_sources` drops every external registry, and nothing
re-asked them when the index came back empty.

`parallel_search_sources` — the one chokepoint every surface calls — now
re-queries the registries the index displaced (skills.sh, ClawHub, LobeHub,
well-known) when a non-empty query got no index match, inside the same
`overall_timeout` (a shared deadline, so the 30 s budget never doubles).
GitHub stays out of the fallback: a single miss (typo) would otherwise spend
an unauthenticated user's whole hourly GitHub budget. Browse (empty query),
index hits and explicit `--source` filters are unchanged.

The fan-out loop moved into `_fan_out` so both passes share the pool/timeout
handling instead of duplicating it.

Slimmer redo of #112509 (@KoNit-K), which put the fallback at the same
chokepoint but only for skills.sh and with a second copy of the pool code.
Fallback shape follows the reporter's Option A.

Fixes #112503

Co-authored-by: KoNit-K <124019182+KoNit-K@users.noreply.github.com>
2026-09-16 17:43:11 -07:00
teknium1 b002dfc04d fix: pruned skill_view/read_file results reload after a proactive prune
A committed proactive tool-result prune (`prune_tool_results_only`, driven from
`agent/turn_preflight.py::compress_after_tool_results`) demotes old skill_view and
read_file bodies to one-line markers, but only the full-compaction path called
`_reset_read_dedup_caches`. The repeat-view dedup therefore kept answering
"unchanged / content_returned: false" for content that no longer existed in the
transcript, so the `[SKILL_PRUNED: ... reload with skill_view(...)]` marker asked
for a reload the tool then refused (#112763). Treat the committed prune as the same
content-loss boundary compaction already is: reset the task's read/skill dedup right
where the pruned list is committed.

Sibling surface: manual `/compress` on CLI, TUI and the messaging gateway called
`compress_now()` without `task_id`, so the boundary reset hit the "default" bucket
instead of the session's. Pass the session-scoped task id on all three.

Test double in tests/hermes_cli/test_cli_manual_compress.py gains the `task_id`
kwarg the real `_compress_context` facade already accepts.

Supersedes #103268 (@jo0wz), which reached the same path with a process-global
ghost registry (not task-keyed, skill_view only).
2026-09-16 17:23:44 -07:00
wangtao cb0cf7a191 fix(stt): preserve subprocess error details 2026-09-16 17:21:37 -07:00
Xuxyyy 84893f8342 fix(tools): honor false interrupt debug values 2026-09-16 17:21:14 -07:00
teknium1andJohn Paul Soliva 05e3b864a9 fix(bot-mode): the DM delivery retry reads the stream the CLI writes and resumes the persisted row
Both bot-to-bot DM retry gates (tools/bot_mode_dm.py::_run_local_turn and
tui_gateway/methods_bot_relay.py bot_relay.deliver) classified a failed turn from
`(proc.stderr or proc.stdout)`. A failed `hermes … -Q` turn prints the provider
prose on stdout (it is the turn's final_response) and `session_id: …` on stderr
on every run, so the classifier only ever saw the banner: every 429/5xx/context
overflow classified `unknown`, the policy-gated re-run never fired, and the relay
sender always got `reason: unknown`. Classify from both streams in the order the
CLI writes them (tools.bot_failure_reasons.turn_failure_text) at both sites.

Classifying alone double-delivers: the failed attempt's turn-start persist already
wrote the DM as the Bot Chat's unanswered tail row, and the re-run (a fresh
process replaying the same session + payload) appended a second identical copy.
The re-run's child env now carries HERMES_RESUME_UNANSWERED_TURN=1
(tools.bot_relay.retry_turn_env); the quiet one-shot consumes it before the turn
(hermes_cli.quiet_single_query.adopt_unanswered_turn) and re-stages the
identical unanswered tail row as the pending CLI user dict, stamped durable, so
_stage_turn_user_message reuses it and the flush writes no second row. Opt-in
by design: an identical tail alone cannot tell a re-run from a person's
deliberate re-send.

Slimmer redo of #105529 by @jonpol01 (same diagnosis and shape; the marker is
consumed at the CLI seam that already reads the dispatcher's env instead of
inside agent/turn_context.py).

Co-authored-by: John Paul Soliva <soliva.johnpaul@icloud.com>
2026-09-16 17:19:58 -07:00