Commit Graph

281 Commits

Author SHA1 Message Date
Ben Barclay
b8a41f7bf2 fix(config-remote): review round 9b: guard reads keep the caller's read base, dashboard model saves mask inherited route keys, MCP ack checks every toggle field
1. _write_config_state (atomic_config_write: /verbose, /footer, ...) runs its no-omission guard
   read under keeping_read_base, like save_config, so a poll between the caller's read and its
   save no longer becomes the base its stale document is diffed against.
2. Dashboard / profile model assignments (_apply_main_model_assignment: POST /api/model/set,
   profile builder, custom endpoints) share persist_model_selection's semantics under Remote
   Config: apply_model_selection(mask_cleared=True) stores null for a cleared key the effective
   block holds, and remote_model_selection_guard refuses the whole assignment when any changed
   model.* key is locked (a bulk save would otherwise omit it and land a half route).
   persist_model_selection now builds its keyed write from the same _merge_selection_updates.
3. profiles.configure MCP acknowledgement compares enabled AND the legacy disabled field per
   server, so a lock that kept disabled: true reports mcp_servers unapplied.

Regressions (each fails with the production change reverted):
test_poll_between_read_and_atomic_config_write_sends_only_the_callers_edit,
test_dashboard_model_switch_masks_inherited_endpoint_credentials,
test_dashboard_model_switch_refuses_whole_assignment_on_a_locked_route_key,
test_profile_editor_reports_mcp_unapplied_when_legacy_disabled_cleanup_is_locked.
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
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
Teknium
76f2fdb794 fix(cache): a rotated key, token or same-size edit is never served stale from a file cache
Every cache keyed on a file's stat signature had the bug the config caches had: a same-size
in-place rewrite in one coarse timestamp tick keeps mtime, ctime, size and inode, so the older
parse was served for the rest of the process. Move the helper to utils.file_cache_version
(file_signature + content digest while the file is under 2 s old; always_digest for signatures
compared much later, where the racy digest going empty would read as a change) and key every
cache that can hold a secret, token, pairing/allowlist, route or config on it:

- auth.py: global auth-store memo, Nous auth-status memo (was mtime only)
- gateway/pairing.py approved-users cache (a revocation kept access)
- run_profile_reconcile: served-profile signature (always_digest: a false change reconnects
  adapters) and the hook-consent signature
- webhook dynamic routes (route HMAC secrets), Feishu comment pairing/rules cache (mtime only)
- MCP OAuth tokens-file reload check (mtime only; always_digest: a reload tears the session down)
- config parse-failure record (always_digest), named-custom-provider memo, model aliases,
  gateway.standalone memo, profile model read, MoA preset, agent raw config,
  tui_gateway raw config cache, onboarding due stamp, free-tier inventory stamp,
  provider model-list credential fingerprint, git safe.directory key, skills prompt
  manifest

config_cache_version takes its stat through config_version, so its errors and seams are unchanged.
Left alone: the tool-definition cache key and the platform manifest stamp (a safe worker must
never open config.yaml or a plugin file; the MoA preset cache is skipped in one instead) and the
CLI MCP watcher seed (pinned to file_signature by a main test).
2026-10-27 12:57:09 -07:00
Teknium
fbb1b417e2 fix(providers): one guarded api_mode_for_model for resolution, /model and resume
Runtime resolution caught a raising api_mode_for_model hook and kept the
profile's declared api_mode, but /model (model_derived_api_mode, also the
resume re-derivation in the TUI, CLI and gateway), the stale
codex_responses check in resolution, the agent's Responses routing check
and the auxiliary client asked the same hook unguarded: a model could
resolve and then fail building the switch result.

agent.provider_route_hooks.model_api_mode is now the one call: a raise
answers the profile's declared api_mode, logged with its traceback once per
provider. A None answer keeps each caller's existing meaning.
2026-10-26 01:34:59 -07:00
Teknium
8d359c7824 fix(models): a plugin profile's static_models stay with the home that registered it
sync_plugin_provider_catalog copied every profile's static_models into the process-wide
_PROVIDER_MODELS with setdefault: the first served home won forever, so a second home that
registers the same provider name with other models defaulted to the first home's model, and a
home without the plugin listed (and could switch to) a provider it does not have.

Nothing is copied any more. static_catalog(provider) answers from the built-in row, else from the
bound home's profile at lookup time; static_catalog_providers() lists built-ins plus this home's
plugin rows. The catalog readers (defaults, detection, pickers, setup) use them.
2026-10-26 00:32:11 -07:00
Teknium
2f644f3fed Merge origin/main into copilot-seams/integration
Conflict: hermes_cli/env_loader.py import block. Kept the branch's
left_core_migration.profile_env_names import and main's ConfigBackend
switch (load_yaml_file_readonly no longer imported; _load_secrets_config
reads through config_backend.read_config_doc_readonly).

No main commit since 0c771d7a5b touches Copilot code; nothing to port.
2026-10-25 21:02:41 -07:00
Teknium
889d753725 feat(left-core): migration rows for a model provider that moved to a plugin
LEFT_CORE rows gain three generic fields for a model-provider plugin:

