Commit Graph

3151 Commits

Author SHA1 Message Date
Teknium
67bce8c25d fix(slack): strip mention labels before emphasis parsing in rich_text
A labelled mention such as <#C1|dev_ops_alerts> or <!subteam^S1|@eng_team_x>
was split by the italic regex on its underscores before the leaf mention
split ran, so Slack showed the token literally with a stray italic run.
The label is dropped from the element anyway, so drop it up front.
2026-10-28 19:38:41 -07:00
Muneeb Anjum
a0f9c92bd7 fix(slack): render mentions as rich_text elements in rich_blocks
rich_text does not interpret mrkdwn, so <@U…>, <#C…>, <!subteam^S…> and
<!here|channel|everyone> tokens inside lists, quotes and table cells were
emitted as text and rendered literally. Split them into user/channel/
usergroup/broadcast elements at the emphasis leaf so surrounding bold/
italic/strike spans survive.

Fixes #133315. Squashed from #133323 (095821f, 53c8268, fcf7c97, 9fd0327).
2026-10-28 19:38:41 -07:00
Victor Kyriazakos
31d5f1d44d feat(whatsapp): log delivery and read status of sent messages to gateway.log
Baileys reports the delivery status of messages Hermes sends
(`messages.update` with `update.status` in 1:1 chats, a per-recipient
`message-receipt.update` in groups), but the bridge only handled poll
updates there, so operators could not see whether a reply was delivered
or read.

