The speak and transcribe stream sockets refused the local Desktop's own
credential. They now redeem the interactive runtime ticket through the existing
native gate (no Origin, loopback peer, served profile) and run in the grant's
profile. Desktop sends the ticket as a subprotocol and its main process strips
Origin only for those two paths on a fresh /api/ws reservation.
Rows RT-71, RT-80.
Refs #143547
Co-authored-by: Dolverin <5910064+Dolverin@users.noreply.github.com>
The dashboard's /chat pump without a keep-alive token closed its socket with 4410 when the child
exited, where main closed it normally (1000) whether the child exited or the socket broke. Only
the dashboard's /chat uses this pump, and the Webapp does not need the change, so it closes as
on main again; the keep-alive path keeps reporting an exited child with 4410.
Two rules the Webapp needs had been applied to every surface's WebSocket gate. The loopback gate
took a one-use socket ticket before ?token=, so on the standalone dashboard and hermes serve (which
mint no such tickets) a ticket in the URL or the subprotocol was spent and refused, and a stray one
beside a valid session token refused the upgrade. Behind the sign-in gate the server's own
?internal= credential opened only /api/ws and /api/pub, so a gated dashboard refused it on
/api/events, /api/pty, /api/console, the voice streams and plugin sockets such as kanban's, where
main accepts it.
Both rules now apply only on the gateway's Webapp listener (app.state.ui_surface == "webapp"): there
the loopback gate takes the Webapp's socket tickets and the server's credential opens only the
sockets its spawned clients dial. Everywhere else the gate judges ?token= alone on loopback and
accepts ?internal= on every socket behind the sign-in gate, as main does.
A Webapp page minted its one-use socket tickets from three routes that did the same thing with a
different socket name: /api/webapp/gateway-ticket for /api/ws, /api/webapp/terminal-ticket for the
host terminal and /api/webapp/audio-ticket?socket= for the voice streams, each with its own copy of
the surface check, and the renderer had a helper for each.
POST /api/webapp/socket-ticket?socket= now mints them all. A table names each socket (gateway,
host-terminal, speak-stream, transcribe-stream), the surface policy that lets a surface mint it, and
whether the mint checks the profile the page will dial (the gateway socket, as before). An unknown
socket gets 400 and a surface that does not serve the socket gets 404, as before. In the renderer,
ticketedWebsocketUrl() mints the ticket and builds the URL for any of the four sockets. Main's
/api/auth/ws-ticket is unchanged. The tests, fixtures and code comments that named the old routes
now name the new one.
Signing the Webapp out has to end every grant made under the browser credential, and each kind of
grant checked that its own way: socket tickets and tracked sockets compared digests from
web_session_sockets, the cookie login's binding read the token straight from web_server, the Bot
Desktop viewer check and the file tickets each compared a digest by hand, and the sign-out verb set
the token and then called close_all() and revoke_all() itself. A new grant kind was one more place
to forget, which is how a grant outliving sign-out kept coming back.
hermes_cli/browser_credential.py now owns the credential: current(), its generation (a SHA-256
digest), is_current(generation), and rotate(), which replaces the credential and runs the revokers
registered with on_rotate(). Socket tickets, tracked sockets, Bot Desktop viewer tickets, file
tickets and the cookie login's binding record the generation when they are made and check
is_current() when they are used; the open-socket and file-ticket stores register their revokers, and
hermes webapp --sign-out calls rotate(). What signing out ends is unchanged.
@teknium1's 56be810f764 makes the WebSocket upgrade's ?token= leg ask
webapp_sign_in.token_works_alone first, as the bearer header does. That commit tests /api/ws. This
one tests every socket on the Webapp's listener that takes a provider token as ?token= (/api/ws,
/api/events, /api/pub, /api/pty and both voice streams): a browser login's access token, copied out
of its cookie, opens none of them before a sign-out or after it. It also tests that a token the
listener gave a native app's sign-in opens a socket that stays open across a sign-out, as the native
app stays signed in.
token_works_alone's docstring, the module docstring, the developer guide and the Desktop guide now
name a socket's ?token= among the places the gateway refuses such a token on its own.
Greptile finding "Browser tokens survive sign-out": behind the sign-in
gate the WebSocket upgrade's `?token=` leg (web_server_chat._ws_auth_reason)
verified a provider access token without the Webapp's native-sign-in
check the bearer header applies (webapp_sign_in.token_works_alone). A
token copied out of a browser login's cookies therefore still opened
/api/ws (and every other socket behind _ws_auth_reason: /api/pub,
/api/events, /api/pty, /api/console, the audio streams, plugin sockets)
after `hermes webapp --sign-out`, untracked by sign-out.
The leg now runs the same check: on the gateway's Webapp behind the gate
only a token this listener gave a native app's sign-in opens a socket on
its own; the standalone dashboard accepts any provider token, as on main.
_ws_request_view carries the app so the check reads its state.
The Webapp's gateway ticket validated `profile` and then dropped it, so `/api/ws` answered every
request that names no profile for the gateway's launch profile. A tab loaded on `?profile=work`
polled `session.active_list` without a profile, never saw its own running session, and after 45 s
of a quiet tool call showed "Hermes ended this turn without a reply" while the turn kept running.
The ticket now names the profile, and the upgrade binds the socket to that home's authority, the
way a native ticket does (`gateway/run_api.py`). The socket keeps its host scope, so a request that
names another served profile still reaches it. A tab with no profile is unchanged.
Reported by @BearHuddleston on #141864.
Streaming voice in the Webapp never streamed: spoken replies and live dictation always fell back to
the whole-reply path. The browser dialed `/api/audio/speak-stream` and `/api/audio/transcribe-stream`
with the one-use ticket it had minted for the gateway socket, and a socket ticket opens only the
socket it was minted for, so both voice streams refused it.
Each voice stream now has a socket name, and the Webapp mints its ticket from
`POST /api/webapp/audio-ticket?socket=speak-stream` or `?socket=transcribe-stream`, on the same
surface and with the same credentials as the gateway ticket. The browser-hosted Desktop asks for one
on every voice dial. A voice stream's ticket opens that stream once and nothing else, and the
gateway's and the host terminal's tickets open neither stream. Native Desktop is unchanged: its
unnamed tickets and session token still open the voice streams.
`hermes webapp --sign-out` replaced the browser session token and closed the sockets that token
had opened. On a Webapp behind the sign-in gate (a wildcard bind, or a public URL in front of a
loopback bind) browsers never hold that token: they sign in with the dashboard's password or
OAuth provider and keep that login in cookies. Sign-out reached none of it. After it, a signed-in
browser still read /api/sessions, minted socket tickets, and kept its chat socket and host
terminal open, so signing out to cut off a lost device left that device a live host shell.
Each login on the gateway's Webapp is now bound to the browser session token. A password login
or OAuth callback there also sets the HttpOnly cookie hermes_webapp_signin, the hex
HMAC-SHA256 of "webapp-sign-in" keyed with the current token, with the session cookies' Path,
SameSite and Secure policy; a refresh renews it with them. The gate treats a cookie session on
the Webapp without a matching value as signed out: API requests get 401 with the login URL and
pages go to /login. Replacing the token therefore signs every browser out, whichever provider it
signed in with, and so does the CLI replacing the stored token while no gateway runs.
A request whose binding checked out records the token's digest, and the socket tickets it mints
(chat, host terminal, /api/auth/ws-ticket) carry it. Redeeming such a ticket after a sign-out
opens nothing, and the socket it opens is tracked like a token socket, so sign-out closes it with
4401. The verb now reports whether the gate is on and how many browser sockets it closed. The
standalone dashboard never sets or checks the binding and keeps its logins as before.
A loopback Webapp tab opened its host terminal with the session token in the socket URL, where
logs, history and proxies keep it. An authenticated request now mints a one-use ticket named for
one socket: a chat ticket does not open the host terminal, a terminal ticket does not open the
chat socket, and the host terminal opens only with its own ticket. The Webapp's plugin sockets
use their polling fallback, as the signed-in Webapp already did, so no URL carries the token.
hermes webapp --sign-out replaced the token but left open tabs connected until they reconnected.
The gateway tracks every socket the session token opened, closes them with 4401 on sign-out and
revokes media stream links. Native clients and signed-in browsers stay connected.
Carried from BearHuddleston's #93508 onto main. The Webapp relay and the
profile-incarnation fence stay out: carried code follows main's
named-profile rule and refuses a missing or deleted profile home.
- Webapp routes: one-use launch tickets, window handoff, and gateway
WebSocket tickets minted for the signed-in browser
- Browser surface policy and the SPA document policy
- A host terminal for the browser that survives reconnects
- Staged browser uploads and file tickets; file.attach takes a staged upload
- hermes sessions adopt
- Webapp bundle build helpers and the renderer freshness check
- Regenerated gateway contracts
Co-authored-by: emozilla <emozilla@nousresearch.com>
- desktop-plugin-sdk.md: ctx.socket on a local gateway authenticates with
the native grant its ctx.rest calls carry (minted by main, attached as a
header to that one dial). Also when the socket keeps retrying, when it
stops, and when it starts again.
- web_server_chat._ws_auth_reason: a socket that sends
X-Hermes-Gateway-Ticket is judged by that header alone, so a core socket
presenting it is refused even with a valid token query credential.
- web_server.py: why the web_server_dashboard import sits mid-module. It is
not an import cycle (web_server_dashboard reaches back only inside
functions); the load-bearing part is the middleware registration order.
Refs #134889 (PLG-1, PLG-8)
Refs #139523
A local Desktop talks to its gateway with authMode "native" and no static
token, so pluginSocket dialed /api/plugins/<id>/... with an empty ?token=.
The canonical WS gate (web_server_chat._ws_auth_reason) refused every such
upgrade: Kanban stayed on its 60 s poll, third-party ctx.socket was dead, and
the reconnect loop re-dialed every <=30 s forever, keeping an idle-exit
gateway awake.
The plugin socket now rides the credential its REST twin already uses on a
local gateway: the one-use native-http grant in X-Hermes-Gateway-Ticket.
- Gateway: GatewayRuntimeAPI stamps the raw socket peer on WebSocket scopes
too. PluginApiWebSocketGate redeems the grant once, ahead of routing
(native_http.redeem_native_ws: the HTTP seam's exact checks - single header,
no Origin, loopback peer, ready/served profiles, native-http purpose and
capability - plus the profile selectors, /api/plugins/ paths only), binds
the grant profile's home and secret scope for the whole connection, and
requires both that profile's and the launch profile's plugin consent before
accept. The route's credential check reads that principal and never
redeems. /api/ws and other core streams keep their purpose-bound credentials.
- Desktop main: hermes:plugin:ws-url mints the grant for the routed profile
and reserves a one-use dial bound to its origin (scheme, host, port) and
path. The path is checked one decoded segment at a time (dot segments, an
encoded slash or backslash, double encoding and bad escapes are refused),
then parsed with the real URL parser and required to stay under
/api/plugins/<id>/, and the dial records that parsed path. The webRequest
hook strips Origin and attaches the header only to an upgrade that matches
that dial, so the grant can't reach another host or another plugin's
path. The grant never enters a renderer URL. The redial/mint/prepare
branch shared by both gateway-socket IPCs moves to
local-gateway.localGatewayDial (main.ts stays under its line cap).
- Renderer: pluginSocket asks main for the URL when authMode is native, with
a deadline (a main process that never answers counts as a refused dial),
and stops after 5 dials in a row that never stay open, including a socket
that opens and closes at once (polling fallback stays).
Refs #134889 (PLG-1)
Refs #139523
17 conflicts, all from main's lint sweep (ruff UP007/UP017/UP022/UP028/UP031/UP037/UP041,
FURB188/FURB192); no other main commit touches a conflicted file. Resolution: the branch side
of each file plus main's exact autofix (ruff 0.15.10, main's ruff.strict.toml, --fix
--unsafe-fixes). ruff.strict.toml takes main's copy. The pool-retirement live fixture stays
deleted with the pooled backend this branch retires.
start_gateway_api imported hermes_cli.web_server (the whole dashboard FastAPI app, ~686 routes)
on the event loop before the session API listened: ~0.57 s of every cold `chat -q`, and it
stalled identify. The listener now serves the ticketed native /api/ws itself (same Host, peer and
loopback checks) and mounts the dashboard on its first request, imported off the loop, running
its own startup then. A gated listener (non-loopback bind or dashboard.public_url) still mounts
the dashboard before it listens; a gateway started without --idle-exit (Desktop, services) loads
it in the background right after READY. The light boundary helpers move to
hermes_cli/web_server_boundary.py (web_server keeps the names); the dashboard's own uvicorn
builder is unchanged, the gateway uses a FastAPI-free build_listener_server.
Cold `chat -q` (fresh home, loopback stub, archive trees, loaded host, 3 reps): base 4.59 s,
with this and the adapter fix 3.76 s, main 3.34 s.
Review: https://github.com/NousResearch/hermes-agent/pull/106742#issuecomment-6073624820
(cherry picked from commit e90fa09fd682b729123fd9d1103f99af5ed869d9)
45 conflicts, all from #135177 (lefthook + `ruff check --fix` over 2,366 files). No other main commit
touches a conflicted file. Resolution: the branch side of each file, then main's exact autofix
(ruff 0.15.10, `--config ./ruff.strict.toml --fix`) on it — rewrites only (typing generics, noqa
drops, import forms), no import removed. tests/cron/test_bot_chat_cli_home.py stays deleted
(1cc9cb9199 retired its lane).
No product surface launches the stdio entry any more (Ink and Desktop attach
to the profile gateway via ui-tui/scripts/gateway_bootstrap.py), but dev
harnesses still run it (apps/desktop/e2e/real-session-builder.ts,
scripts/probe_active_session_exclusivity.py) and it opens the launch home's
state.db as a writer. Run beside a live gateway it was a second writer on the
canonical store.
main() now takes the gateway's own gateway.lock reservation for the launch
home before anything opens state.db, exits 1 with a crash-log reason when the
home is owned, and releases it at exit. Holding the lock also keeps a gateway
from starting on the home while the entry writes. The e2e builder runs on a
sandbox home and closes before Desktop boots, so it is unaffected; the
exclusivity probe now asserts the startup refusal (verified live: all
checks pass). Fix the stale web_server_chat comment claiming gatewayClient
spawns its own entry.
(cherry picked from commit 4f21d3a8f758a8c1af22310a28f8665b3cb533ce)
Gate finding (quality, Low): the ValueError branch added for malformed
Origin authorities copy-pasted the origin_mismatch reason f-string, so the
format lived in two places. Map the parse failure to parsed=None and let
the existing mismatch return handle it. Behaviour unchanged (still fails
closed with 4403 origin_mismatch).
urlparse raises ValueError on bracketed authorities like "http://[::1" or
"https://[not-an-ip]:80". Three user-input boundaries let that escape:
the WebSocket Origin guard, /api/media/proxy and the custom-endpoint
base_url save, turning a bad header/param into an unhandled 500 instead of
a clean rejection. Fail closed there: 4403 origin_mismatch for the WS
guard, HTTP 400 for the two routes.
Salvaged from #131323 (net diff; the interim loopback-origin exemption the
PR added and then removed is squashed out).
Gated mode accepted only browser-minted ws-tickets and server-internal
credentials, but a token-mode Remote desktop connection bakes its
stored session token into ?token= (buildGatewayWsUrl) — so the WS
upgrade to /api/ws 403'd forever against a password-gated server even
though the same token authenticates REST fine. The REST bearer leg
already verifies session tokens via _verify_access_token; the WS leg
was the only inconsistent gate.
Gated ?token= is now verified against the dashboard auth session
providers (the same verify_session seam), stamps {user_id, provider}
identity, and audits success/failure (TOKEN_AUTH_SUCCESS/FAILURE). The
legacy in-process _SESSION_TOKEN stays rejected; a ProviderError (all
providers unreachable) rejects with token_unavailable instead of
crashing the upgrade; the bot-desktop display-ticket guard is kept.
Co-authored-by: salch-cred <141555468+salch-cred@users.noreply.github.com>
A fresh dashboard /chat always spawned the TUI in the dashboard process's
launch directory, so from a phone or any browser there was no way to aim
a new session at a specific repository. Amp's runners now serve many
directories and the web composer offers a picker of the runner's projects
and discovered git checkouts; this ports that mechanism onto the surface
Hermes already has: the dashboard is the phone/web front, the host's
projects.db + repo-discovery cache are the served directories.
- GET /api/chat/workspaces: the profile's projects (with folders) and
discovered repos (session-derived + scanned), default_cwd, home;
?scan=1 rescans desktop.repo_scan_roots on the host, so headless
installs (no Desktop to populate the cache) discover repos too.
- /api/pty?cwd=<dir>: validated (existing directory, fail-closed 400
via the PTY error path) and forwarded to the TUI child as HERMES_CWD
(self-spawned gateway cwd) + HERMES_TUI_CWD (explicit cwd on
session.create for the dashboard's in-memory gateway, whose own cwd
is the launch dir). Resumed sessions ignore it.
- ui-tui: session.create carries cwd when HERMES_TUI_CWD is set, so
/new inside a dashboard chat stays in the picked workspace too.
- web: workspace selector in the Chat rail above "New chat" (projects,
repos by recency, Other path…, rescan), remembered per profile in
localStorage; 17 locales.
- docs: web-dashboard.md rail + REST sections.
Live E2E: real `hermes dashboard` under a scratch HOME with two git
repos under desktop.repo_scan_roots -> /api/chat/workspaces?scan=1
lists both; /api/pty?cwd=repo-a -> TUI status bar shows ~/code/repo-a;
/api/pty?cwd=<missing> -> "Working directory does not exist" + close.
/api/ws consumed any ticket and stamped its identity; display.observe mints
provider "bot-desktop" tickets for viewers who may only be watching a screen,
so one of those redeemed on /api/ws became a full authenticated session.
Refuse bot-desktop tickets in _ws_auth_reason (reported as ticket_invalid, same
as the display route refuses gateway tickets).
(cherry picked from commit 753c3c35975fe1efab4a5bbc8bc6bbc9532b8521)
* fix(dashboard): prevent PTY input from blocking event loop
* fix(win-pty): don't terminate a healthy ConPTY on write cancellation; log leaked write workers
Review follow-up to the backpressure fix.
CancelledError on WinPtyBridge.write() ran the same path as a timeout and
force-terminated the ConPTY. Cancellation means the owning socket went away
mid-write, which is the keep-alive session's normal reattach case, not a
wedged child; killing the process there defeats the PTY-outlives-socket
design. Give the in-flight write the shutdown grace window and only
terminate if it never lands.
When terminate() fails to unblock pywinpty, the worker stays parked in the
default executor. That was swallowed by a bare except; log it so a slow
thread-pool starvation is diagnosable.
---------
Co-authored-by: Austin Pickett <pickett.austin@gmail.com>
For each issue anchor present in BASE 63279301bc non-test .py and absent on HEAD, the BASE comment/docstring block was re-attached at the HEAD location of the code it explained (matched by the distinctive code line / enclosing def). Sentences already covered by an existing HEAD comment were deduped; the issue number always survives. Insert-only: no code lines changed.