- providers: the ids and aliases the plugin's profiles register. A name
  nothing resolves to gets the install line appended on every "unknown
  provider" surface (runtime resolution / Desktop error text via
  auth.resolve_provider, /model, `hermes model`, `hermes auth add`);
  resolve_runtime_provider installs the plugin first for a home that uses it
  (the CLI and Desktop resolve the provider before the agent whose start runs
  the migration exists); and hermes_cli.providers.get_provider never lets the
  models.dev catalog stand in for such a name while the plugin is not loaded
  (models.dev lists `github-copilot` at api.githubcopilot.com with
  GITHUB_TOKEN: it would have sent a raw GitHub token there).
- profile_env: env names core kept profile-managed. env_loader's
  _PROFILE_MANAGED_ENV_KEYS and config._EXTRA_ENV_KEYS read them statically
  (env_loader runs before discovery), and the generic env writers refuse them
  while the plugin is absent (the executable/argv authority its profile
  declares once installed).
- notice: one more per-home sentence on every migration outcome.

First consumer: the github-copilot row (providers copilot + copilot-acp and
every alias). It is in use when copilot/copilot-acp is a provider the home
routes through: model, fallback chain, auxiliary tasks, delegation and its
fallback chain, MoA presets, cron job pins, auth.json active_provider, or
HERMES_INFERENCE_PROVIDER. A GH_TOKEN alone is not use. COPILOT_GITHUB_TOKEN
and the two base-URL overrides stay out of children as provider env (Tier 2),
as when core shipped Copilot. Its notice tells a profile with no token the
plugin reads (no COPILOT_GITHUB_TOKEN/GH_TOKEN/GITHUB_TOKEN, no `manual`
credential-pool row or providers.copilot login: a gh_cli pool row was seeded
from `gh auth token`) to run `hermes auth add copilot`; the plugin no longer
reads gh or the Copilot CLI's token files. Read-only, never runs gh.

The unknown-provider hint helper moves out of auth.py (over the size cap)
into auth_error_copy.unknown_provider_hint.
2026-10-25 20:47:10 -07:00
Ben Barclay
871900df63 feat(config): route every user config.yaml read and write through a ConfigBackend seam
Add hermes_cli/config_backend.py (config-config design §4.1, D10/D11): a
ConfigBackend protocol, the FileBackend (today's behaviour), selection by
HERMES_CONFIG_BACKEND only (default file; 'remote' and unknown values fail
closed with ConfigBackendUnavailable), and path-level helpers
(read_config_doc, read_config_doc_readonly, config_version, config_exists,
write_config_key, write_config_document, supports_file_tooling).

Migrate every direct reader/stat/exists/bypass writer of a user config.yaml
to the helpers (config.py loaders + caches, config_effective, env_loader,
gateway, TUI, CLI watchers, cron, tools, profiles, logging, time). File
tooling (config edit, backups, xAI migration rewrite, raw dashboard editor)
checks supports_file_tooling() first; migrations skip write-back without it.

Add scripts/check_config_yaml_readers.py (CI lint next to the writers gate)
that rejects a direct read of a config path outside the backend.
2026-10-25 18:54:09 -07:00
Teknium
b9712a0c9f refactor(providers): generic wire seams for per-model api_mode, endpoint headers, max-tokens param
Core branched on the Copilot slug/host for four wire decisions. Replace them with
generic ProviderProfile hooks (providers/base.py L1 block) and move the Copilot
logic into plugins/model-providers/copilot/wire.py:

- api_mode_for_model(model, *, api_key=None): run_agent Responses routing, aux
  CodexAuxiliaryClient wrap, model_switch.model_derived_api_mode (copilot rows
  of _PROVIDER_API_MODE_OVERRIDES removed).
- client_headers(*, base_url, api_key, has_images): agent_init/_client_lifecycle
  host tables, the client-kwargs chokepoint guard (_ensure_route_client_headers),
  the image request-client header swap, both aux header branches.
- request_headers(*, base_url, model, user_initiated): first-call-of-a-user-turn
  attribution in turn_api_request and MoA reference slots.
- max_tokens_param(*, base_url, model): run_agent._max_tokens_param and
  auxiliary_max_tokens_param.

agent/provider_route_hooks.py asks the named provider's profile first, then any
registered profile overriding the hook, so custom routes at a provider's host
keep its quirks. Plugin absent = generic behaviour.
2026-10-25 18:23:40 -07:00
rob-maron
cafa03f7f4 PR review comments 2026-10-21 23:05:11 -04:00
rob-maron
15307dece7 Usage-window plan support 2026-10-20 21:04:30 -04:00
David Dudok de Wit
97e6f117de fix(gateway): keep the session's route for a --once alias with no endpoint
A session on Anthropic behind a proxy, or rotating a credential pool, ran
/model haiku --once, and that one turn went to the provider's default
host with its default key, without the pool or the session's request
overrides. So did an endpointless model_aliases entry, a plain model id
that reverse-matches one, and an external_process provider's own alias
or declared id, which also lost the session's command. With the previous
commit, /model M --once through an alias named M with no endpoint now
reaches the owner too.

The owner ran a pick whole whenever resolved_via_alias was set. But
switch_model gives a pick its own endpoint and key only for a direct
alias with a base_url (_apply_direct_alias_endpoint); for every other
alias kind it resolves the provider's default route, and the owner ran
that in place of the session's.

switch_model now says on its result whether it applied a direct alias's
own endpoint (alias_endpoint_applied, False by default), and the owner
runs a same-provider pick whole only then. The owner decides from the
route switch_model resolved and validated, not from a second read of the
alias table, which a config.yaml edit in between or another profile's
reload of the shared table could change. Every other alias keeps the
session's pool, endpoint, key, command and overrides, and the wire still
follows a provider that picks it per model. An alias with its own
endpoint, and a different provider, still run whole; the CLI still sends
the alias name.

Refs #134889, #140719

(cherry picked from commit eeac2f5b5fdd7d9b5e863a154bdaf654ea99202a)
(cherry picked from commit 752350eb3dd60e18c0c94e4fbed4382c6dfc79fc)
2026-10-19 10:18:29 -04:00
Mark S.
2082d25ffd Merge pull request #139576 from unsupportedpastels/fix/gateway-p5-config-reads
fix(gateway): a new local session reads its profile's current config
2026-10-16 17:42:17 -04:00
unsupportedpastels
556033f656 fix(gateway): expand config ${VAR} refs for a new local session against the profile's current .env
A single-profile owner binds no secret scope and never reloads .env for
local turns, so session.create expanded config.yaml ${VAR} refs (MCP
headers, provider base_url, ...) against the os.environ the daemon
started with; a rotated value only reached new sessions after a
restart. Tool env already refreshes from the profile .env.

stage_local_session now reads config through load_profile_config: it
binds the profile's secret scope (build_profile_secret_scope, the same
.env + secret-source + managed composition the owner scope uses) around
the read when none is bound. A served profile's owner scope is kept as
is; on the launch profile a scope miss still falls to the process env,
so systemd / op run injection keeps resolving. Frozen sessions are
untouched (their stored config is not re-expanded).

