Documentation
¶
Overview ¶
Package pluginlimits sets the largest gRPC message plugins and plugin hosts exchange, and recognises a plugin that refused a message for its size.
A gRPC server accepts 4 MiB per message unless told otherwise, and go-plugin's DefaultGRPCServer does not tell it. A request body over that size (a long context, a few base64 screenshots, one PDF) then failed in every post_auth plugin. The plugin SDKs serve with GRPCServer instead, and the hosts' brokered servers add ServerOptions, so both sides accept MaxMsgBytes. go-plugin's client side already allows math.MaxInt32.
A plugin built on an older SDK keeps the 4 MiB limit. Hosts wrap its refusal with AsTooLarge so the caller can answer 413 naming the plugin.
Index ¶
- Constants
- Variables
- func AsTooLarge(err error, plugin, hook string, bytes int) error
- func CheckSize(plugin, hook string, bytes int) error
- func ClientMessage(err error) string
- func GRPCServer(opts []grpc.ServerOption) *grpc.Server
- func HostServiceServerOptions() []grpc.ServerOption
- func IsRequestTooLarge(err error) bool
- func IsTooLarge(err error) bool
- func MaxMsgBytes() int
- func ServerOptions() []grpc.ServerOption
- type TooLargeError
Constants ¶
const DefaultMaxMsgBytes = 64 << 20
DefaultMaxMsgBytes is 64 MiB, above the LLM vendors' request limits (Anthropic's is 32 MB).
const EnvMaxMsgBytes = "PLUGIN_GRPC_MAX_MSG_BYTES"
EnvMaxMsgBytes ("PLUGIN_GRPC_MAX_MSG_BYTES") overrides DefaultMaxMsgBytes, in bytes. The hosts pass it to plugin processes (see pkg/pluginenv), so one setting covers both sides.
const HostServiceMaxMsgBytes = 8 << 20
HostServiceMaxMsgBytes is the largest message a plugin may send the host's brokered service API (KV, events, edge payloads, management calls). Those calls carry no LLM bodies; the largest is a 5 MB Studio KV value. It is not tied to MaxMsgBytes, so raising the body limit does not let a plugin push larger messages into the host.
const LegacyMaxMsgBytes = 4 << 20
LegacyMaxMsgBytes is gRPC's default receive limit, which plugins built before AI Studio 2.3 still have.
Variables ¶
var ErrRequestTooLarge = errors.New("request is larger than plugins accept")
ErrRequestTooLarge: a request is over MaxMsgBytes, so the host refuses it without calling the plugin (no plugin can be sent it).
Functions ¶
func AsTooLarge ¶
AsTooLarge wraps err in a *TooLargeError when IsTooLarge(err), and returns it unchanged otherwise.
func CheckSize ¶
CheckSize returns a *TooLargeError wrapping ErrRequestTooLarge when a message of bytes is over MaxMsgBytes, so the host can refuse it before marshalling it for a plugin that would refuse it anyway.
func ClientMessage ¶
ClientMessage is what a client is told about a request refused as too large for a plugin. It names no plugin: which plugins an LLM runs is the operator's configuration. The host logs the full error.
func GRPCServer ¶
func GRPCServer(opts []grpc.ServerOption) *grpc.Server
GRPCServer is a drop-in for go-plugin's DefaultGRPCServer (the ServeConfig GRPCServer field) that adds ServerOptions.
func HostServiceServerOptions ¶
func HostServiceServerOptions() []grpc.ServerOption
HostServiceServerOptions returns the receive limit for a host's brokered service-API server.
func IsRequestTooLarge ¶
IsRequestTooLarge reports whether err is a request refused for its size, by a plugin or by the host's limit.
func IsTooLarge ¶
IsTooLarge reports whether err is gRPC refusing a message for its size, on either end: "received message larger than max" or "trying to send message larger than max". A plugin's own ResourceExhausted (a quota, say) is not.
func MaxMsgBytes ¶
func MaxMsgBytes() int
MaxMsgBytes returns EnvMaxMsgBytes when it holds a positive whole number, capped at math.MaxInt32 (gRPC's own ceiling), and DefaultMaxMsgBytes otherwise.
func ServerOptions ¶
func ServerOptions() []grpc.ServerOption
ServerOptions returns the receive and send limits for a plugin's gRPC server, which the host sends request and response bodies.
Types ¶
type TooLargeError ¶
type TooLargeError struct {
Plugin string // plugin name
Hook string // hook or RPC, e.g. "post_auth"
Bytes int // size of the message the host sent
Err error
}
TooLargeError is a plugin call that failed, or was not made, because the message was over the plugin's gRPC limit (Err is ErrRequestTooLarge when the host's own limit refused it).
func AsTooLargeError ¶
func AsTooLargeError(err error) (*TooLargeError, bool)
AsTooLargeError returns the *TooLargeError in err's chain, if any.
func (*TooLargeError) Error ¶
func (e *TooLargeError) Error() string
func (*TooLargeError) Unwrap ¶
func (e *TooLargeError) Unwrap() error