Commit Graph

12795 Commits

Author SHA1 Message Date
unsupportedpastels
60f5029394 feat: Daybreak switch for catalog-listed ChatGPT subscription models
OpenAI Daybreak (Trusted Access for Cyber) reduces cyber refusals for
approved accounts. Codex's model picker has a Daybreak toggle; Hermes had
no way to request it.

The signed-in account's Codex /models catalog already lists, per model,
which cyber programs that account may use
(available_access_programs.cyber). Hermes reads that catalog for Fast and
Ultrafast; it now keeps the cyber list from the same fetch.

- agent.daybreak (default false) is one profile-wide switch, like Codex's.
- Desktop shows a Daybreak switch in a model's options submenu, next to
  Fast, only when this account's catalog lists daybreak_blue for that
  model. Unknown or unreachable catalog: hidden.
- Each Responses request adds access_programs.cyber=daybreak_blue only
  when the switch is on AND the request's credential and model are listed.
  Checked per request, so a /model switch, credential rotation or expired
  catalog never carries it to a model or account without it.
- The gateway re-reads the switch every turn, so a flip applies to the
  next turn of a running chat without rebuilding its agent.
- The opt-in codex app-server runtime does not send it, so the switch is
  hidden there.

Co-authored-by: FroRaut <79215537+Froraut@users.noreply.github.com>
2026-11-02 15:06:27 -05:00
unsupportedpastels
a4847138bb fix(dashboard): trust a loopback public_url's exact origin behind a Host-rewriting proxy
With webapp.public_url: https://localhost:8443 in front of a Webapp on
127.0.0.1:9120, a proxy that rewrites Host to the backend's address
sends Host 127.0.0.1:9120 with Origin https://localhost:8443. That
Origin names neither the bound port nor the Host it dials, so CORS gave
no grant and every WebSocket upgrade got 4403. The loopback port check
never read the configured public URL, and a loopback public URL does not
turn on sign-in.