Refs #134889 (CFG-4)
Refs #139523
2026-10-16 12:45:04 +00:00
Teknium
76c3029551 fix(model): keep YAML-aliased model routes on the new selection
When `model:` carries an anchor reused elsewhere (`auxiliary.vision: *route`),
the safe loader returns one shared dict for both keys. persist_model_selection
assigned a fresh merged copy to config["model"], leaving the alias holding the
old route; the round-trip writer merges onto the shared ruamel node, so the
later auxiliary.vision merge wrote the old values back and /model save reported
success while persisting old-model.

Edit the loaded model mapping in place instead, so every alias carries the new
route — the same file main's per-key writer produces (alias kept, both keys
resolve to the new route). Still one publication.
2026-10-16 05:44:17 -07:00
Teknium
3a02759c29 fix(model): decide the route before snapshotting config for /model save
persist_model_selection read the raw config, then ran
should_clear_context_pin (cold-start disk I/O) and the rest of the
selection logic, then published the whole document with
atomic_config_replace, which deletes keys missing from the snapshot.
Any setting another process saved in that window was silently erased
(e.g. display.theme written via atomic_roundtrip_yaml_update).

Compute the model updates from a pre-read first, then do read -> merge
-> replace as one in-memory section under _CONFIG_LOCK. If model:
changed between the pre-read and the snapshot, recompute against the
fresh block so the route rules still see the current state.

Adds a test where a real subprocess saves a setting during the route
decision; it fails on the previous head and passes here.
2026-10-16 05:44:17 -07:00
helix4u
5ae26ec781 fix(model): publish saved model selections atomically 2026-10-16 05:44:17 -07:00
Teknium
408cc0d12e Merge origin/main (#32: 36 commits to cf23a1a5cc) into feat/unified-gateway-runtime
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.
2026-10-09 10:24:04 -07:00
Maciej Lisiewski
2ff58849f4 ci: ruff UP037 fixes 2026-10-09 17:34:38 +02:00
Teknium
607a23e858 Merge origin/main (#30: 54 commits to 1744a19e0d) into feat/unified-gateway-runtime
8 conflicts, all from main's lint sweep (#135281 "Harder linter fixes" + the RUF series:
implicit-Optional, unused-unpacked-variable, next(...) for [...][0]). 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) on it. ruff.strict.toml takes main's
copy (the newly enabled rules). tests/cron/test_bot_chat_delivery_child_env.py stays deleted
(1cc9cb9199 retired its lane).
2026-10-08 21:38:54 -07:00
Teknium
4492d033c5 fix: canonical model mutation commits the route the next turn actually runs
prepare_model() wrote only model.default/provider/base_url into the frozen
policy and cleared the launch key only when the provider *name* changed. A
probe on r6-base (custom -> custom, new origin) committed base_url B while:
- api_mode, a context_length pin and key_env from endpoint A survived;
- the explicit launch key bound to endpoint A stayed bound (provider_changed
  is a name comparison);
- _resolve_policy_agent_runtime still read the creation request's base_url
  as explicit_base_url, so the next turn went to A, with A's key.

