Commit Graph

17 Commits

Author SHA1 Message Date
alt-glitch
360f48814c refactor: callers find the install folder through project_root_str()
61 call sites counted directories up from their own __file__ to find the
install folder. They now call hermes_cli._startup_fast.project_root_str(),
so the layout move changes one line instead of 61.

Kept with a reason in the lint baseline: files that cannot import Hermes
code (bootstrap, update path, pm/) and the sys.path bootstraps left for
part 2b. The baseline drops from 89 to 28 root_from_file sites.

Six existing tests that patched a module __file__ now patch the owner.
2026-11-13 18:45:31 +00:00
unsupportedpastels
eef9a3e52c fix(plugins): a task left from an unloaded plugin load cannot publish after a reload
Under plugins.isolation: host, discover_and_load(force=True) (reload-plugins,
and every plugin install, enable or update) loads a plugin again into the same
host process under the same plugin_key. A task the first load spawned kept
running, and its emit_plugin_session_event was taken for the new load and
published to the session's viewers.

- Hermes numbers each load of a plugin in the host (load), sends it with the
  load request, and forgets it at unload.
- The host binds that load, with the plugin, to each request it serves, so it
  follows the request's code onto the tasks it spawns; session_event carries it.
- The gateway process publishes only when that load is the plugin's current
  one; otherwise it logs and returns False, as the hosted call did before this
  PR forwarded it. A category plugin's fresh instance keeps its key's load.
- ctx.emit_to_session reads the manager's home_path directly: every manager
  sets it, as the other readers of the plugin's own profile assume.
  Suggested by @BearHuddleston in review.
- The late-event test now covers a same-host reload and waits with
  tests.waiting.wait_until and Events instead of sleep loops.

ctx.emit_to_session from such a task is unchanged (it reached viewers on
main too).

Refs #142005, #141982
2026-11-06 20:22:20 -05:00
unsupportedpastels
5f8968bd76 fix(plugins): a hosted session event goes out only as the live plugin sending it
Under plugins.isolation: host, the forwarded emit_plugin_session_event took
the plugin_id the caller passed: a hosted plugin could publish as another
plugin id, and a task it left running kept publishing after it unloaded.

- The host process records which plugin's code each request it serves runs
  (the plugin_key of a load/unload, the owner of an invoked reference) and
  sends that with session_event.
- The gateway process looks that plugin up among the loaded ones and
  publishes only when plugin_id is its own; otherwise it logs and returns
  False, as the hosted call did before it was forwarded.
- In-process, emit_plugin_session_event still takes plugin_id as given.
- Contract and guide wording: without plugin-rpc-v1, clients must not
  assume plugin RPC is supported.

Refs #142005, #141982
2026-11-06 20:22:20 -05:00
unsupportedpastels
be3d288fa0 fix(gateway): plugin RPC is a detectable contract member and session events work hosted
A client could not tell "no such plugin method" from "this server has no
plugin RPC": runtime.describe advertised nothing, and plugin.* was in no
contract or ledger. Under plugins.isolation: host the module-level
emit_plugin_session_event returned False and sent nothing, and an
in-process ctx.emit_to_session from a plugin's own thread on a multiplexed
gateway looked the session up in the launch profile.

- runtime.describe lists plugin-rpc-v1.
- tui_gateway/contracts gains CANONICAL_NAMESPACES (canonical_namespace):
  plugin.{plugin_id}.{name} with open params, rendered as
  CanonicalRpcNamespaces in the TS contract and x-canonical-namespaces in
  OpenRPC; the serve handler ledger gets one row for it.
- The plugin host forwards emit_plugin_session_event to the gateway process
  (host->parent request session_event), looked up in the host's profile.
- ctx.emit_to_session binds the plugin manager's home before the lookup.

Refs #142005, #141982
2026-11-06 20:22:20 -05:00
unsupportedpastels
7e8c8a5856 fix(plugins): keep a reloaded hosted plugin when an abandoned load fails late
A hosted load abandoned at its load deadline can fail after a reload of
the same plugin succeeded. Its failure cleanup unloaded the plugin key,
which tore down the live load: its tools failed with "plugin host
callable was released" and its on_unload had already run.

