Skip to content

fix(py): fix various IDE type check issues, streaming syntax, and missing default value runtime crash - #5340

Merged
huangjeff5 merged 3 commits into
mainfrom
jh-dx-fix1
Jun 23, 2026
Merged

fix(py): fix various IDE type check issues, streaming syntax, and missing default value runtime crash#5340
huangjeff5 merged 3 commits into
mainfrom
jh-dx-fix1

Conversation

@huangjeff5

Copy link
Copy Markdown
Contributor

I noticed these issues while spinning up a new sample project and coding directly in IDE:

fromgenkit.plugins.google_genaiimportGoogleAI# ^ red squiggly: "GoogleAI is not exported"ai=Genkit(plugins=[GoogleAI()])
@ai.flow()asyncdefgreet(name: str='world') ->str:
returnf'hi {name}'awaitgreet('Alice') # red squiggly: "str not assignable to None"awaitgreet() # runs but crashes: INVALID_ARGUMENT@ai.flow()asyncdefstream(topic: str, ctx: ActionRunContext) ->str:
asyncforchunkinai.generate_stream(prompt=topic):
# ^ red squiggly: "not iterable"ctx.send_chunk(chunk.text)
return''
  1. Plugin imports flagged as private — the plugin's __all__ was built dynamically: __all__ = [GoogleAI.__name__, VertexAI.__name__, ...]. Pyright only treats a symbol as part of the public API when __all__ contains string literals. Rewrote the lists to string literals across google-genai, ollama, and flask __init__.py.

  2. Defaulted flow input collapses to None — the @ai.flow() decorator's @overload definitions were ordered most-general first (0-arg → 1-arg → 2-arg). A function async def f(x: str = '...') is structurally callable with no args, so pyright matched the 0-arg overload, which says "input type is None". Reordered to most-specific-first so the input type stays as the caller wrote it.

  3. Streaming reported as not iterable — ModelStreamResponse only exposed .stream and .response. Added __aiter__ delegating to the underlying channel. The explicit .stream / .response API still works; the natural async for chunk in ai.generate_stream(...) form now works too.

  4. Runtime crash on await greet():
    (A) Action.run() validated input against the schema before checking whether the function had a Python default, so it raised INVALID_ARGUMENT on None against str.
    (B) Even bypassing validation, _invoke was calling self._fn(None), but Python only uses a parameter's default when the argument is omitted, not when None is passed explicitly.

Two-part fix:

  • At decoration time, inspect the function's FullArgSpec and remember whether the input arg has a Python default.
  • At runtime, skip schema validation when input is missing AND the function has a default, AND omit the input argument from the dispatch call (passing ctx by keyword in the 2-arg form so it doesn't accidentally land in the input slot).

@huangjeff5huangjeff5 changed the title ix(py): fix various IDE type check issues, streaming syntax, and missing default value runtime crashfix(py): fix various IDE type check issues, streaming syntax, and missing default value runtime crashMay 17, 2026

@gemini-code-assistgemini-code-assistBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the handling of actions with defaulted input arguments, enabling them to be called without input while skipping validation. It also improves static analysis by reordering decorator overloads and transitioning __all__ exports to string literals. A bug was identified in the logic for detecting optional arguments in methods, where the self parameter prevents the correct identification of defaulted arguments.

Comment threadpy/packages/genkit/src/genkit/_core/_action.py Outdated
huangjeff5and others added 2 commits May 19, 2026 15:00
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@huangjeff5
huangjeff5 merged commit 51be800 into mainJun 23, 2026
19 checks passed
@huangjeff5
huangjeff5 deleted the jh-dx-fix1 branch June 23, 2026 20:26
@huangjeff5huangjeff5 mentioned this pull request Jul 22, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixpythonPython

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@huangjeff5@i14h@pavelgj