Root fix, two halves:
- prepare_model applies the shared apply_model_selection() contract
  (model_selection_config_updates: api_mode synced, context pin dropped when
  its route changed, inline key / key_env / api_key_env dropped on a route
  change), and decides launch-key reuse with the same route-identity test
  (now public as selection_route_changed: provider OR normalized base_url),
  so custom -> custom on another origin drops the endpoint-bound key.
  Private config values whose model.* field was cleared are not re-hydrated.
- _resolve_policy_agent_runtime honours the creation request's base_url only
  while it still is the policy's endpoint; the creation request itself stays
  immutable (retry identity unchanged).

A same-route re-pick keeps the launch key and key_env (pinned by the test).

Review: https://github.com/NousResearch/hermes-agent/pull/106742#issuecomment-6067585232
2026-10-08 19:09:34 -07:00
Maciej Lisiewski
4278b6aa24 ci: RUF013, RUF015 2026-10-08 21:29:48 +02:00
ahisblessed
4ec2e50b3c fix(cli): let persist_switch_by_default cover provider-scoped model picks
resolve_persist_behavior() hard-coded the provider-scoped path as exploratory
(return False before the config default was read), so
model.persist_switch_by_default: true was silently ignored whenever --provider
was passed - which is the exact shape the Desktop picker sends.

For twin provider pairs (two custom_providers entries sharing one base_url with
different keys) that is not exploration of a different backend: it is tenant or
account selection on the same backend. The session-scoped pick is dropped, and
the next chat re-derives the provider from the shared base_url, which
deterministically returns one fixed twin - the request is then served with the
other tenant's key, silently: wrong credentials, quotas and billing, no error.

Read the flag before the explicit_provider bail-out so an opt-in to persistence
covers provider picks too. --session and --once stay the explicit opt-outs and
--global still persists; without the flag provider picks remain exploratory, so
the existing behavior is unchanged for everyone who never set the key.

Fixes #123150
2026-10-02 22:40:31 -05:00
finn763
d8dba2e687 fix(config): keep built-in model validation for settings-only provider blocks
A providers.<slug> block with no base_url/url/api of its own is settings,
not a user-defined endpoint. Only remap to the custom: validation branch
when the user-config entry declares a base_url; otherwise openai-codex and
other listing-less built-ins keep their normal catalog path.

Closes #120020
2026-09-29 20:57:57 -05:00
kshitijk4poor
71fe5fccad refactor(model_switch): remove parse_model_flags, which only tests called
Every /model surface parses through parse_model_switch_args. The legacy
5-tuple wrapper had no production caller; its remaining references were two
tests of the tuple shape, an unused import, and two tui_gateway patch()
calls on a function tui_gateway no longer calls.