The bridge now queues a `delivery_status` event for status changes of its
own sends (tracked IDs only, so messages typed on the linked phone are
never reported). The adapter logs one gateway.log line per change and
never dispatches it as an inbound message.
2026-10-28 19:34:11 -07:00
Teknium
f3acd8ff33 fix(whatsapp): run the bridge reaps off the gateway event loop
The reaps now wait out a SIGTERM grace (up to 6s each) with time.sleep, and
connect() called them inline on the loop every platform shares, freezing
Telegram/Discord/etc. while a slow WhatsApp bridge exited. Run them via
asyncio.to_thread. The psutil-fallback test reads /proc of every process,
which names files under the real Hermes home on a box running Hermes, so
it opts out of the home write guard.
2026-10-28 19:21:20 -07:00
Teknium
7b90783f76 fix(whatsapp): keep main's TIME-WAIT-aware port_is_free for the respawn wait
Replaying the branch onto main linearly resurrected port_accepts_listen, the
duplicate helper the branch dropped when it merged main (#140186 already
gives port_is_free the bridge's SO_REUSEADDR semantics). Restore the merged
tree: one helper, one contract.
2026-10-28 19:21:20 -07:00
unsupportedpastels
fb45657d55 fix(whatsapp): don't treat the old bridge's TIME_WAIT as a busy port
The port-free wait used a plain bind probe, which Linux refuses while the
previous bridge's closed connections sit in TIME_WAIT (up to 60s). node's
listen sets SO_REUSEADDR and succeeds then, so a normal restart failed with
whatsapp_bridge_port_busy after 10s and waited for the reconnect backoff.
Probe with SO_REUSEADDR on POSIX so only a live listener blocks the spawn.
2026-10-28 19:21:20 -07:00
Victor Kyriazakos
29b44be139 fix(whatsapp): wait for the old bridge to release its port before respawning
connect() SIGTERMed the previous bridge, slept a blind 1s and spawned the
new one regardless. A bridge that was slow to exit (or ignored SIGTERM)
still held 127.0.0.1:<port>, so the new bridge died on EADDRINUSE and the
reconnect loop retried the same race forever.

- _kill_port_process / _kill_stale_bridge_by_pidfile wait out a SIGTERM
  grace, then SIGKILL survivors after re-checking identity (a PID recycled
  inside the window is never signalled).
- connect() replaces the blind sleep with a bounded bind-probe wait for the
  port and fails with a named retryable whatsapp_bridge_port_busy instead
  of spawning onto a busy port. A holder that is not our bridge is still
  never killed.
- Listener discovery falls back to psutil when neither lsof nor ss is
  installed; without it the scan was silently empty and nothing was reaped.
- A bridge that dies during the post-spawn health wait no longer leaves a
  dead-PID bridge.pid; disconnect() waits for a force-killed bridge to exit.
- bridge.js handles the listen error and exits with a clear EADDRINUSE
  message instead of an unhandled stack trace.
2026-10-28 19:21:20 -07:00
Teknium
f7641ace78 fix(web): pair a cached body with its own final URL; keyless Firecrawl reports its redirect target
The cache body and its final-URL annotation were separate writes, so two fetches of one key
interleaved as A-put, B-put, B-final, A-final left B's body validated against A's destination.
The index entry now records the body's sha256; the final-URL write is compare-and-set on it and
a hit is served only when the body on disk matches the entry it was recorded for.

The keyless Firecrawl path returned the requested URL and dropped metadata.url, so the shared
redirect gate never saw the destination. It now reports metadata.url (sourceURL = requested).
2026-10-28 13:54:02 -07:00
Teknium
6fc7c7dbf2 fix(web): Firecrawl re-checks the website policy against the URL it was redirected to
_scrape_one read metadata.sourceURL as the post-redirect URL, but Firecrawl
reports the REQUESTED url there (sourceURL on REST, source_url in the v4 SDK's
model_dump used by the direct-key and Tool Gateway paths) and the final URL as
metadata.url. The SSRF / website-blocklist re-check therefore re-checked the
requested URL, and a public redirector returned a blocklisted page.

Read the final URL from metadata.url, and fill sourceURL from source_url so the
extract cache still files a redirected page under the requested URL.

Found on Hermes Cloud staging.
2026-10-28 13:54:02 -07:00
Teknium
6696c7b0a4 fix(web): Exa and Keenable origin statuses never read as vendor throttling
Keyless Exa reports the target's status as CRAWL_HTTP_<code> / CRAWL_NOT_FOUND and
Keenable mirrors it as its own HTTP status with a "The target server ..." message.
Neither used the "HTTP <code> from origin" shape, so a site's own 429 walked the
keyless extract ring as if the vendor throttled us, and a 404 read as a vendor
failure with an API-key hint. Normalise both (keyless and keyed paths) into the
origin shape; Keenable's own rate limit and refusals keep the vendor wording and
still fail over.
2026-10-28 13:13:12 -07:00
Teknium
85af2bb438 fix(web): an origin HTTP 429 never walks the keyless extract ring
The new "HTTP 429 from origin" error matched the ring's rate-limit predicate,
so a site's own 429 failed over Parallel -> Firecrawl -> Keenable -> Exa and
returned Exa's error instead of the origin's. Origin errors are the page's
answer; vendor-side 429s still fail over.
2026-10-28 13:13:12 -07:00
Teknium
76911b77f2 fix(web): an origin HTTP 4xx/5xx never triggers the keyless extract rescue
The rescue exists for backend outages. A batch whose URLs all answered 404/410
is the pages' own answer, so re-fetching it through the keyless ring wasted a
request and contradicted _dispatch_extract's docstring. Origin-status errors
(the "HTTP <code> from origin" shape) are now excluded from the whole-batch
trigger; backend failures still trigger it.
2026-10-28 13:13:12 -07:00
Teknium
f7dde7f56d fix(web): web_extract reports a target's HTTP 4xx/5xx as an error on every extract provider
Scraping vendors answer 200 and report the target page's own status inside the
payload. Firecrawl (direct key, Nous Tool Gateway, keyless REST) put it in
metadata.status_code / statusCode and Hermes never read it, so
web_extract("https://httpbin.org/status/403") returned the stub error page
with error: null: the agent could not tell blocked from blank, the keyless
rescue never ran, and the error page was cached as content.

One shared helper in plugins/web/_common.py (origin_http_error /
with_origin_status / vendor_error_entry) now turns an origin status >= 400
into "HTTP <code> from origin[: reason]", keeping any error-page body as
content. Applied to:
- Firecrawl SDK/gateway scrape and the keyless REST scrape (both key spellings)
- Parallel keyed + keyless (error was the bare "http_error"; the payload's
  http_status_code was dropped)
- Exa keyed (URLs Exa could not fetch were silently missing from results;
  their reason lives in response.statuses)

Tavily, Perplexity and Keenable already surface per-URL failures (Tavily's
failed_results carry no status code).

Salvages the Firecrawl statusCode check from #99549 (and #99556), which read
only the camelCase key and only flagged empty content, so it missed the
Gateway/SDK case where the 403 body is a non-empty stub page.

Found on Hermes Cloud staging.

Co-authored-by: liuhao1024 <sunsky.lau@gmail.com>
Co-authored-by: Ahmett101 <ahmet.tunc@gmail.com>
2026-10-28 13:13:12 -07:00
Teknium
e1be6fcfe0 fix(config): config_keys come from the loader's discovery, count only for active plugins, never widen a section
Review findings on the config_keys seam:

- Discovery: drop the glob scan. config_keys is parsed onto PluginManifest
  (plugin.yaml, and extensions.com.nousresearch.hermes in a portable
  plugin.json) and read from the loader's own collect_directory_manifests +
  entry points + resolve_manifest_winners, so skip rules, precedence and the
  project-plugin gate are the loader's.
- Only active plugins count: gate_manifest must load the plugin (disabled wins,
  plugins.enabled opt-in, requires_hermes); memory providers count when
  memory.provider selects them.
- Bounded: a declared path is at least two segments deep and is ignored when
  DEFAULT_CONFIG already defines it; runtime keys are consulted only after the
  schema walk refused a key, so a plugin declaring [agent] no longer hides
  agent.max_turnz.
- No lru_cache: a plugin installed or enabled in a long-running process counts
  on the next config get/set (the lookup runs only for refused keys).
- computer_use.backend (read by the plugins/computer_use selector) and
  dashboard.kanban move to a core table with their readers; the selection
  sections derive from read_selection's own _SELECTION_NAME_KEYS.
- Tests use fixture plugins (enabled/disabled, hostile [agent], selected memory
  provider, portable plugin.json, project opt-in).
2026-10-28 13:09:00 -07:00
Teknium
e402afa783 fix(config): recognize runtime-read selection and plugin-declared keys in config get/set
`hermes config get browser.cloud_provider` / `browser.use_gateway` warned "not a recognized
config key" although the runtime selects the browser provider from them. The validator only
walks DEFAULT_CONFIG, and provider selections stay unseeded on purpose (a stored key is the
explicit pick), as do core-section keys plugins read.

- tools.tool_backend_helpers.selection_config_keys(): the keys read_selection() honours
  (<category>.use_gateway, browser.cloud_provider, stt/tts/image_gen/video_gen provider keys,
  web.backend/search_backend/extract_backend).
- plugin.yaml / dashboard manifest.json `config_keys`: a plugin names the core-section paths it
  reads; declared for retaindb, byterover, computer_use/cua, kanban dashboard.
- hermes_cli/config_runtime_keys.py consults both before the DEFAULT_CONFIG walk.

Found on Hermes Cloud staging.
2026-10-28 13:09:00 -07:00
ethernet
2edfd0d369 feat(auth): the deployment session token authorizes the gated dashboard
A token-only deployment (nix/agenix: backend.sessionTokenFile ->
HERMES_DASHBOARD_SESSION_TOKEN=file:<path>) had no way to satisfy the
June-2026 fail-closed gate: gated mode demands a registered
DashboardAuthProvider, the interactive prompt then writes basic-auth
credentials the deployment never asked for, and the provisioned token
itself is rejected on every gated leg (REST 401, /api/ws 403) — the
desktop's 'HTTP reachable but the WebSocket fails' incident.

The bundled session_token plugin closes that: it registers whenever the
session token is provisioned (skippable via
dashboard.session_token_auth.enabled: false) and verify_session
constant-time-compares the presented credential against it. Both legs a
token-mode client uses — the REST bearer path and the /api/ws ?token=
upgrade — run through that seam, so one provisioned token authorizes both.

It is deliberately not an interactive login: a new interactive_login
capability flag keeps it off the login page, /api/auth/providers, the
auto-SSO redirect and the native provider chooser (a token-gated /login
now renders a note explaining the credential channel), while
supports_session stays True so the gate's verify loops consult it.

Rotation semantics are pinned by tests: a saved client copy from before a
secret redeploy must fail closed, not half-work.
2026-10-28 13:49:47 -04:00
kshitijk4poor
aecf04f3d8 fix: an answered Discord approval whose click edit fails still retires its card
When a click records the answer but Discord rejects the interaction
edit, the view was stopped but the card kept its pending embed and
dead buttons. The settle observer skips cards whose click owns the
edit, because `_backend_settled` was already set.

Now a failed edit after a recorded answer clears `_backend_settled` and
retires the card through its message: buttons removed, "already
resolved" footer. The retire runs under the same lock as the
observer's, so only one of them edits. The edit error is still raised,
as before. A failed edit on a no-op click (nothing recorded) is
unchanged.

Tests:
- The edit-failure case of test_click_stops_view_even_if_interaction_edit_fails
  now asserts the card is retired.
- A new test fires the observer during the failing edit (the usual
  order, since the waiter wakes before Discord answers). The observer
  skips, and the click's own retire stamps the card.

Both fail on the previous commit. The new test also fails with only
the retire call removed.

Reported by Greptile on #145948.
2026-10-28 15:28:40 +05:30
kshitijk4poor
e0e3349ed3 refactor: move the Discord exec-approval view into a sibling module
adapter.py was already far past the 2,000-line limit, and this stack
grew it from 7,414 to 7,512 lines. AGENTS.md lets a unit that is
already over the limit only shrink. The file's FILE_LINES allowance
covers an earlier platform-table move, not the approval code.

ExecApprovalView now lives in adapter_exec_approval_view.py. Its body
moved verbatim: build_exec_approval_view(discord, base, unauthorized=...)
returns the class, and _define_discord_view_classes assigns it to the
same module global as before. The one change inside the body: the
failed-lookup log now carries its traceback (exc_info=True), which the
health check requires of a catch-all in a new file. A builder is needed because discord.py
can be installed lazily after the adapter is imported, and the other
views are defined the same way. adapter.py ends at 7,374 lines, 40 below
main.
2026-10-28 15:28:40 +05:30
kshitijk4poor
50f57a131f fix: a stale Discord approval click leaves the card to the request's observer
Item 1 of the review is only partly fixed by the stale-click commit
before this one. Clearing `_backend_settled` lets the settle observer
retire the card, but the click still edited the same card with
"Approval expired — command was not run" through its own interaction
response. Nothing serializes that edit with the observer's. If the
click's edit lands last, it hides the real outcome and reattaches the
disabled controls. Discord serializes the interaction payload before
awaiting the response, so a later embed change can't repair it.

When a click on a card with a request id resolves nothing, that request
has already settled through another path. Since the earlier commits, its
observer is always registered (it is registered before the send, and a
request gone before that already retires the card). So the click now
only answers the clicker privately ("no longer pending") and leaves the
card edit to the observer.

A click whose lookup raises recorded nothing, and its request may still
be pending. It used to stamp the card "expired — not run" and disable it
for good, and that edit could race the observer too. Now it re-opens the
card for a retry, tells only the clicker ("Couldn't record your choice.
Click again, or answer with /approve or /deny." — a new string in every
locale), and leaves the final edit to the observer. A card without a
request id has no observer, so its no-op click keeps the old "expired"
edit.

Tests:
- The stale-click regression now asserts that the click never edits the
  card. It fails on the previous commit.
- A new test drives a failed lookup on a really pending request with its
  observer attached: the card stays live, and a later text answer
  retires it with the real outcome.
- A third test pins the expired edit on a card with no request id.
2026-10-28 15:28:40 +05:30
kshitijk4poor
8654f1a684 fix: answered Discord prompts release their view
Raising the `discord_prompt_timeout` cap to the platform-safe maximum
makes a gap much larger. Slash-confirm, update and clarify views never
called `stop()` when answered; only exec approvals did. discord.py keeps
an unfinished view registered after the answering edit, and its timeout
task sleeps until expiry with no upper bound.

So every answered prompt stayed registered for the whole configured
timeout, now up to a year. When the timeout finally fired, the base
`on_timeout` stamped "Prompt expired — no action taken" over "Approved
by X". The overwrite already happened on main within 900 s; the higher
cap only delays it.

`_finalize_embed` (slash confirm, update, exec approval) and the clarify
`_finish` now stop the view in a `finally`, after the answering edit, so
an edit failure still releases it. The exec view's own `finally: stop()`
is now covered by `_finalize_embed` and goes away.

New parity test: an authorized answer on each of the three views (and
the clarify "Other" hand-off) leaves the view finished. All four cases
fail on the previous commit. Exec cards stay covered by
test_discord_approval_lifecycle.
2026-10-28 15:28:40 +05:30
kshitijk4poor
b5caaf7b44 fix: a Discord approval card that settles mid-send shows how it ended
The card registered its settle observer only after `channel.send`
returned. If the request ended during the send (wait timed out, /stop,
session closed, withdrawn), the registration found no entry and the card
retired with the default reason "resolved". The card then said "This
approval has already been resolved" for a command that never ran.

Build the view first and register the observer before sending. A reason
that arrives while the card is still in flight is held on the view
(`pending_retire`) and applied as soon as the card exists. Only a
request that was already gone before the card was built still has an
unknown outcome. That card now says "⌛ This approval is no longer
pending (it timed out or was answered elsewhere)", a new outcome-neutral
string, translated in every locale. It no longer claims either
"resolved" or "not run".

Building the view outside `_build` also removes the `view_holder` list
that only existed to get the view back out. The view never depended on
the channel.

The test now covers the three orderings (after, during, before the send)
and asserts the footer. Two of them fail on the previous commit.
2026-10-28 15:28:40 +05:30
kshitijk4poor
cfed2ca71f refactor: pass the approval request id explicitly, not through platform metadata
The runner tunnelled the approval request id to Discord as a private
`_approval_request_id` key inside the platform metadata dict. That dict
goes to every adapter that renders approval buttons. The relay adapter
forwards it verbatim, so the private key reached the external connector
in every approval prompt frame.

Add an optional `request_id` to `send_exec_approval` and to
`ExecApprovalPrompt`, have the runner pass `approval_data["request_id"]`,
and have Discord read `prompt.request_id`. The metadata passed to the
adapters is back to the thread routing it carried before the PR (`None`
in a plain chat). The always-true `"timeout_s" in approval_data` guard
goes with it.

Native-button adapters render through `_send_exec_approval_prompt`,
whose signature is unchanged. The only `send_exec_approval` override,
`LocalSessionAdapter`, takes `**kwargs`, as does every test double, so
no other adapter or double changes.
2026-10-28 15:28:40 +05:30
赵桂雄
ac50e08b54 fix: preserve resolved Discord observer after stale click
A stale button click that resolves zero gateway approvals must not mark the backend settled and suppress the already queued resolved observer. Cover the external-answer to stale-click race through the real component gate.
2026-10-28 15:28:40 +05:30
Gille
39b2158afc fix: preserve configured Discord timeouts and retire approval views 2026-10-28 15:28:40 +05:30
Gille
4f86e97791 fix: align Discord approval buttons with request timeout 2026-10-28 15:28:40 +05:30
Teknium
e3d0046203 fix(config-remote): a rotated IdP client secret fetches a new token
The IdP token cache was keyed on (token_url, client_id, scope), so a
rotated GATEWAY_RELAY_IDP_CLIENT_SECRET kept serving the bearer cached
under the old secret until it expired. The key now includes a digest of
the secret.
2026-10-27 17:33:48 -07:00
Teknium
714eab92e9 fix(config-remote): an explicit config set is stored even when it equals the inherited value
`hermes config set display.skin ares` with `ares` already supplied by an
upper level printed "Set ... in Remote Config" but sent no PATCH: the
document save diffed the key away as unchanged. A later upper-level
change then replaced the user's choice.

Keyed Changes.set and keys named in a new `pinning_keys()` block (the
CLI's `config set` document save) are now sent even when unchanged,
matching the file backend, which always writes them to config.yaml.
A key a lock already freezes is skipped, not refused.
2026-10-27 17:33:48 -07:00
Ben Barclay
748b71cef7 fix(config-remote): a configured URL's user info is never echoed in messages
destination.display_url() drops user:password@ from a URL (an unparsable one is cut at the last
@). The boot error, describe(), the user-layer provenance, the destination policy's own errors,
the redirect refusal and the IdP failure all show that form; the request itself still checks
(and refuses) the URL as configured.

Addresses teknium1's P3 (refused URL echoed with credentials) on #122509.
2026-10-27 17:33:48 -07:00
Ben Barclay
5da4eeb03c refactor(config-remote): backend.py uses diff.py's path helpers instead of its own copies
backend.py and diff.py each defined _set_path/_pop_path, and the two _pop_paths already returned
different things (None vs bool). backend.py now imports diff.py's pair; its callers ignore the
result, so only the duplicate goes.

Addresses teknium1's P2-3 on #122509.
2026-10-27 17:33:48 -07:00
Ben Barclay
f292c4c357 fix(config-remote): the poll interval is a constant, not a HERMES_* env var
HERMES_CONFIG_REMOTE_POLL_SECONDS is gone: the interval is 300 s (the 30 s floor stays), so no
new non-secret HERMES_* env var is needed before config can be read. A plane-served interval is a
later cross-repo change. The environment-variables reference now lists HERMES_CONFIG_REMOTE_URL
and HERMES_CONFIG_INSTANCE_ID next to HERMES_CONFIG_BACKEND, with why each must be env.

Addresses teknium1's P2-2 on #122509.
2026-10-27 17:33:48 -07:00
Ben Barclay
3f903abeed refactor(config-remote): core resolves a backend kind generically and asks it through the protocol
HERMES_CONFIG_BACKEND=<kind> now resolves to plugins.config_backends.<kind>.get_backend() (a
direct import, never the general plugin loader, D11), with the kind checked against a package-name
pattern before any import. What core read from the remote plugin's internals is a protocol method
with a no-op FileBackend version: bootstrap_env_names() (env_loader's .env bootstrap),
preserve_read_base() (keeping_read_base) and doctor_warnings() (hermes doctor).

Addresses teknium1's P2-1 on #122509.
2026-10-27 17:33:48 -07:00
Ben Barclay
c0c74d20e4 fix(config-remote): serve main's ConfigBackend.cache_version from the remote backend
main (76f2fdb794, 5f02a8c19e) added cache_version to the ConfigBackend protocol and keys
every parse cache (load_config, the TUI raw read, profile reads) on config_cache_version.
The remote backend lacked it, so every cached read in remote mode raised AttributeError.
Its version is already exact (etag + local generation), so cache_version returns it
unchanged. Test: config_cache_version follows the remote version across a poll; without
the method 41 tests in test_remote_backend.py fail.
2026-10-27 17:33:48 -07:00
Ben Barclay
e4374020bd fix(config-remote): adapt the remote backend to the seam as merged in #134362
puts back what that build deliberately left for the remote backend, on
main's seam shape:

- RemoteBackend implements main's protocol (read_user_doc, probe_readable)
  and is not a FileBackend; _route returns (backend, home) and explicit
  files go through _ExplicitFile, so the is_layer branches are gone.
- One bootstrap: _ensure_bootstrap_env / bootstrap_deployment select the
  backend from the process env, the launch home's .env and the managed .env.
  #134362's _dotenv_backend_override did not survive its file-only refactor,
  so nothing stacks; its rules are now tests (stale shell remote + .env file
  boots file; empty .env value resets to file; .env-only remote selects
  remote; an absent key keeps the shell value).
- The file-tooling gates main removed (backup/import/snapshot restore,
  config edit, migration write-back, config backups, profile clone and
  distribution install, raw config editor, xAI migration, gateway --config).
- profile_serve_signature uses the backend version for config.yaml.
- restore_config_model_settings_if_rewritten is a no-op without file tooling.
- PM's dependency runtime reads a home's selection from the local file it
  publishes to (config_backend.local_file_layer), so a remote deployment
  never needs the plane there or fails PM closed.
- Ratchet: _container_slots/_validate_quoted_containers move to
  config_value_checks, _count_cron_jobs to backup_restore, the gateway
  --config load to gateway/config_loader.
2026-10-27 17:33:48 -07:00
Ben Barclay
60c215db4c fix(config-remote): review round 9c: dashboard model saves keep the credential mask and refuse late locks
1. _resolve_assignment_credentials (POST /api/model/set) and the custom-endpoint make_default /
   activate paths replaced an inherited model.api_key with the target provider's key_env by
   popping it. Under Remote Config the block is the effective one, so the pop became a profile
   unset that cannot reach the upper level, and the inherited inline key (which outranks key_env
   at runtime) stayed active at the new endpoint. drop_model_key stores null for a key the
   effective block holds (file backend: plain removal), the same mask apply_model_selection uses.
2. remote_model_selection_guard is a preflight; a lock published after it was still silently
   omitted from the document save, landing a half route with ok=true. New
   config_backend.refusing_locked_omissions("model") scope: the remote backend's document intent
   raises ConfigLockedError (HTTP 403, nothing sent) when a lock it sees at save time covers a
   changed key under the scoped prefix. Wrapped around every whole-document model assignment save
   (dashboard main slot, profile builder, custom endpoint make_default / activate). The CAS retry
   already refuses a locked key through _patch_body's write_check.

Regressions:
test_dashboard_model_switch_keeps_mask_when_target_provider_carries_key_env (fails with the pop
restored), test_dashboard_model_switch_refuses_when_a_lock_lands_after_the_guard[poll] (fails
with the scoped refusal disabled), [cas-retry] (coverage of the existing retry refusal).
2026-10-27 17:33:48 -07:00
Ben Barclay
b1bbb51e21 fix(config-remote): review round 9 blockers: read-based save diff, masked inherited route keys, honest editor acks, UTF-16 bootstrap parse
1. A document save is diffed against the base the saving context READ (per-context
   _READ_BASE recorded by read_user_layer / read_user_doc_readonly / version and after the
   context's own acknowledged write), not against whatever a poll installed between the read and
   the save. save_config's fail-closed guard read keeps the caller's read base. A poll before save
   no longer turns its changes into our unsets/sets with the current expectedVersion.
2. persist_model_selection (remote): a key the switch clears that the effective model block
   still holds is stored as null ("no value", contract 5.4), not unset at the profile level, so
   an upper-level old-endpoint api_key/key_env/api_key_env/context_length stops applying at the
   new endpoint. New config_backend.write_changes carries explicit nulls.
3. profiles.configure: skills / toolsets / MCP sections report applied only when the section
   reads back as written; a bulk save that dropped a locked key is no longer acknowledged.
4. _dotenv_assignments decodes UTF-16 (BOM) and strips NULs as the runtime sanitizer does, so
   stage2 / first-read selection agrees with the backend the runtime boots.

Regressions (each fails with the production change reverted):
test_poll_between_read_and_save_sends_only_the_callers_edit,
test_model_switch_masks_inherited_endpoint_credentials,
test_profile_editor_reports_a_locked_skills_edit_as_not_applied,
test_stage2_decides_like_the_runtime_for_utf16_dotenv[utf16-bom|utf16-no-bom].
2026-10-27 17:33:48 -07:00
Ben Barclay
5719daa071 chore(config-remote): meet main's ruff rules and the PR's config-reader gate after the rebase
The rebase onto main brought new lint rules (UP006/UP037/RUF100/RUF059/PLW1510/B009) that the
PR's own files did not meet, and main code that reads/writes config.yaml directly, which the PR's
reader gate (scripts/check_config_yaml_readers.py) refuses. No behaviour change in file mode.

- ruff --fix (safe fixes only) on the PR's files; explicit check=False / unused-name fixes in tests.
- gateway/session_config.py (new on main): the multiplexed 'mtime' getter uses config_version /
  config_exists, like tui_gateway's _cfg_get_mtime.
- hermes_cli/prune_advisor.py (new on main): decide() writes sessions.auto_prune through
  config_backend.write_config_key (a remote refusal is the existing "could not save" answer).
- hermes_cli/profiles.py _strip_multiplex_flag (new on main): config_exists, not Path.is_file().
- hermes_cli/config_backups.py / update_receipt.py: annotated as file tooling / pre-swap
  interpreter (both already gated on file tooling or run without the backend importable).
2026-10-27 17:33:48 -07:00
Ben Barclay
55805716e7 fix(config-remote): credentials go only to the configured https origin, never through a redirect
andrexibiza P1-A. The plane bearer (client.request) and the IdP client secret (_idp_token) were
sent to whatever HERMES_CONFIG_REMOTE_URL / GATEWAY_RELAY_IDP_TOKEN_URL held, over urlopen's
default redirect-following opener.

New remote/destination.py is a transport policy, not a host allow-list (D19 keeps the plane URL
operator-selected):
- https only; plain http only to localhost / 127.0.0.1 / ::1 (tests, local development);
- no user info, query or fragment in the configured URL (an ambiguous destination);
- credentialed requests use an opener with no redirect handler: any 3xx raises
  CredentialDestinationError instead of being followed.

The URL is checked before the bearer is resolved and before the IdP secret is encoded, so a refusal
sends nothing. CredentialDestinationError is a non-retryable PlaneCredentialError: boot fails
closed at once (no retry sleeps), writes refuse with config_plane_unreachable.

Tests (test_remote_credential_destination.py, 25): foreign ambient http origin, https->http
downgrade of the default, other schemes, userinfo/query/fragment refused before send with the
bearer never resolved; D19 default, on-prem https and loopback http allowed; real cross-origin
301/302/303/307/308 from a loopback plane and 302/307/308 from an IdP: the target listener sees
no request; boot through the real backend fails closed with zero plane/token requests. All 25
fail with client.py/credentials.py reverted.
2026-10-27 17:33:48 -07:00
Ben Barclay
2e36106171 fix(config-remote): config set/unset name Remote Config, not a config.yaml that is never written
With HERMES_CONFIG_BACKEND=remote the success line printed get_config_path() although the write
went to the plane's profile level and no local file exists. The backend now names its write
destination (ConfigBackend.destination); the file backend keeps the path byte for byte.
2026-10-27 17:33:48 -07:00
Ben Barclay
f15b518b25 fix(config-remote): review round 7 — grouped edits are one write, readers see only completed migrations
1. Grouped edits: new write_config_keys(path, {key: value}) sends related keys as ONE backend
   write (one CAS PATCH in remote mode), so a lock on any key refuses all of them.
   persist_model_selection, the TUI /focus setter and the thinking_mode setter use it; the TUI
   gets _write_config_keys (one raw round-trip save with the file backend). File-mode writes
   are unchanged (key by key, comment-preserving).
2. Migration reads: _postprocess has no single flight any more. A reader or writer that finds
   the published doc unmigrated runs its own private pass; the first to finish publishes
   (generation-fenced, st.postprocessed set only on publish). read_user_layer /
   read_user_doc_readonly snapshot only completed output (_snapshot re-completes when a poll
   lands in between), and write_changes prepares only against completed output. Waiting on the
   other pass instead could deadlock on _CONFIG_LOCK; private recursion is unchanged.
3. Docs: developer-guide/config-backend.md says the remote backend ignores the managed
   config.yaml while the managed .env still applies.
2026-10-27 17:33:48 -07:00
Ben Barclay
9803082be8 style(config-remote): drop trailing blank line in values.py 2026-10-27 17:33:48 -07:00
Ben Barclay
fd059c01f4 fix(config-remote): review round 4 — leaf-level CAS intent for new sections, D32 guard on routed secret-source hydration, config-only in-memory migrations, bootstrap completes before other threads select, project .env in the early bootstrap, keyed TUI section/prompt/consent setters 2026-10-27 17:33:48 -07:00
Ben Barclay
6dd799b30a fix(config-remote): review round 3 — intent-preserving CAS retry, private in-memory migration, poller roster snapshots, dotenv+managed bootstrap before the first read, deployment carried into routed children, remote-safe profile create/rename, backend-versioned roster cache, keyed TUI edits, RPC answers on backend refusal, stage2 uses the runtime's selection, refuse values a pending migration would rewrite 2026-10-27 17:33:48 -07:00
Ben Barclay
58504aab4a test(config-remote): vendor portal-groups fixtureVersion 2 conformance set; multi-group response, group lock and opaque ETag v2 regressions
- Re-vendor conformance/ from gateway-gateway 36dff9281f (gg #328): the 35 v1 files are
  byte-identical, plus the 12 multi-group fixtures of portal-groups contract §7.2 (each sha256
  checked against the contract table). APPROVED_FIXTURE_DIGEST e7e92b9b… -> 3fdf7068…
- The runner reads only profile writes, expect.locks[path, level] and defaultsMerge, so v2 needs
  no code change; a new check pins fixtureVersion to {1, 2} so a future format is reviewed.
- Stub plane can emit group levels, groupProvenance and lockedByGroupId; tests prove these are
  ignored, a group lock refuses client-side as lockedBy group, the plane's group 403 maps to
  ConfigLockedError + dashboard 403, and the ETag is echoed verbatim.
2026-10-27 17:33:48 -07:00
Ben Barclay
99e5ea1796 fix(config-remote): review round 2 — staged secret-source publication, generation-checked migration, plane value refusals
- env_loader: secret sources apply into a private staging copy of the
  environment; the D32 protected-name check runs before anything is
  published to os.environ, so a refused plane URL/credential is never
  visible to a concurrent request (the poller reads them live).
- remote backend: the doc's schema version and generation are captured
  together under st.lock; a migration whose doc was replaced before it
  starts (or at any step/commit) never touches the replacement.
- remote backend: plane value refusals (config_value_invalid,
  config_path_invalid/reserved, config_secret_literal, 413 too_large)
  become ConfigValueError; the dashboard maps them to 400/413 with the
  plane's message; config_request_invalid and others stay opaque.
- stub plane enforces the contract §11.1 depth limit; bulk-save test
  asserts the exact PATCH.
2026-10-27 17:33:48 -07:00
Ben Barclay
f0def49876 fix(config-remote): stamp writerConfigVersion only when the profile level's stored data is current
Contract §5.3 (absent = unchanged): an unrelated write from a newer agent no longer
re-stamps a profile level that still stores pre-migration keys, so later readers keep
running those migration steps (D12, R6). A newer stamp is never lowered. The stub plane
now honours 'absent = unchanged' too.
2026-10-27 17:33:48 -07:00
Ben Barclay
23b346f6cb fix(config-remote): review round 1 — boot selector latch, stale polls, migration diffs, dashboard refusals
1. Secret sources can no longer switch remote mode off. The backend is selected BEFORE
   apply_all and the protected-name check judges by that backend; HERMES_CONFIG_BACKEND is
   never a source's to set (reverted; remote mode exits, file mode warns and drops it).
2. A poll GET that a write (or a newer fetch) overtook is dropped instead of installed: every
   install bumps a sequence the GET captured when it started. profileVersion alone cannot tell
   (an upper-level change keeps it equal).
3. Writes diff against the doc readers got, i.e. migrated in memory (D12), also after the CAS
   re-read: an unrelated edit no longer sends the migration's unsets. A migration step for a
   doc a poll replaced mid-migration is dropped.
4. Dashboard: expected config refusals keep their message (lock 403, value 400, conflict 409)
   through http_failure; anything else stays an opaque 500.
5. Conformance: the fixture digest is pinned to a literal (contract §13.4).

Stub plane: deep_merge now ignores null over a mapping (contract §6.2); docstring says it is a
test double, not server-conformance evidence.
2026-10-27 17:33:48 -07:00
Ben Barclay
503dcc90a2 fix(config): read the vendored secret-key fixture BOM-tolerant (windows footgun lint) 2026-10-27 17:33:48 -07:00
Ben Barclay
fa08fa90d0 fix(config): remote backend — no st.lock across migrations, re-arm poller after fork, classify poll refusals by status 2026-10-27 17:33:48 -07:00
Ben Barclay
69d037b349 feat(config): remote config backend (HERMES_CONFIG_BACKEND=remote)
plugins/config_backends/remote serves each profile's user layer from the
config plane: boot fetch inside load_hermes_dotenv with bounded retry and
fail-closed exit (D2), per-process ETag poller (D9), key-level diff writes
with CAS and one conflict retry (D10), client-side lock and secret-literal
checks (D7, D17), in-memory migrations (D12), managed config.yaml ignored
(D18), plane credential from auth.json or IdP client credentials only and
never from a secrets: source (D26, D32). Vendored gg conformance fixtures
run against the lock matcher, secret rule and _deep_merge.
2026-10-27 17:33:48 -07:00
Teknium
2a8413a52e fix(webapp): self-hosted sign-in admits whom it admitted on main, each as the machine owner
Maintainer ruling: an owner restriction on self-hosted OIDC adds no real protection, because
anyone the login provider lets in already gets the agent and terminal as you on main. Remove the
first-sign-in owner pin (owner_pin.py, dashboard-auth/self-hosted-owner.json) and the
dashboard.oauth.self_hosted.owner check; the self-hosted provider is back to main's code. Who may
sign in is decided by the login provider's app configuration, and the docs now say so.

The hosted-room daemon test signs in two different IdP accounts again (as on main); both act as
the owner and share one Group Chat list.
2026-10-27 17:32:49 -07:00