Claim the plugin key before the host start can block, and run the
failure cleanup only while this load still owns the key.
2026-11-05 18:29:48 -05:00
unsupportedpastels
f23fb505e7 fix(plugins): keep a failed hosted load's error when its cleanup fails
The failed-load cleanup added in the previous commit could raise before
the original exception was re-raised, so the plugin's recorded error
became the cleanup's (an on_unload that raised SystemExit, or one that
exited the host). Run the cleanup best-effort, log its failure, and
re-raise the register() error.
2026-11-05 18:29:48 -05:00
unsupportedpastels
994e901730 fix(plugins): run a failed hosted load's on_unload cleanup
Under plugins.isolation: host, a plugin whose register() queued an
ctx.on_unload callback and then raised kept that callback (and any
objects it handed over) in the plugin host. The in-process loader runs
the callback when register() fails, so a hosted plugin that started a
thread or opened a resource before failing leaked it until the host
exited, and a later successful load inherited the stale callback.

PluginHost.load now unloads the plugin key in the host when the load
fails, which runs the queued callbacks and drops the host-side
references, matching the in-process failure path.
2026-11-05 18:29:48 -05:00
Teknium
99cf3a6358 fix(providers): seed_pool_credentials takes plain values; hosted ambient tokens reach the host
Under plugins.isolation: host, profile_call encodes kwargs without callable refs, so the
is_suppressed / explicitly_configured lambdas arrived in the host as non-callable Opaque values
and a hosted provider seeded nothing (while _profile_seeds_pool still disabled generic env
seeding). The seam now passes data: suppressed_sources (frozenset) and explicitly_configured
(bool), computed only for profiles that override the seam.

Shell-exported GH_TOKEN-style names are always stripped from child envs, so a hosted provider
that declares them (env_vars + ambient_credentials) never saw a shell-only token. The plugin host
env now re-adds exactly those names through get_secret under the host home's scope: the launch
home keeps its shell value, a routed home gets only its own .env value, never the launch one.
2026-10-26 00:32:10 -07:00
Teknium
808eaf32f9 fix(plugins): hosted providers keep their declared types across the plugin-host wire
Under plugins.isolation: host every value crosses as JSON, so a dataclass
arrived as a generic Record, a Path as str, an enum as its value and a
plugin object as an Opaque placeholder. Core consumers that type-check
broke:

- secret sources: SecretSource.fetch() came back as Record, the
  orchestrator rejected it ("fetch returned Record instead of
  FetchResult") and applied no secrets; fetch() also received home_path
  as str, so `home_path / "x"` raised in the plugin.
- context references: ContextCompletionItem (a __slots__ class) became
  Opaque, so @prefix: autocomplete silently returned nothing.
- context engines: clone_for_agent() returned Opaque, so no agent could
  get its own copy of a hosted engine.

The provider ABC's annotations are the contract, so the wire now
restores against them: the parent rebuilds results from the declared
return type (dataclasses, enums, Paths, typed containers; a declared
provider ABC becomes an object proxy) and the host rebuilds method
arguments from the declared parameter types. Type names never come from
the host. ContextCompletionItem becomes a slots dataclass so it crosses
as data.
2026-10-25 05:10:15 -07:00
Teknium
7ae117eb4c fix(plugins): name portable plugin skills after the plugin, not a hashed namespace
A portable plugin's skills registered as agent-plugin-<slug>-<sha8>:<skill>
(agent-plugin-blender-5a80e4ba:blender) because one manifest field named both
its plugin-data directory and its skill namespace. The hash only matters on
disk. Skills now take the plugin's own name (blender:blender), the form every
native plugin skill uses; a clash with an already-registered qualified name is
skipped with a warning naming the owner, as before. The data directory keeps
its hashed name, so no plugin data moves, and skill_view still resolves names
saved in the old form.
2026-10-24 04:01:10 -07:00
Teknium
02f46d9818 fix(terminal): a plugin backend in the plugin host refuses with the isolation setting
Under plugins.isolation: host a user terminal backend's create_environment()
ran in the host and its environment came back as an Opaque placeholder, so the
first command failed with a backwards 'not available inside the plugin host'
AttributeError and the host was left holding a sandbox nothing could clean up.
Pre-existing for every plugin terminal backend; the Singularity move makes it
reachable for Singularity users who run host isolation.

Creating the environment now refuses before the host starts anything, naming
plugins.isolation: in_process (the Bot Desktop placement refusal's shape).
2026-10-22 05:26:10 -07:00
funky-xamarin
588f83a273 fix(plugins): preserve route authorization across hosted HTTP requests
(cherry picked from commit 9be287ee25ae513e009b657d97d62e5919ae8a12)
2026-10-18 03:27:52 -07:00
unsupportedpastels
358ed4c305 fix(plugins): keep slow hosted plugin requests off the gateway's shared threads
Every request forwarded to a profile's plugin host parked a thread of the
gateway's default asyncio.to_thread pool until the host answered, with no
timeout. Forty concurrent slow requests to a secondary profile's plugin
held that pool, so /api/dashboard/plugins (also to_thread) timed out and
plugin assets took seconds; a hung handler held its thread for good.

Forwarded requests now run on a small pool of that profile's own (four
threads per plugin host home), so a slow plugin queues only behind its own
profile's plugin requests. Each request gets HOSTED_REQUEST_TIMEOUT_SECS
(60 s, a documented module constant; no config key), queueing included,
and then answers 504; PluginHost.asgi_request takes the remaining time as
its reply timeout, so the gateway thread is freed and the host keeps
serving later requests. The host protocol has no cancel, so the host may
still finish the abandoned handler. The launch profile's
plugins.isolation: host mount forwards through the same helper and gets
the same pool and 504. The docs say so.

Refs #134889 (PLG-3)
Refs #139523
2026-10-16 19:15:07 -04:00
Maciej Lisiewski
2ff58849f4 ci: ruff UP037 fixes 2026-10-09 17:34:38 +02:00
Maciej Lisiewski
d76cce4f11 ci: apply all automatic linter fixes available 2026-10-08 17:22:54 +02:00
teknium1
ad5c8e336e fix: plugin host review findings (async ctx, caller session, restarts, per-profile dashboard)
Independent review of the plugin host found eight defects; each is fixed here and
the reproducible ones are covered by two new invariant tests (red on the previous
head, green now).

- Async plugin code: `await ctx.<facade>.<async method>` works (the facade probe
  reports coroutine methods and the host returns a coroutine function), and ctx
  calls made from coroutines keep the caller's session. The wire origin is now a
  ContextVar carried onto host event-loop tasks, and the host's fallback context
  starts empty instead of copying whichever caller created the host.
- Memory / context-engine / cron providers survive a host crash: proxies record
  the host generation, and a category proxy reloads its plugin into the new host
  on next use (bounded by the same restart budget). A proxy from an earlier host
  can no longer address a recycled object id.
- Hosted provider objects no longer leak: the host imports a category plugin's
  module once and drops objects whose Hermes proxies were collected.
- Every public attribute of a hosted object is read live (class-level defaults
  included), and attributes Hermes assigns reach the plugin's object unless they
  hold a live handle.
- A user memory provider's config_schema.py runs in the plugin host.
- Dashboard plugin APIs resolve the plugin in the requesting profile (its copy,
  its plugins.enabled, its host) and keep repeated headers such as Set-Cookie.
- platform_actions coroutines run on the gateway loop their adapters use.
- Each incoming request gets its own thread (no pool exhaustion under nested
  callbacks); a late close from a replaced host no longer triggers a reload; the
  model-provider extraction cache is keyed by full path.
2026-10-03 10:15:11 -07:00
teknium1
5fa55d1678 feat(plugins): run third-party plugins in a per-profile plugin host (plugins.isolation: host)
plugins.isolation: host imports every non-bundled plugin in a host process started
on demand per profile with only that profile's environment, and hands plugins a
RemotePluginContext; Hermes registers proxies for tools, hooks, commands, skills and
provider objects (subclasses of the ABC it checks). Re-entrant: handlers may call
ctx back into Hermes while Hermes waits on them. Every user-code import path routes
to the host (general, memory/context-engine/cron, model-provider profiles via a
cached credential-free extraction, dashboard APIs via an ASGI bridge) or refuses.
One table names what cannot cross (live gateway objects); the static audit shown
by `hermes plugins validate/show` reads it. A host that dies is restarted with its
plugins (bounded). Default stays in_process: nothing changes unless opted in.

Why: shared-pool deployments must never run one tenant's plugin Python in an
interpreter holding another tenant's data, without plugins becoming tenant-aware.
2026-10-03 10:15:11 -07:00