The en-dash --session normalization those tests covered moves into the
parse_model_switch_args keeper. test_model_switch_once_flags and
test_model_switch_context_offload are removed: the first re-tests the
private parser the keeper already drives, the second the one-line to_thread
wrapper that tests/gateway/test_model_command_context_offload.py proves off
the event loop through the real /model handler.
2026-09-29 15:58:55 +05:30
Teknium
a5bd246865 Old pre-decomposition import paths are gone: plugin compat layer removed on schedule (#126164)
* refactor(plugins): remove the Sep 2026 decomposition compat layer on schedule

The PLUGIN-COMPAT layer (2776813df3 + d63e380324 + 0a5164cebe) kept pre-#102117 import paths
alive for external plugins until 2026-09-14. That window closed two weeks ago; since then the loader
has already been skipping plugins that use the old paths. This removes the layer itself:

- 328 appended `PLUGIN-COMPAT` blocks (lazy `__getattr__` pointer tables, re-exported third-party
  names, restored dead definitions) and the three re-export stub modules
  (gateway/startup_watchdog, hermes_cli/observability/relay_runtime, tools/environments/modal_utils)
- COMPAT_MANIFEST.md, compat_manifest.json, scripts/check_compat_pointers.py and its lint step
- the reporting surfaces: CLI banner notice, `hermes plugins compat`, the `hermes doctor` section,
  the post-update notice, the Desktop one-time dialog, the loader's pre-import skip and the
  `plugins.allow_deprecated_imports` escape hatch

An external plugin that still imports an old path now fails to load with its ImportError as the
reason in `hermes plugins list`, the same path as any broken plugin.

hermes_cli/plugin_compat.py stays as three inert stubs (compat_report, removal_in_effect,
summary_lines): an already-running pre-removal `hermes update` lazy-imports them after the checkout
swap (tests/compat/old_updater_surface.json).

In-tree fallout, both already dead: hermes_cli/setup.py::_check_espeak_ng (no callers; its
`shutil` came from a compat block) and gateway/config.py::SessionResetPolicy ("retained solely for
the scheduled plugin-compat window"). Two test_run_agent patches targeted the removed
`run_agent.handle_function_call` pointer; they now patch `model_tools.handle_function_call`, the
seam production reads, like every sibling test in that file.

* chore: retrigger CI (zero-job startup_failure phantom)

* test: drop resolution allowlist rows for the two deleted which() sites

hermes_cli/setup.py::_check_espeak_ng (dead) and tools/skillevaluator_scan.py::scanner_available
(a restored definition inside a PLUGIN-COMPAT block) no longer exist; the stale-row gate requires
their allowlist entries go with them.
2026-09-28 10:21:41 -07:00
brooklyn!
296ec08dcf fix(models): keep generation models out of chat
Chat catalogs and the session switch treated image and video generation
models as chat. Exclude them by the capability type and name shape the
catalog already publishes, reject selecting one as the session model, and
do not restore a primary already known to be non-chat. Desktop shows the
fallback switch in the transcript.
2026-09-25 12:07:32 -05:00
teknium1
ffc44bbaf3 fix(model): prefer the current provider's alias on implicit switches too
Only the --provider path handed user_providers/custom_providers to
resolve_alias, so the provider-identity comparison behind the
current-provider preference could not see legacy custom_providers
entries on the implicit path (/model <id>) or the authenticated-provider
fallback. On custom:corp-llm, /model shared-model picked another
provider's alias for the same model id and switched to its base_url.

Pass both provider maps on every resolve_alias call site. The two
existing resolve_alias stubs in test_ollama_cloud_auth.py accept the
extra positional args; their assertions are unchanged.
2026-09-23 17:08:21 -07:00
teknium1
79d012bd25 fix(model): match alias ownership on the resolved provider id
The --provider ownership check compared normalize_provider() spellings, but a
legacy custom_providers entry resolves to id "custom:<name>". An alias with
"provider: corp-llm" under "--provider corp-llm" was therefore dropped and the
switch fell back to the provider's own base_url/key instead of the alias's.

Compare resolve_provider_full(...).id on both sides (normalize_provider when
unresolvable), in the ownership check and in resolve_alias's reverse-lookup
preference loop, which now receives the user/custom provider config.
2026-09-23 17:08:21 -07:00
千乘妍 (Xiaoyaner)
1ee38c8090 fix(model): normalize direct-alias provider ownership
Normalize both provider labels at direct-alias ownership comparisons so alias
spellings and case variants match canonical target IDs without weakening
cross-provider rejection.

Maintainer finding: https://github.com/NousResearch/hermes-agent/pull/75262#discussion_r3688616856
2026-09-23 17:08:21 -07:00
千乘妍 (Xiaoyaner)
60f2bcf4ab fix(model-switch): scope direct-alias base_url to the target provider
An explicit `/model <id> --provider X` switch could report target_provider=X
while base_url still pointed at the previous provider's endpoint: resolve_alias
finds a direct alias by reverse model-ID lookup, and the base_url override
applied that alias unconditionally even when the alias belonged to a different
provider. Requests would then be sent to the old provider's URL under the new
provider's identity.

Two narrow changes:

- resolve_alias's reverse lookup now prefers an alias whose provider matches
  current_provider, falling back to first-match only when none does. Insertion
  order is not a routing decision.
- The direct-alias base_url override now ignores (and stops reporting) an alias
  whose provider differs from target_provider.

Exact alias-name lookup stays provider-agnostic, and the first-match fallback is
preserved, both pinned by tests.

[salvaged onto the refactored switch pipeline: the ownership guard now sits in
_route_explicit_provider, where resolved_alias is settled, so both the runtime
resolve (explicit_base_url) and the direct-alias override see the filtered alias]
2026-09-23 17:08:21 -07:00
teknium1
79ec1f2a34 feat(models): GPT-6 Sol/Terra/Luna replace the 5.6 tiers in Nous/OpenRouter catalogs, with Codex -900k variants
OpenAI shipped gpt-6-sol / gpt-6-terra / gpt-6-luna as the successors of the
gpt-5.6 tier line (Sol and Luna live on OpenRouter + the Nous Portal today).
The curated aggregator catalogs (OPENROUTER_MODELS and the derived nous list,
plus the published website model-catalog.json) now carry the gpt-6 tiers and
their -pro variants instead of the 5.6 ones; the openai-api curated fallback
lists them ahead of 5.6.

Codex OAuth support mirrors the 5.6 + Astra contract for every gpt-6 tier:
curated fallback + forward-compat synthesis (from the 5.6 twin or 5.5),
272K advertised fallback, the opt-in -900k picker variants with the
live-verified 900K bump (still capped by the catalog's max_context_window),
dated-snapshot eligibility, wire-suffix stripping, the compaction auto-raise
on the base slug, and the gpt-5.6 effort ladder (max allowed, minimal
rejected). Pricing rows for gpt-6-sol / gpt-6-luna come from OpenAI's model
pages (272K whole-request tier like Astra); Terra has no published page yet
so it deliberately has none.

/model gpt keeps resolving to the flagship: "astra" joins the rank-0 suffix
set so gpt-6-astra sorts above gpt-6-sol.
2026-09-22 11:50:39 -07:00
teknium1
13fe9c7171 feat(providers): external-process provider support for standalone model-provider plugins (from #105863)
The provider-agnostic half of PR #105863, so a CLI-driven subscription provider can ship as a
standalone `kind: model-provider` plugin instead of a bundled one:

- ProviderProfile: `native_reasoning_details_type`, `model_aliases`, `get_model_context_length`,
  `get_usage_cost`, `setup_status`, `discover_models` hooks (all default None / no-op).
- Chat Completions transport: provider-native `reasoning_details` carriers follow only their
  declaring profile; standard records still replay on OpenRouter-style routes, strict routes
  drop the field wholesale (#70233). Relay/stream accumulate `delta.reasoning_details` verbatim.
- `hermes model`: the generic plugin flow gates an external-process row on the CLI's own login
  status (inline `login_command` on a TTY), offers `discover_models()` rows with per-row notes,
  and never writes config when the executable is missing.
- `/model` and the pickers: process providers list their live catalog merged with the pinned
  one, declared aliases/ids resolve inside the provider, and validation accepts a listed id
  without probing `process://`.
- Delegation keeps the selected external-process provider and protocol for the child.
- Model metadata / usage pricing consult the profile's bound and cost hooks first.
- Desktop: `[1m]` renders as a "1M" tag and hyphenated Anthropic versions read "Haiku 4.5".

The bespoke `_model_flow_external_process` and hard-coded `hermes_cli/main.py` paths from the
PR were dropped in favour of main's `_model_flow_plugin_provider`.

Co-authored-by: unsupportedpastels <unsupportedpastels@users.noreply.github.com>
2026-09-20 14:29:39 -07:00
Hermes
04f37f74b0 fix(local): the picker's Local row id and the provider resolver share one definition (#116249)
The /model -> local/ flow offers the 'llamacpp' row from staged GGUFs alone,
but resolve_provider_full only admitted that id behind a live endpoint, so
selecting a staged model died with "Unknown provider 'llamacpp'" before the
runtime seam could start or attach a server.

- providers.py: LLAMACPP_PROVIDER_ID/ALIASES are the single definition; the
  llamacpp rung resolves when a server is reachable OR a model is staged.
- inventory.py: the picker row's slug comes from that definition.
- endpoint.py: honour local_runtime.detect_ports (every provider caller
  invoked the resolver bare, leaving the documented knob dead).
- model_switch.py: a local-runtime alias failure surfaces the seam's own
  message instead of an API-key hint.
2026-09-20 10:03:32 -07:00
teknium1
0469740ab3 feat(cron): jobs follow the main agent model at fire time; pinned locks it on request
An unpinned cron job used to snapshot the global provider/model at creation and treat that
snapshot as its effective pin (#44585), so `hermes model` / `/model` never moved the fleet and
`hermes cron resnap` existed to catch jobs up. New ruling: jobs run on whatever the main agent
model is when they fire. Resolution is per-job pin > cron.model / cron.model_provider (the cron
fleet default) > model.default.

`pinned` replaces the implicit snapshot with an explicit lock: create/update with pinned=true
writes the CURRENT main provider+model onto the job as an ordinary per-job pin; pinned=false
releases both. The cronjob tool exposes it (schema: only when the user asks; it can only lock
the main model, never point spend at a different one) and reports `pinned` per job; the CLI
gets `--pin` / `--unpin`. Legacy records that still carry *_snapshot keys follow the main model.

Removed with the snapshot: `hermes cron resnap`, the tool's resnap action + `all` param, the
"N unpinned jobs keep running on ..." notice in `hermes model` / `hermes config set` / the
dashboard model assignment, and the Desktop cron-model-impact card (setMainModelAssignment
keeps the expensive-model confirm flow in store/model-assignment.ts).

Live A/B (real store + run_job against a temp HERMES_HOME): main-model X -> Y, unpinned job
fires on X before, Y after; pinned job stays on X; unpin -> Y; legacy snapshot record -> Y.
2026-09-20 09:20:51 -07:00
kshitijk4poor
9e0aba49dd fix(model_switch): authenticated-slug lookup is cache-only
get_authenticated_provider_slugs only needs slugs but ran the full listing,
which force-refreshed every stale catalog (6 probes on a cold cache with 6
keys) during alias-fallback routing of a model switch. Pass
non_blocking_catalogs=True: same slug set, 0 forced probes.
2026-09-20 15:17:14 +05:30
teknium1
e03af55edd chore: merge origin/main (resolve website/docs/integrations/providers.md) 2026-09-19 10:47:48 -07:00
kshitijk4poor
b58e1287db fix(model_switch): the OpenRouter mirror is a fallback only when no custom endpoint is configured
#116138 taught the bare-`custom` switched arm to keep the session endpoint when the credential
ladder answered with the `OPENROUTER_BASE_URL` mirror. That test was host/URL-only, so it also
fired when the ladder's answer came from an endpoint configured *ahead* of the OpenRouter rung —
`CUSTOM_BASE_URL`, or a trusted `model.base_url` holding the same URL as the mirror (two env vars
aimed at one proxy). In that configuration the switch paired the new model with the previous
provider's host and key again, i.e. the #73680 shape this arm exists to prevent.

The guard now asks the ladder's own question: the mirror counts as a fallback only when
`CUSTOM_BASE_URL` and a trusted `model.base_url` are both absent, so a URL that equals the mirror
because the user configured it there still wins.

Second act of `test_switch_to_bare_custom_ignores_an_openrouter_mirror` pins it: with both env
vars pointed at the same proxy the switch adopts that endpoint; without the precision check the
test fails (`api.anthropic.com` kept instead of the configured proxy).
2026-09-19 22:18:25 +05:30
kshitijk4poor
3cfbffa16e fix(model_switch): a bare custom switch no longer adopts the OPENROUTER_BASE_URL mirror
The switched-provider bare-`custom` arm adopts the resolved endpoint unless it is the
OpenRouter default. `_fell_back_to_openrouter_default` only knew the built-in
`openrouter.ai` host, so an `OPENROUTER_BASE_URL` mirror — the credential ladder's last
rung, reached whenever no trusted `model.base_url`/`CUSTOM_BASE_URL` exists — looked like a
configured custom endpoint: a session on another provider switching to bare `custom` landed
on the mirror with the `no-key-required` placeholder, dropping the key it was using.

The helper now also recognizes that mirror (read the way the resolver reads it, through the
profile's secret scope), so the arm keeps the session's endpoint and key instead. Sharing the
helper also covers the same-provider #74143 path: a `custom`/`local` session on a session-only
endpoint no longer adopts the mirror either — the same "resolution landed on OpenRouter"
case that guard exists for.

The mirror read is a GUARD read, not a credential fetch: a scope failure (unscoped under
multiplexing) leaves the mirror undetected so the caller keeps the session endpoint, instead
of raising out of `switch_model` where the resolver's own read of the same name is suppressed.

`CUSTOM_BASE_URL` and a trusted `model.base_url` still win: those are endpoints configured for
`custom`, which is the point of the arm.
2026-09-19 22:05:32 +05:30
teknium1
5f914154fd fix: keep model.openai_runtime=codex_app_server across /model switch; document the overlay rung
- model_switch: the host-mandated wire mode (codex_responses on api.openai.com)
  corrects STALE modes; it must not overwrite the resolver's codex_app_server opt-in.
- runtime_provider: docstring ladder gains step 9 (the overlay); one logger.info when
  the overlay replaces a rung's api_mode, since that rung's credential/endpoint is not used.
2026-09-19 09:32:32 -07:00
teknium1
c7b82ed488 fix(gateway): heal a persisted opencode relay URL on /model override rehydration; share the per-model api_mode lookup
- gateway/run_agent_cache.py::_rehydrate_session_model_override re-resolved api_mode from the
  target model but kept the persisted base_url verbatim, so a /v1-stripped or other-family
  relay URL written by an older build stayed on a chat_completions model. Run
  normalize_opencode_base_url after re-resolution for opencode-family providers (test drives
  the production rehydration entry: red before, green after).
- hermes_cli/model_switch.py::_build_switch_result now uses model_derived_api_mode() instead
  of its own exact-key table lookup, so a custom provider extending a family slug
  (opencode-go-bridge) gets the same per-model wire on live /model as on resume.
- tui_gateway/server.py::_resolve_agent_model_runtime: the re-derivation guard is
  any(overrides.values()) — a model_override dict always carries the three keys, so
  'if overrides' was always true.

Part of #96066
2026-09-19 01:16:39 -07:00
teknium1
a750c09129 fix(providers): opencode-go vision models stay on the Go endpoint and attach images natively
Two independent gaps hit a user on provider opencode-go with
deepseek-v4-flash-vision-exp (#96066):

- Vision: the model is absent from models.dev, so get_model_capabilities()
  returned None and image_input_mode: auto detoured images through the lossy
  text describe path. OpenCode Zen/Go resell vendor previews before the catalog
  indexes them; the id's `-vision` token is the vendor's own capability marker,
  so _apply_overrides() now fills the catalog gap with a vision-only base for
  any OpenCode-family provider (built-in or family-slug custom). Catalog entries,
  explicit and _default overrides stay authoritative; reasoning stays unknown.

- Route: _resolve_agent_model_runtime() applied a resumed row's persisted
  api_mode/base_url verbatim. A row written while the session ran an
  anthropic_messages model (MiniMax on Go, or an older build's /zen/v1 relay)
  pinned that wire onto a chat_completions model, surfacing as 401s from the
  Anthropic transport or the Zen relay. Providers that pick the wire per model
  (OpenCode families, Copilot, Nous — the existing _PROVIDER_API_MODE_OVERRIDES
  table, now reachable via model_derived_api_mode()) re-derive api_mode from the
  target model on resume and heal the relay URL; fixed-wire providers keep
  honoring their row.

Salvages #96116 (@Finn763): same two atoms, redone slim (data-driven table
instead of an opencode-only hostname guard in the tui_gateway facade).
2026-09-19 00:05:47 -07:00
kshitijk4poor
9dee8863e1 docs(model_switch): say what the fallback actually relies on
The switched-provider comment implied the guard catches the resolver raise;
it is suppress() leaving st.* at the session values that does. The
stay-on-provider comment now states the one semantic widening of moving to
the shared helper: an empty resolver result keeps the session endpoint on
any host, not only off openrouter.ai.
2026-09-19 10:43:50 +05:30
kshitijk4poor
0cb3760383 fix(model_switch): treat a fall-through to OpenRouter's default as "no custom endpoint configured"
Gate finding: resolve_runtime_provider(requested="custom") never returns an
empty base_url — with no model.base_url but an OpenRouter key present it
lands on OpenRouter's default host, so the "keep the current endpoint"
fallback was dead and an Anthropic session adopting `provider: custom`
hopped to openrouter.ai. The guard _creds_for_current_provider already
carries for this (#74143) is now a shared helper used by both branches;
the branch assigns once instead of assign-then-undo; the import sits with
the other from-imports; the new test's write_text carries an encoding.
Second invariant test pins the no-endpoint case.
2026-09-19 10:43:50 +05:30
kshitijk4poor
daf882e3c2 fix(model_switch): switching to a bare custom endpoint from another provider resolves the configured one
The bare-custom credential branch kept the session's current base_url and
key whenever the target was `custom`, regardless of where the session was.
That is right for a bare-custom session picking another model on its own
endpoint, but when the TUI's per-turn config sync adopts `provider: custom`
from an OpenRouter (or any other) session, the new model was paired with
OpenRouter's URL and key and every request 400/404'd (Bug 2 in issue 73680).

Arriving from another provider now resolves the configured custom endpoint
through resolve_runtime_provider; with none configured the current endpoint
is kept, so direct aliases still supply their own URL afterwards and the
bare-custom same-endpoint case is unchanged.
2026-09-19 10:43:50 +05:30
kshitijk4poor
b2d2cf4e24 fix(cli): the startup route decodes custom:<name> from the caller's providers, not a second config read
Review findings folded: (1) `parse_model_input` resolved the configured
`custom:<name>` ids through its own `load_config()`, so the `user_providers`/
`custom_providers` the three startup callers pass were ignored for this branch
— two config sources for one decision. It now takes `custom_ids` and the route
builds them from its arguments with `custom_provider_slug`, the same identity
`providers:` entries carry everywhere else. (2) The "typo" guard was wrong: it
fired on legitimate bare-custom tags (`custom:qwen3.5:4b`) and its `None` fell
straight back into the default-provider egress the fix exists to prevent. A
bare `custom` route with an unknown id now 404s on the user's own endpoint,
matching `/model`. Docstring lists the `provider:model` form.
2026-09-19 01:44:53 +05:30
kshitijk4poor
10767ab099 fix(tui): hermes --tui -m custom:<name>:<model> routes through the startup owner too
Third entry path with the same egress: `_resolve_startup_runtime` seeded the model
from HERMES_INFERENCE_MODEL and went straight to static provider detection, so the
qualified string reached the configured default. Route through
`resolve_startup_model_route` first, as HermesCLI and oneshot now do.

Also: an unconfigured `custom:<typo>:<model>` now logs a warning and leaves the
route undecided instead of steering a garbage model id at the bare custom endpoint,
and the redundant `qualified_model != raw` guard is gone.
2026-09-19 01:44:53 +05:30
kshitijk4poor
81cd8755b5 fix(cli): a provider-qualified -m selects that provider on both CLI entry paths
`hermes -m custom:jetson-vllm:nemotron-nano-30b` (and `-z`) kept the configured default
provider and sent the UNSPLIT string as the model name, so the whole prompt reached
api.anthropic.com before a 404 — a local endpoint the user picked never saw the request.
`parse_model_input` already decodes the form; nothing on the startup path called it.

`resolve_startup_model_route`, the owner of startup provider/model decoding, now consumes
the colon-qualified form through `parse_model_input` ahead of the `provider/model` branch,
so HermesCLI picks it up unchanged. The oneshot resolver routes through the same owner
before provider auto-detection instead of only after a direct-alias miss.

Live, config `providers.jetson-vllm` at 127.0.0.1:8000 and `model.provider: anthropic`:
before — HTTP 401 from Anthropic, local sink idle; after — sink receives
POST /v1/chat/completions model=nemotron-nano-30b, Anthropic untouched.

Closes #73943. First reported fix: PR #74082 by @Drexuxux (HermesCLI.__init__ decode); the
seam moved to the startup route owner during the Sep-2026 cli.py decomposition.

Co-authored-by: Drexuxux <drexux0@gmail.com>
2026-09-19 01:44:53 +05:30
teknium1
8232680cf3 fix(model): only a local alias hands its URL to the pre-alias resolution
The explicit_base_url hunk in _creds_for_switched_provider passed every
URL-bearing direct alias's endpoint to resolve_runtime_provider, so a
built-in label (anthropic, openai) resolved its vendor key AGAINST the
alias's foreign host; _apply_direct_alias_endpoint then saw a same-origin
credential and kept it. Gate on _resolves_to_custom: only ollama/vllm-style
labels, the ones the missing-endpoint guard refuses, get the alias URL.

CI: tests/hermes_cli/test_model_alias_credentials.py
::test_builtin_label_does_not_pull_that_providers_key_to_a_foreign_host
[anthropic] red on ce4e9d580ac, green here; direct-ollama-alias /model
tests stay green.
2026-09-18 10:20:32 -07:00