_configure_auth_gate now also records the public URL's exact loopback
origin (scheme, host, port; default ports filled in) as
app.state.trusted_public_origins, from listener_public_url (the
Webapp's webapp.public_url) or dashboard.public_url, and
is_trusted_local_origin accepts an Origin equal to it. Nothing else is
widened: another loopback port, scheme or host on the same proxy is
still refused, and a non-loopback public URL adds nothing (its Origin
never reaches the port check).

The port check keeps running on 0.0.0.0 / :: binds. Sign-in cookies are
SameSite=Lax and http://localhost:3000 is same-site with
http://localhost:9119, so sign-in alone does not keep another local
page on the same host off the sockets; a new test pins that.

The public_url cases fail on the previous sources (4 failed: every
trusted case) and pass with this change. web-dashboard.md describes the
proxy setup.
2026-11-02 13:56:48 -05:00
BearHuddleston
5d1095209b fix(dashboard): gate every plugin socket in PluginApiWebSocketGate
The Host/Origin/peer gate for plugin WebSockets was attached as an
include_router dependency. FastAPI passes router dependencies only to
@router.websocket routes (APIWebSocketRoute). A plugin that declares its
socket with router.add_websocket_route(...) or @router.websocket_route(...)
gets a plain Starlette WebSocketRoute, so the gate never ran for it and a
page on another local port could still open that socket.

Run _ws_request_is_allowed in PluginApiWebSocketGate instead. The
middleware sees every /api/plugins/<name> upgrade whatever the route
form, and it closes with 4403 before native-grant redemption, so a
refused upgrade does not consume a grant and the answer is the same for
every plugin name. The router dependency is removed.

test_every_mounted_plugin_websocket_gets_the_gate now covers all three
forms on an app carrying the real middleware: [raw] and [raw-decorated]
fail on the previous sources (DID NOT RAISE WebSocketDisconnect) and
pass with this change. The abnormal-close grant-scope test hand-builds a
scope without a client, which the peer check fails closed; it now sets
client like uvicorn does.
2026-11-02 13:56:48 -05:00
unsupportedpastels
98527bf2c5 fix(desktop): carry the dev renderer URL through Windows SSH backends
connectWindowsRemote ignored devServer: the spawn payload never asked
windows_ssh_runtime to set HERMES_DESKTOP_DEV_SERVER, the ownership record
did not name a renderer, and reuse did not compare one. A dev build's
renderer sockets through the SSH forward were then refused unless the
Windows host had been configured by hand.

Send devServer in the spawn payload and have the runtime helper set (or
clear) HERMES_DESKTOP_DEV_SERVER from it, record it in both ownership
writes, and decide reuse with the POSIX lockServesConnect predicate.
Records without the field count as no dev server, so packaged builds
reuse as before.
2026-11-02 13:56:48 -05:00
unsupportedpastels
3d9a230d57 fix(dashboard): forward the Vite dev page's socket Origin unchanged
The /api proxy rewrote a WebSocket upgrade's Origin to HERMES_DASHBOARD_URL.
Pointed at a port forward (http://127.0.0.1:8000 forwarded to the backend on
9119), that Origin names neither the backend's bound port nor the Host the
proxy keeps (localhost:5173), so the backend refused the dev page's sockets.

The proxy sets no changeOrigin, so Host stays the page's own authority and
the browser's Origin already names it, which the backend admits as
same-origin. Drop the rewrite and its helper, pin the proxy options, and
pin both header pairs in the backend test.
2026-11-02 13:56:48 -05:00
unsupportedpastels
b332cead53 fix(dashboard): admit a WebSocket Origin that names the Host it dials
The Origin gate now trusts a loopback origin only on the bound port or
the desktop dev renderer. A dashboard reached through a port forward
(ssh -L 8000:localhost:9119, docker -p 8080:9119) sends an Origin on the
forwarded port, so its own page could no longer open /api/ws or
/api/pty, and a Webapp tab dialling back in during a restart wait was
refused (tests/gateway/test_restart_wait_prompt_reach.py).

An Origin whose authority equals the upgrade's Host header is that
server's own page: same-origin by definition. A page on another port
cannot make the two match, and the Host check before it still stops DNS
rebinding. The Vite dev-proxy case without the Origin rewrite is now
admitted for the same reason; a different host on the same port is not.
2026-11-02 13:56:48 -05:00
FroRaut
cb837e10a5 fix(dashboard): stop trusting fixed dev-server ports for CORS and WebSockets
_TRUSTED_LOCAL_ORIGIN_PORTS (9119, 5173, 5174, 4174) was trusted on every
backend, including packaged Desktop backends on an ephemeral port. A Vite app
on 5173, or on 5174 when 5173 is taken, could still read the session token
from / and open /api/ws. _is_trusted_local_origin() now accepts only the bound
port and the desktop dev renderer this backend was spawned for
(HERMES_DESKTOP_DEV_SERVER). `hermes dashboard` keeps working on 9119 because
that is its bound port.

The dashboard's Vite dev server was the only client that relied on a fixed
port: the browser's Origin on proxied /api upgrades is Vite's. The /api proxy
now presents upgrades from Vite's own page (Origin host equals Host) with the
backend's origin, and passes every other Origin through for the backend to
refuse, so it does not launder foreign pages the way Vite's rewriteWsOrigin
would. Vite's default CORS grants every localhost port and would hand another
local page the token hermesDevToken() injects into index.html, so it is off.

(cherry picked from commit 66de028a3ce39ec49a32205855dc269d30bf3942)
2026-11-02 13:56:48 -05:00
FroRaut
e45b32ac48 fix(dashboard): stop trusting loopback port 3000 for CORS and WebSockets
_TRUSTED_LOCAL_ORIGIN_PORTS kept :3000 because web-dashboard.md listed
it, but nothing in the repo serves the dashboard or the desktop renderer
there. It is the default port of many local web apps and dev servers,
and it is the origin used in the original report: with :3000 trusted, a
page on http://localhost:3000 still got the CORS grant on `/` (the
session token) and on /api/files/download?token=, and still passed the
WebSocket Origin gate.

Drop :3000 from the trusted ports and from the documented list. The
dashboard's own origins (the bound port, :9119, the Vite dev server
:5173, the desktop renderer's :5174/:4174 and HERMES_DESKTOP_DEV_SERVER)
are unchanged.

(cherry picked from commit 0fc889ab9b1826c5062eb88959f96099258ab056)
2026-11-02 13:56:48 -05:00
FroRaut
5c1a0345a4 fix(dashboard): apply the WebSocket Host/Origin gate to plugin sockets
HTTP middleware (the Host check, CORS) never runs for a WebSocket
upgrade, so every core socket calls _ws_request_is_allowed() before
accept. Plugin sockets did not: the kanban plugin's
WS /api/plugins/kanban/events only checked the credential, so a session
token read by a page on another local port, a remote site or a
DNS-rebinding host still opened it.

_mount_plugin_api_routes() now attaches _plugin_ws_request_gate to every
plugin router, next to the secret-scope dependency. For a WebSocket it
runs the same _ws_request_is_allowed() check as the core routes (Host,
Origin via _is_trusted_local_origin(), loopback peer) and closes with
4403; plain HTTP requests pass through. The gate sits on the mount, so a
plugin cannot skip it or drift from the core rule.

(cherry picked from commit 25418b7ea4e5444b2bcec0baf7ed49452a9ee23f)
2026-11-02 13:56:48 -05:00
Froraut
67e0e1940a fix(dashboard): address review — trust the desktop dev renderer's own origin
The fixed loopback-port allowlist refused every documented hgui slot
past 0: worktree-ui-dev.md runs slot N's renderer on 5174+N. That
renderer talks to its backend directly, so slot 1 (:5175) got no CORS
grant and a 4403 on its WebSocket upgrades.

