Conversation
The gateway's plugin engine was the "engine unavailable" stand-in. It is now tw-plugin's runtime (QuickJS in Wasmtime) behind `plugin::Engine`, `plugin::PluginHost` and `plugin::ReplyHost` (`plugin::sandbox`): - The runtime starts on the first plugin load (a configured plugin, or an inspect), not with the gateway, and is reused across reloads. A core without plugins, and every test that builds a gateway, never starts it. If it cannot start, every plugin fails to load with that reason, and the requests it covers follow `on_error`. - Each load runs on its own thread with an 8 MiB stack: the sandbox needs more than 2 MiB, and a load can come from any thread (a config reload, or the main thread at startup, which has 1 MiB on Windows). - Plugins are compiled from exactly the bytes that were hashed. Manifests, permissions (in `tw_api::Permission` order), scope, reply mode, settings (in the author's order) and hooks map onto the gateway's types; load errors, including top-level evaluation errors, keep their line and column, so they reach `PluginInspection.error` and status `error`. - `onRequest`, the per-reply instance, `onReplyText`, `onReplyTextEnd` and `onToolCall` delegate to the sandbox, with their logs and CPU time. Tests load real plugins (manifest, hash of the bytes, a syntax error with its line, a manifest that asks for more than it uses, a caller with a small stack), run a request hook and a reply hook through the adapter, and take a real plugin through the control plane: inspect, install, a changed file and approval. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Superseded by #259, which carries the same sandbox adapter (lazy runtime, loads on an 8 MiB thread, hooks delegated one to one) plus the data-plane fixes that go with it. Closing this one so the two do not collide in plugin/sandbox.rs. The control-plane test that takes a real plugin through inspect, install, a changed file and approval will follow separately once #259 is in. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces the "engine unavailable" stand-in with the tw-plugin sandbox (#254). The adapter is
tw_gateway::plugin::sandbox, and it implements the gateway'sEngine,PluginHostandReplyHostseams.Runtime lifetime
PluginInspect.errorwith that reason, and the requests it covers followon_error.Loading
spawn_blocking(inspect, create, approve) and, at startup, the main thread, which has 1 MiB on Windows.LoadError::Syntaxwith line and column), reachPluginInspection.errorand statuserror.Hooks
on_request,reply→on_text,on_text_endandon_tool_calldelegate totw_plugin::Pluginandtw_plugin::Reply. Results, logs and CPU time are mapped one to one.Tests
Checks
cargo fmt --all --checkcargo clippy --workspace --all-targets -- -D warnings, and--libcargo test --workspace🤖 Generated with Claude Code