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
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.
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.