Electron hands its HERMES_DESKTOP_DEV_SERVER down to the backend it
spawns: profileBackendParentEnv copies process.env. So
_is_trusted_local_origin now also trusts that exact origin when it is
loopback. Any other loopback port is still refused, including another
slot's renderer. The CORS middleware and the WebSocket Origin gate
share this check, so both honour it. No new setting: the variable
already exists and is documented.

(cherry picked from commit fb08ccb4ef9a130469fc0d203917fcc0e5e200ef)
(cherry picked from commit d921624b8339f693067dec1495fd6afe38ad4093)
2026-11-02 13:56:48 -05:00
Froraut
bd9328f969 fix(dashboard): trust only the documented loopback origins for CORS and WebSocket upgrades
Any page served from another local port could steal the dashboard
session token and open /api/pty — a full shell.

- CORS used allow_origin_regex ^https?://(localhost|127\.0\.0\.1)(:\d+)?$,
  i.e. every port. CORS wraps the SPA catch-all too, so a fetch of `/`
  from http://localhost:3000 (or Live Server :5500, a previewed
  agent-built site, a compromised local dev app) got
  Access-Control-Allow-Origin reflected and could read index.html's
  window.__HERMES_SESSION_TOKEN__. The ?token= download route was
  readable the same way.
- WebSocket upgrades skip preflight, and _ws_host_origin_reason checked
  the Origin through _is_accepted_host, which drops the port and accepts
  any loopback alias. So ws://127.0.0.1:9119/api/pty?token=<stolen>
  from Origin http://localhost:3000 passed the gate.

