Repository navigation
test(py): lock subflow context inheritance and the Dev UI context path - #6584
Merged
Merged
Conversation
- A subflow sees the parent's context unless the call passes context=;
an override (including {}) replaces it and is undone when the subflow
returns or raises.
- Inheritance holds across asyncio.gather, create_task, .stream(), and a
subflow called from a tool during generate.
- Reflection v1 and v2 runAction context reaches the flow and a nested
subflow; v1 spans show auth redacted; v2 rejects a non-object context.
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces comprehensive test suites in flow_context_test.py and reflection_v2_test.py to verify context propagation behavior across flows, subflows, tools, and reflection APIs. The feedback recommends improving test robustness by using defensive guards (e.g., dict(ctx.context or {})) to prevent potential TypeError exceptions when ctx.context is None. Additionally, it is advised to replace pytest.raises inside flow definitions with standard try/except blocks to avoid framework-level exception wrapping that could mask test failures.
apascal07
approved these changes
Oct 7, 2026
…t-propagation # Conflicts: # py/packages/genkit/tests/genkit/core/endpoints/reflection_test.py
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.
A subflow sees the parent flow's context unless the call passes
context=. This locks that contract with real@ai.flowtests, plus the Dev UI path that feeds context in. One runtime change: v1runActionrejects a non-objectcontextwith 400, same as v2.Decisions
Action.runsets the context ContextVar only whencontext is not None, socontext={}is an override, not "no context". This matches JSrunWithContext, which checkscontext === undefined. Tests cover replace,{}, and the parent getting its own context back after the subflow returns or raises..stream()runs the subflow as a task Genkit creates, and flow →generate→ tool → subflow runs through the generate loop. Tests lock both. Plaingather/create_taskare stdlib ContextVar copies and are not retested here.context. A v2 agent (bidi) run seescontexttoo. A subflow's span records the inherited context withauthas<redacted>."context": "gold"straight to the flow, soctx.contextwas a string andctx.context.get(...)failed inside user code. Now v1 answers 400 before the flow runs, matching v2's invalid params. We chose rejecting over coercing to{}because a malformed request should fail where it is malformed.ctx.contextchanges the parent's dict too, same as JS. These tests don't assert either way, so we can change that later without breaking them.Verified: removing ContextVar inheritance fails 5 of these tests; removing the reset fails both restore tests; dropping
context=fromrun_bidi_actionfails the agent test; removing the v1 guard fails the v1 rejection test.