Repository navigation
fix(py): keep inline use=[...] instances, type middleware kwargs, and stop mid-stream retries - #86
Merged
huangjeff5 merged 12 commits intoNov 13, 2026
Conversation
huangjeff5
force-pushed
the
fix/py-1.0-pr6b-middleware-instances-resilience
branch
from
November 11, 2026 06:22
47719f5 to
be59650
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr6b-middleware-instances-resilience
branch
from
November 11, 2026 16:21
be59650 to
3a3b6df
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr6b-middleware-instances-resilience
branch
from
November 11, 2026 17:31
3a3b6df to
9bd4843
Compare
huangjeff5
changed the base branch from
fix/py-1.0-pr6-devui-middleware-mcp
to
fix/py-1.0-pr6-middleware-sandbox
November 11, 2026 18:37
huangjeff5
force-pushed
the
fix/py-1.0-pr6b-middleware-instances-resilience
branch
from
November 11, 2026 18:38
9bd4843 to
06c4e79
Compare
- use=[Mw(...)] ran a fresh cls(config=...) rebuilt from serialized config: custom __init__ crashed, __init__ state reset, re.Pattern lost its flags (SECRET bypassed an IGNORECASE guard), Callable config fields raised PydanticSerializationError. The call's child registry now keeps the caller's instance and the per-call copy is a shallow copy.copy. MiddlewareRef serialization stays for traces and the Dev UI. - A Middleware subclass defining 0.12 model()/generate()/tool() without the matching wrap_* raises TypeError at class definition instead of becoming a silent no-op.
…ks commit
- A string Fallback entry inherits the caller's config narrowed to keys
the backup's config class accepts (portable generation keys when it
has none), instead of {} wiping max_output_tokens/temperature. Matches
JS (entry.config ?? req.config). version/extra never carry over.
- Retry and Fallback no longer retry or fail over once the failed
attempt streamed chunks to the caller, which spliced a second answer
onto partial JSON in ChunkAccumulator.
…ueue The engine now shallow-copies middleware per generate(), so a reused Filesystem instance shared one _message_queue across calls. One request's read_file contents could be injected into a concurrent request's next turn.
…ool/generate _reject_legacy_hooks raised on any plain method named model, generate or tool, so a helper like def tool(self, name) broke class definition. Reject only an async def with self plus three positional params.
huangjeff5
force-pushed
the
fix/py-1.0-pr6b-middleware-instances-resilience
branch
from
November 11, 2026 18:40
06c4e79 to
5957719
Compare
apascal07
approved these changes
Nov 12, 2026
… and middleware ref dumping
huangjeff5
deleted the
fix/py-1.0-pr6b-middleware-instances-resilience
branch
November 13, 2026 17:11
This was referenced Nov 15, 2026
Merged
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.
Genkit keeps caller-instantiated middleware instances instead of rebuilding them from JSON config, stops
RetryandFallbackonce chunks have already streamed to the client, and types middleware constructors.Main Changes
_compile_middlewarediscarded passed middleware instances and calledcls(config=...), which crashed any custom middleware requiring__init__arguments and dropped non-JSON state (clients, compiled regex flags). We now retain a shallow copy (copy.copy(instance)) per generate call, preserving constructor state while isolating per-call mutations.generate_stream), if an attempt failed after chunks had already been sent over SSE,RetryandFallbacktriggered a new attempt, appending a second response to the partial first response in the client's stream. Middleware now monitorsctx.on_chunkand immediately aborts retry/failover if chunks were already emitted.Retry,Fallback,Filesystem,Skills,ToolApproval) accepted raw untyped**kwargs, allowing typos to pass static type checking and fail only at runtime. All constructors now declare explicit typed keyword arguments (Retry(max_retries=3)).async def model(...)withoutwrap_model) were silently skipped by the 0.13+ runtime. Defining such a class now raisesTypeErrorimmediately at class definition time with instructions to usewrap_model.