The docs (web-dashboard.md § CORS) already promise a fixed list: 9119,
3000, 5173 and the configured port. Both gates now trust exactly that —
plus the desktop renderer's strictPort dev/preview servers (5174/4174)
— via one _is_trusted_local_origin(). Non-web origins (packaged
Electron file://) are unaffected; trusted public hosts keep their
existing exact-host rule.

(cherry picked from commit 8a5f1dcee82e2a020b72d7bd7e9b5a0e6f11f390)
(cherry picked from commit 9dad5f4cd0988ad60ae4883541b68efb9092bb1a)
2026-11-02 13:56:48 -05:00
Teknium
aa28a71341 fix(cli): the glyph layout's reasoning summary never repeats the start of the thought
The "∴ Thought for Ns" line that closes a reasoning block appended the
reasoning's first bold heading, or — with no heading — its first sentence.
Models whose reasoning has no headings (e.g. Claude) therefore got their
opening sentence printed twice: once in the reasoning body streamed above the
line, and again as the summary's title. Drop the title entirely; the reasoning
is already shown in full right above, so the summary is just the duration.

Removes the now-dead _full_title/thought_title/_TITLE_MAX helpers and the
write-only _reasoning_full_text buffer in the stream mixin.
2026-11-02 07:54:35 -08:00
Teknium
b5bce5c622 fix(auth): two rotations in one iat second order by obtained_at, never expiry
Greptile P1: oauth_pair_order fell through to expiry when both JWT iat
claims were equal, so a later rotation with a shorter TTL read as older.
Equal iat now falls to the sub-second local issue stamp and is a tie
without one; expiry only orders pairs lacking an issue stamp.
2026-11-02 06:58:25 -08:00
Teknium
8c792c1601 fix(auth): a quarantined profile still recovers from a sibling's re-login
Re-review of #147866: a quarantined profile has no access token, so its identity read as unknown
and the same-account guard stopped it adopting the shared login a sibling just signed in with
(the ca6513542d recovery path; main recovers). An empty profile adopts on order alone again;
pushing the profile over the shared store still requires a known same identity.
2026-11-02 06:58:25 -08:00
Teknium
8a930dc139 fix(nous): never push or adopt the shared login across identities
Review findings (warnings): two non-JWT access tokens both read as account
identity None, so "same account" was True and a newer profile was pushed over a
DIFFERENT account's shared store. And (pre-existing) the adopt branch had no
identity gate at all: a profile signed in as account A adopted account B's newer
shared tokens and rewrote its auth.json to B.

Push, the renewal skip and adopt now all require a KNOWN identical identity
(guest anon credential or account JWT sub); a missing sub is unknown and never
matches another unknown. A second identity keeps using the existing `renewal`
slot of the shared store.
2026-11-02 06:58:25 -08:00
Teknium
d0f69f7fcb fix(nous): order shared-store freshness by issue time, not expiry
Review finding (critical): a rotation always issues LATER but not always
later-EXPIRING (the Portal sets access TTLs per client and per issue). Ordering
by expiry first made the renewal guard refuse a fresh, shorter-lived pair and the
next merge adopt the redeemed one (reuse detection -> forced re-login), and made
the push write a redeemed pair over a sibling's live one.

The shared-store merge, the renewal write guard and the profile-fork heal
(auth_oauth_grants) now share ONE comparator, oauth_pair_order: JWT iat, then
last_refresh / obtained_at; expiry only when a side lacks an issue stamp. The
heal still always consolidates to one copy; only which copy wins changed.
2026-11-02 06:58:25 -08:00
Teknium
b29bf60b3a fix(nous): an older shared login never replaces a newer profile login
_merge_shared_nous_oauth_state adopted the shared nous_auth.json state whenever its
refresh token differed from the profile's, without asking which was newer. When the
shared store fell behind (a lost shared write after a profile-side refresh), the
profile's auth.json was overwritten with the older agent key and an already-redeemed
refresh token; the next refresh replayed it and the Portal's reuse detection forced a
re-login.

The shared copy is now adopted only when its token pair is newer (expiry first, the
same ordering the forked-grant heal uses; issue time breaks a tie). When the profile
is the newer one it is pushed to the shared store instead, and a renewal write never
rolls the shared store back to an older pair of the same account. Unstamped states on
both sides keep the legacy behaviour.
2026-11-02 06:58:25 -08:00
Teknium
30375b51bc fix(providers): refuse only a synthesized placeholder for the selected entry
Review findings on #147761: the missing-profile-key refusal fired for a
custom provider on model.openai_runtime=codex_app_server (which owns its
auth), for a caller-supplied explicit_api_key='no-key-required', and lost
the selected entry when explicit_base_url replaced its URL (back to the
misleading 401). The check now runs on the final api_mode and skips
transports that never send the key (codex_app_server, bedrock_converse),
skips any caller-supplied key, and identifies a named-entry runtime by
its selected entry rather than by URL.
2026-11-02 06:57:42 -08:00
Teknium
139716ae63 fix(providers): refuse the placeholder only for a routed profile
A single-profile process reads key_env from its process environment too, and
origin/main pins its placeholder behaviour (test_custom_entry_shadow_key_env,
test_bedrock_mantle_key_env). The refusal targets the multiplexed named-profile
case where a key exported in the server shell is invisible by design.
2026-11-02 06:57:42 -08:00
Teknium
894859c9fc fix(providers): a profile missing its declared key says so instead of a 401
A named profile served by a multiplexing gateway reads provider keys only from
its own .env (by design). When a custom endpoint declares key_env and the
variable is missing from that scope (e.g. exported only in the server's shell),
resolution substituted the keyless placeholder `no-key-required`, sent it, and
the user saw "custom rejected your API key ... HTTP 401", naming neither the
variable nor the profile.

Resolution now refuses that runtime before any request with a typed
AuthError(missing_api_key) naming the provider, the variable, the profile, and
`hermes -p NAME config set VAR <key>`; it also says when the variable exists only
in the server's environment. Custom blocks with no key_env (Ollama, llama.cpp,
vLLM) keep the placeholder. Registry API-key providers' existing "Set X." error
gains the same profile hint on named profiles. The TUI/Desktop init-failure
wrapper no longer prints ".." after a message ending in a period.
2026-11-02 06:57:42 -08:00
Teknium
af090b5f6d fix(update): a failed shallow-lock write closes its fd and drops the lock
Review finding on 0c793bb: if os.write in _ShallowLock.__enter__ raised
(ENOSPC), the fd leaked, so the rest of the process looked like a live holder
to release_dead_fetch_locks and Windows refused to delete the lock. Close the
fd and remove the lock on that failure. Also fix the docstring that named the
reclaimer instead of the holder.
2026-11-02 04:24:00 -08:00
Teknium
792ed0d99a fix(update): reclaim the shallow.lock a killed update's shallow fetch left behind
A `git fetch --depth 1` (installer checkouts are shallow) killed during its pack
transfer strands .git/shallow.lock, and every later fetch fails "Unable to create
'.../shallow.lock': File exists" until the 10-minute age sweep. The killed-update
reclaim (same custody + no-live-git proofs as the ref locks) now covers it;
release_dead_ref_locks becomes release_dead_fetch_locks.

Hermes's own _ShallowLock holder runs no git between its git calls, so it now keeps
the lock fd open while held: the /proc / lsof fd probe (and Windows' unlink refusal)
sees a live Hermes holder and the lock stays.
2026-11-02 04:24:00 -08:00
Teknium
57ebc3eb83 fix(update): reclaim the ref locks a killed update's fetch left behind 2026-11-02 04:06:07 -08:00
Teknium
f45d3aaa9a fix(mem): an allocator-only trim no longer suppresses a forced full collection
collect=False trims stamp their own clock; _last_trim_monotonic now stamps collecting trims
only, so a housekeeping/agent-close trim cannot push agent-cache pressure eviction's forced
collection inside the 5 s force floor (Greptile review).
2026-11-01 22:07:56 -08:00
Teknium
0488f459be perf(mem): timer trims run one full collection per quiet period, never during a turn
The housekeeping tick and the TUI idle reaper now call trim_memory_when_idle: allocator trim
only, plus one full gc.collect() once no turn has run in this process for 5 minutes (again
after a later agent close re-arms it). Nobody is waiting then, so the pause harms no one, and
whatever cyclic garbage remains (openai SDK resource cycles) is still reclaimed. The quiet
clock is the existing process-wide live-turn counter in review_idle_queue.
2026-11-01 22:07:56 -08:00
Teknium
fd2648e8da perf(mem): agent-close and TUI turn trims stop forcing a full GC in the gateway
On a long-lived gateway every agent close (idle-cache eviction, /new, session end) forced
trim_memory(force=True), and its gc.collect() walks the whole shared heap with the GIL held:
264-760 ms on the live 3.6M-object gateway, about once a minute, freezing every other
session's thread, adapters and streams. The TUI turn-completion trim runs in the same
process after every TUI/Desktop turn.

Both now pass collect=False: what an agent close or a finished turn drops goes by reference
counting, cycles are left to CPython's automatic collection, and the next trim returns their
pages. The forced collection stays on the idle reaper (runs only when every session is
quiescent) and agent-cache pressure eviction (memory is the emergency there).
2026-11-01 22:07:56 -08:00
qby
6965dd7033 perf(mem): the gateway housekeeping tick trims without a forced full GC
The messaging-gateway housekeeping tick runs trim_memory() every cooldown
(60s by default), and every call forced a full gc.collect() before
malloc_trim(0). On a long-lived gateway whose live heap is hundreds of MB
that collection holds the GIL for 400-600ms, freezing every thread in the
process — platform adapters, SSE streams, in-process API requests — once a
minute, for the ~8MB of RSS that regrows before the next tick (#139763).

trim_memory() now takes collect=; the tick passes collect=False, so that
lane only asks the allocator to return already-free arenas and leaves
cycle collection to CPython's generational GC. The pressure lanes (agent
close, large tool result, post-compression) keep the collect-then-trim
default, where a collection is what makes the trim return anything. The
trim log line gains collected=<bool> so the lane in force is visible.

The TUI idle reaper's periodic lane is deliberately unchanged: it trims
only when no session is busy or attached, and its comment records the
forced collection there as intentional.
2026-11-01 22:07:56 -08:00
Teknium
5351ed71d4 fix(mem): cap malloc arenas before any server thread exists; honour .env MALLOC_ARENA_MAX
Review fixes for the arena cap:
- serve/dashboard/gateway apply runtime.malloc_arena_max at hermes_cli.main import, right
  after the profile .env and config load and before logging/plugins start any thread
  (glibc latches its arena limit once threads allocate; the old serve call ran after
  plugin discovery). Legacy python -m gateway.run and cli.py --gateway apply it first too.
- MALLOC_ARENA_MAX / glibc.malloc.arena_max present only because Hermes loaded the
  profile .env (absent from /proc/self/environ) is applied via mallopt with the
  operator's number; one present at exec is already glibc's and wins.
- exact tunable-key match, C-int range check, glibc capability gate (gnu_get_libc_version
  + mallopt) instead of sys.platform; tests gate on glibc and drive the real entry point.
2026-11-01 21:54:15 -08:00
Teknium
fcbf94c2e7 perf(mem): cap glibc malloc arenas in the gateway and serve processes
glibc gives each new thread its own malloc arena, up to 8 x CPU cores, and keeps
every arena's freed pages. A long-lived gateway churns through ~1,100 short-lived
Python threads an hour (tool heartbeats, turn watchdogs, stream monitors, pipe
drains) on top of native pools (the relay plugin's tokio runtime, anydoc's rayon
pool), so it fills every slot: 157 of 160 arena heaps on a 20-core host after 10 h.

runtime.malloc_arena_max (default 4) sets mallopt(M_ARENA_MAX) in-process at
gateway bootstrap and web_server.start_server (serve / dashboard), next to the
existing RLIMIT_NOFILE floor. In-process rather than MALLOC_ARENA_MAX in the
unit/plist/spawn env, so commands the server runs (terminal tools, MCP servers,
builds) keep glibc's default, and every launch path (systemd, launchd, Desktop,
detached auto-start, docker) is covered by one call. An operator's own
MALLOC_ARENA_MAX / glibc.malloc.arena_max tunable wins; 0/false/null keeps
glibc's default; non-glibc hosts are untouched.
2026-11-01 21:54:15 -08:00
Teknium
c9577b6722 fix(cache-bounds): atomic expiry vs refresh; one LRU order for skill scopes
Review fixes for the bounded-cache PR:
- models_pricing: catalog + deadline are expired, swept and published under one
  lock, so a refresh landing between a sweep's two pops can no longer keep its
  catalog without its deadline (Nous 300 s policy TTL never expiring).
- model_metadata memos: endpoint sweep+publish and both Codex writers
  (evict + context/max publish) hold one MEMO_LOCK.
- skill_commands: the per-scope maps share one recency order, touched on every
  use, so a scope used for dispatch no longer loses its /reload-skills baseline
  and reports unchanged commands as added.
2026-11-01 21:53:36 -08:00
Teknium
36708d1efa perf(memory): one lazy models.dev parse and bounded long-lived caches
Shed only entries no reader can use, or the least recently used past a count far
above any real working set; nothing a live session needs is ever dropped.

- models_catalog_static: _PROVIDER_MODELS fills its xAI rows from the
  process-wide models.dev copy on the first xAI lookup (or a whole-table walk),
  never at import. main parsed the catalog at import and threw it away; an idle
  gateway now never parses it, and a reader parses it exactly once.
- model_metadata: the per-credential /models memo sweeps expired entries on
  write (rotated keys left one catalog each); the Codex OAuth context memos keep
  the newest 128 token fingerprints, the bound codex_service_tiers already uses.
- models_pricing: _cache_catalog drops catalogs past their deadline, as the
  reader already does for the one key it reads.
- skill_commands: per-(platform, profile, project) command maps are one LRU of
  64 scopes across all three tables; an evicted scope rescans on next use.
- auxiliary_client: async semaphores are held per event-loop object and a closed
  loop's table is dropped on the next acquire (main keyed by id(loop) and kept
  every loop forever, and a weak key cannot work: a semaphore that made a caller
  wait binds its loop). Checked on stdlib asyncio and uvloop 0.23.
- agent_runtime_helpers: the sanitizer-heal log counters are an LRU of 1024
  sessions; the told-once set and pending notices are never evicted.

Helpers live in agent/cache_bounds.py and agent/model_metadata_memo_bounds.py;
model_metadata.py does not grow.
2026-11-01 21:53:36 -08:00
Teknium
7aa5200e91 fix(sessions): hermes sessions adopt offers login-stamped phone chats
adoptable_sessions validated each row with no subject, so a phone chat stamped
with the dashboard login (basic:admin) was dropped although the host owner the
adoption resumes as can adopt it. Judge rows for host_owner_subject(). The test
now also registers Platform(mobile) first: a routeless row with that label still
adopts while the hermes-mobile plugin is loaded.
2026-11-01 21:30:21 -08:00
Teknium
3da1531caf fix(sessions): bundled platforms and automation labels stay read-only; adopt scan stays fast
Review folds on #147802:
- client_label also refuses bundled platform plugins (teams, irc, line, ...) and
  curator/batch/homeassistant, which the enum-only check let adopt as writable.
- hermes sessions adopt pre-filters out refused labels (subagent/cron bulk) instead
  of resolving every routeless row (0.9s -> 6.6s on an 18k-session store).
- handed_off_ref accepts an adopted phone chat, whose created_source keeps the app label.
2026-11-01 21:30:21 -08:00
Teknium
fcee404be6 fix(sessions): old phone-app chats continue in Desktop instead of opening read-only
Before the gateway owned sessions, `hermes serve` stored whatever `source` a client
sent, so phone apps signed in through the dashboard login left routeless rows labelled
`mobile`, `ios` and the like. Resume only adopted the local surfaces' labels, so those
chats opened read-only (#143601) and the next prompt answered `session_read_only`.

Adopt any routeless, owner-owned row whose label is not a local surface, a built-in
messaging platform, or an automation / foreign-writer label (cron, subagent, kanban,
bot_room, a2a, webhook, api_server, import, recovered, webui, local, unknown). It
resumes as a `gui` chat, and binding relabels it `desktop` (created_source keeps the
app's label), because once bound the row has a route and its old label would read as
a messaging chat. Routed rows never qualify, so the hermes-mobile plugin platform,
which registers `mobile`, keeps its messaging route. Third-party WebUI rows stay
read-only: that process runs its own agent on the same state.db.

The same predicate feeds the read-only mount (skips them), sidebar edits, the stored
picker and `hermes sessions adopt`.

Refs #146814, #144814.
2026-11-01 21:30:21 -08:00
Teknium
2d0bf91f11 fix: every /bg entry point joins its background delegations in the run
The gateway /bg fix above covered messaging chats only. The shared-owner
/bg (prompt.background, used by the CLI, TUI and Desktop) and the classic
local CLI /bg run the same detached bg_* side agent, and on main a
background delegate_task there also leaves a completed ledger row pending
forever: nothing wakes or drains a bg_* session. Their side agents now
declare the channel stateless, so the batch runs inline and the result is
in the one answer /bg reports. The sync-fallback note names /bg.

Refs #140569.

Co-authored-by: milnerrad <302432023+milnerrad@users.noreply.github.com>
2026-11-01 21:11:06 -08:00
Teknium
06433066f4 fix: bare hermes migrate passes no setup-only flags; an import that ran with errors gets its own warning 2026-11-01 19:53:24 -08:00
Teknium
43cc73f12d fix: hermes migrate openclaw imports secrets only with --migrate-secrets
First-run setup keeps passing --migrate-secrets (what core's old OpenClaw step did); the named
command forwarded setup's choice too, so API keys and bot tokens came over without being asked.
2026-11-01 19:53:24 -08:00
Teknium
f21c7baef1 fix: hermes migrate <agent> exits non-zero when the import fails 2026-11-01 19:53:24 -08:00
Teknium
afc5c55d47 feat: setup and hermes migrate offer the OpenBot import too 2026-11-01 19:53:24 -08:00
Teknium
3053b9dd92 feat: hermes migrate and setup move Grok Bot users over; hermes migrate <agent> installs the importer
Grok Bot joins setup's "Coming from another agent?" step (detected from its desktop app
or a downloaded grok-bot-export file). Bare `hermes migrate` offers the same import on an
existing install; `hermes migrate <agent>` imports from one agent, installing the
agent-importers plugin from the catalog when missing. A plugin too old for the picked
importer is updated once and the import retried, for setup and migrate alike.
2026-11-01 19:53:24 -08:00
Teknium
722d4fac96 feat(desktop): lock a skill from the Capabilities pane
Adds the user-facing half of the per-skill lock (hermes curator lock):

- PUT /api/skills/lock {name, locked, profile?}: resolves the skill and
  keys the record by its directory (what the write guards resolve), in
  the selected profile; 404 for an unknown skill, 500 when the sidecar
  write fails.
- GET /api/skills rows carry locked (best-effort; a corrupt sidecar
  lists everything unlocked instead of failing the list).
- Desktop: Lock/Locked text toggle with a state-specific hint in the
  skill detail pane for every provenance (optimistic, rolls back on
  error), plus a lock glyph on locked rows (list rows, cards, detail
  header). Strings in all bundled locales.
2026-11-01 15:47:21 -08:00
Teknium
91c51e04f4 feat(skills): a locked skill can't be changed by the agent through any write path
Builds on the per-skill lock record (`hermes curator lock`): the lock now holds against the
agent everywhere, not only the background passes.

- skill_manage refuses every mutating action on a locked skill for every origin (normal turns,
  cron, subagents, review fork, curator); a corrupt sidecar still fails closed only for the
  autonomous passes so one broken file can't freeze every skill edit.
- write_file / patch hard-refuse any path inside a locked skill's directory and the lock
  record (skills/.usage.json) while any skill is locked (tools/skill_lock.path_refusal, wired
  into _check_sensitive_path).
- terminal refuses, before approvals and under --yolo, commands that write into a locked skill:
  redirections/tee, cp/mv/rm/touch/mkdir/chmod, sed/perl -i, git changes in its tree, archive
  extraction into it, inline python/bash code naming it, including after a cd into it; and the
  agent running `hermes curator unlock`. Reads and running the skill's own scripts still work.
- The curator never auto-archives a locked skill.
- Docs: "Locking a skill" rewritten for the new contract.
2026-11-01 15:47:21 -08:00
Davis Ford
b694c7d907 feat(skills): per-skill content lock against autonomous writes (#25083)
`hermes curator lock <skill>` records `locked: true` beside `pinned` in the
active profile's skills/.usage.json. While locked, skill_manage refuses
patch/edit/write_file/remove_file/delete on that skill when the write origin
is the background review fork or the curator consolidation pass, for the
whole skill directory and on both the single-op and the batch path. The
skill stays readable, listed and auto-loadable; foreground user-directed
writes are not gated; unlocked siblings keep learning.

- tools/skill_usage.py: set_locked / is_locked (strict: a corrupt sidecar
  raises instead of reading as unlocked) / locked_skill_names
- tools/skill_manager_guards.py: _locked_guard, wired into
  _background_review_preflight ahead of the delete guard; fails closed on
  an unreadable sidecar instead of silently relaxing the lock
- hermes_cli/curator.py: `curator lock|unlock`, locked list in `status`
- agent/background_review.py: one prompt sentence so the fork does not
  retry or recreate a refused locked skill
- docs: curator.md "Locking a skill's content" section, line 47 corrected
  (pins block deletion only, #141673), skills.md pointer

Related: #140332, #142933, #89961
2026-11-01 15:47:21 -08:00
Teknium
bd47fe3b63 fix(telemetry): count busy messages that wait behind a running FIFO turn; cancelled rows read as dropped; per-profile home and closing-day peak
- A message the adapter sees as idle (its earlier message's adapter task ended while a queued
  turn runs as a FIFO turn, outside the adapter's session guard) is stamped by the runner's
  running-turn check at FIFO admission and settled there, so a busy chat counts every waiting
  message once. A queued row cancelled later (/stop, /new, refused head, edit) settles dropped
  through SessionAuthority._settle_cancelled.
- A row that is already terminal when admit_message re-reads it counts as reached only for a
  turn outcome (completed / interrupted / failed / steered); cancelled, rejected or deleted is
  dropped / never.
- The arrival's home is the routing identity's runtime profile, not the profile that last ran a
  turn in that chat id (two bots of different profiles in one channel).
- The day's peak of running chats is kept per UTC day, and a day closing after midnight folds
  its own peak before its row is written.
2026-11-01 13:50:05 -08:00
Teknium
a41d1dfca0 fix(telemetry): a busy message saved behind a pause or restart is not dropped; auto-resumed chats count toward their own profile's peak
A graceful stop/restart (runtime_draining) and the session_busy /
unknown_execution pause notices tell the user the message is saved while its
FIFO row stays queued, but the busy-arrival settle recorded dropped/never.
Park the arrival instead: it counts as queued if this process later runs the
row, and not at all across a restart (the existing doc promise). A row read
back as unknown right after commit already started, so it counts as reached.

The startup auto-resume loop claims chats from the launch profile's scope;
pre-assign each claimed chat to the home its turn resolves to, so a resumed
secondary-profile chat no longer counts toward the launch profile's peak.
2026-11-01 13:50:05 -08:00
Teknium
6f55623cc9 feat(telemetry): count messages that arrive while a chat's agent is busy, and the day's peak of busy chats
hermes.gateway.busy_arrival.count: one row per human message that reaches a
chat whose turn is still running (the shared runtime's busy dispatch),
recorded once its fate is known: queued (ran later as its own turn),
steered (steer or interrupt-mode redirect into the running turn),
interrupted (hard interrupt, then ran next), merged (folded into another
busy message of the same burst), dropped (/stop, /new, refused, queue cap),
with the wait from arrival to the moment it reached the agent.

hermes.engagement.day.count gains gateway_peak_busy_chats_bucket: the most
chats of the owning profile with a turn running at once that UTC day, kept
in memory from the runner's running-turn set at every turn boundary
(_persist_active_agents, moved to the agent-cache mixin so the gateway.run
facade does not grow) and folded into the profile's engagement day state.

Both are opt-in through the existing shared-metrics gate; no chat ids or
session keys leave the process.
2026-11-01 13:50:05 -08:00
Teknium
b7ab3f7d85 fix(telemetry): tool names a stable release shipped stay valid after leaving core
Spotify left core (#135389) and the five browser_vault_* tools folded into one
browser_vault after v0.21.6/v0.21.7 shipped them, which dropped spotify,
spotify_* and browser_vault_* from the shared-metrics contract (and spotify /
spotify_* from the v3/v4 schema enums). Pending rows older releases stored
with those names no longer exported as recorded: the drift re-bucket turned
toolset=spotify into custom and tool_name=spotify_search into unknown, and a
tool_unavailable row (no fallback bucket) was left out entirely.

They join RETIRED_TOOL_NAMES / RETIRED_TOOLSET_NAMES, the existing legacy set
for removed core names; recording still maps through the live sets, so no new
row carries them. The v3/v4 schema enums regain the removed values, and the
v4 tool_unavailable enum also gains the contract values it never listed
(browser_vault, set_theme, setup_beat, setup_choose, start_chat).

Tests: the retired-name packaging test gains spotify and browser_vault cases,
and the schema-equals-contract test covers tool_unavailable; both red on
origin/main.
2026-11-01 13:38:10 -08:00
Teknium
001b0eba27 fix(update): never offer the delete answer when there is nothing to pull; scan ignores showUntrackedFiles
- A main checkout reports in_place_update=False, so the keep/delete prompt fired even with HEAD
  already on origin/main; a "no" deleted edits on a no-op run. Ask only for a real branch switch
  or when the target is not HEAD or an ancestor of it.
- status.showUntrackedFiles=no hid every untracked entry from the scan, so the stash fell back
  to whole-tree --include-untracked. The scan now passes --untracked-files=normal.
2026-11-01 10:08:01 -08:00
Teknium
c483933325 fix(update): tree-ref probe reads only the exit code, so it needs no text decoding
test_subprocess_text_encoding requires encoding= with text=True (Windows ANSI code page).
2026-11-01 10:08:01 -08:00
Teknium
005fbe8058 fix(update): stash only what the update collides with, and ask before stashing
`hermes update` ran `git stash push --include-untracked` on every dirty tree,
so any untracked folder in the checkout was hashed into git objects and
deleted from disk, then written back on restore. A 55 GB leftover worktree
copy (2.8M files) made the "stashing before update" step take minutes, and
declining the restore left the whole folder parked in git stash.

- Untracked entries are stashed only when a ref the update can land on
  (target, origin/<branch>, local <branch>) has a file at that path, or a
  parent/child of it; the rest stay on disk via exclude pathspecs, because a
  pull or checkout never refuses on them. Comparison is casefolded so a
  case-insensitive filesystem still counts Config.py vs config.py. Forks and
  unreadable target trees keep the old stash-everything behaviour (the
  upstream sync lands on a ref fetched later).
- An interactive terminal now asks "Keep these changes after updating?"
  BEFORE anything is stashed. Yes stashes and restores without a second
  prompt; no deletes exactly what would have been stashed, so no stash
  entry is left behind. A run with nothing to pull does not ask. Gateway
  /update, --yes and non-interactive (Desktop) paths are unchanged apart
  from the scoped stash.
2026-11-01 10:08:01 -08:00