Skip to content

feat: rename generative slots -> generative stubs - #801

Merged
jakelorocco merged 2 commits into
mainfrom
jal/genstubs
Apr 10, 2026
Merged

jakelorocco merged 2 commits into
mainfrom
jal/genstubs

Conversation

@jakelorocco

@jakelorocco jakelorocco commented Apr 9, 2026 •

Copy link
Copy Markdown
Contributor

Misc PR

Type of PR

  • Bug Fix
  • New Feature
  • Documentation
  • Other

Description

  • Link to Issue: Fixes N/A

We were requested to rename GenerativeSlots -> GenerativeStubs. I've gone through this repo and other mellea repos (tutorials, demos, contribs, website). The only other reference was in tutorials. I've opened a PR here.

Testing

  • Tests added to the respective file if code was changed
  • New code has 100% coverage if code as added
  • Ensure existing tests and github automation passes (a maintainer will kick off the github automation when the rest of the PR is populated)

@github-actions github-actions Bot added the enhancement New feature or request label Apr 9, 2026
@github-actions

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

The PR description has been updated. Please fill out the template for your PR to be reviewed.

Comment thread CHANGELOG.md Resolved
@jakelorocco
jakelorocco marked this pull request as ready for review April 9, 2026 14:52
@jakelorocco
jakelorocco requested a review from a team as a code owner April 9, 2026 14:52

@psschwei psschwei 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.

(testing out some things with this review. review was AI generated but human reviewed/approved)

Code Review

The rename is thorough and mechanically correct across ~40 files — nice work on the coverage. A few items to consider before merge:

1. No backward-compatibility shim for genslot import path

The module mellea.stdlib.components.genslot is deleted with no re-export. Multiple doc pages teach users from mellea.stdlib.components.genslot import PreconditionException — external code following current docs will get ModuleNotFoundError on upgrade.

Suggestion: Add a minimal genslot.py shim with a deprecation warning, or explicitly document this as a breaking change in the upcoming release's CHANGELOG (not by rewriting old entries).

2. docs/metrics/coverage-current.json not updated

Lines 1822, 1838, 1875 still reference mellea.stdlib.components.genslot. If this file is auto-generated and gets regenerated, no action needed — but if it's checked by CI it could break.

3. CHANGELOG history rewriting

Historical entries at lines 242/275 were changed from "genslot"/"gen slots" to "genstub"/"gen stubs". Standard practice is to leave historical entries untouched and add a rename note under the current version's section. I'd recommend reverting those edits and adding a new entry instead.

Minor

  • docs/docs/docs.json:448 — Mintlify redirect still says /core-concept/generative-slots. This is arguably correct (preserves old bookmarks), but worth an explicit decision.
  • Notebook formatting — Two .ipynb files had their source arrays collapsed to single strings. Valid JSON but creates unnecessary diff noise.

Overall the rename itself is clean and consistent — template file + template_order are correctly in sync, all class/variable/error-message references are updated, and good call checking the tutorials repo too.

@jakelorocco

jakelorocco commented Apr 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Makes sense!

  • Added backwards compatibility for genslots with tests for it.
  • Reverted changes to the changelog

I also added an m fix genslots command that modifies references in the code (similar to m fix async). Output looks like:

(mellea) ~/code/mellea4 ✗ % m fix genslots --dry-run scratchpad/testing.py
Found 2 reference(s) in 1 file(s):
  scratchpad/testing.py:4 - mellea.stdlib.components.genslot → mellea.stdlib.components.genstub
  scratchpad/testing.py:5 - import genslot → import genstub

@jakelorocco

Copy link
Copy Markdown
Contributor Author

@planetf1, can you please comment on:

docs/docs/docs.json:448 — Mintlify redirect still says /core-concept/generative-slots. This is arguably correct (preserves old bookmarks), but worth an explicit decision.

I didn't see any code that references this and my understanding of the above statement is this is to make bookmarks keep working form the old version of the website. I think we should leave this as is?

@psschwei

psschwei commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

@planetf1, can you please comment on:

docs/docs/docs.json:448 — Mintlify redirect still says /core-concept/generative-slots. This is arguably correct (preserves old bookmarks), but worth an explicit decision.

I didn't see any code that references this and my understanding of the above statement is this is to make bookmarks keep working form the old version of the website. I think we should leave this as is?

Yeah, I think so too (should've probably dropped that, was testing an automated PR review workflow, guess it could use a little tweaking still 😉 )

@planetf1

Copy link
Copy Markdown
Contributor

@planetf1, can you please comment on:

docs/docs/docs.json:448 — Mintlify redirect still says /core-concept/generative-slots. This is arguably correct (preserves old bookmarks), but worth an explicit decision.

I didn't see any code that references this and my understanding of the above statement is this is to make bookmarks keep working form the old version of the website. I think we should leave this as is?

Yeah, I think so too (should've probably dropped that, was testing an automated PR review workflow, guess it could use a little tweaking still 😉 )

I think it may be too early to focus on keeping all our doc URLs stable.. I would stick to what we deem to be the main entry points (maybe just the docs themselves), otherwise we'll start making things complex to maintain.

Most of the entries in docs.json are effectively 1:1 mappings for clarity - I'd mostly go for that approach unless we have a good reason not to.

One thing to be careful of is any inbound links from the landing page (since that is a distinct repo). We could have a 'contract' where we keep that nominated list stable - but nothing formalized currently.

That being said, the website doesn't currently point to generative-slots (or stubs)

I'd therefore be inclined to update the source/destination to be in sync (which would break a bookmark) - but that's more driven by the lack of explicit policy to preserve links and keep things simple rather than any objection to the naming being used....

@jakelorocco

Copy link
Copy Markdown
Contributor Author

Sounds good. I will leave the bookmarks / links untouched for now.

@jakelorocco
jakelorocco added this pull request to the merge queue Apr 10, 2026
Merged via the queue into main with commit 88a4d75 Apr 10, 2026
7 checks passed
@jakelorocco
jakelorocco deleted the jal/genstubs branch April 10, 2026 13:06
@jakelorocco jakelorocco linked an issue Apr 10, 2026 that may be closed by this pull request
akihikokuroda pushed a commit to akihikokuroda/mellea that referenced this pull request May 27, 2026
…ng#801)

* feat: rename generative slots -> generative stubs

* feat: add backwards compat with deprecation warning; add genslot fixer cli
planetf1 added a commit to planetf1/mellea that referenced this pull request Aug 11, 2026
…KING returns

generative-computing#1504 fixed generative-computing#1503 by switching two `genstub.py` call sites to
`inspect.signature(func, eval_str=True)`. That resolves postponed parameter
annotations, but it also evaluates the return annotation, so an unresolvable
return type — a `TYPE_CHECKING`-only import, or a forward reference — raises
`NameError` at both sites even when every parameter resolves cleanly:

- `get_argument` reads only the named parameter's annotation, so the return
  annotation is incidental and resolving it should never fail the call.
- `describe_function` renders the signature into the prompt via
  `GenerativeStub.jinja2`, so the return annotation *is* consumed by the model.
  An unresolvable one is therefore left as its postponed string and renders
  quoted — `-> 'Decimal'` — which still names the type, rather than being
  dropped from the prompt. The alternative, omitting it entirely, tells the
  model less.

Both now use the shared `resolve_signature_annotations` helper. The generative-computing#1503
behaviour is unchanged for resolvable annotations: the existing assertions that
no parameter renders quoted still pass.

Scope of what generative-computing#1504 actually broke: only *direct* calls to these two functions,
which previously returned a quoted string rather than raising. No `@generative`
user could observe it, because `create_response_format` already failed earlier
in `GenerativeStub.__init__` — a separate defect dating to `88a4d754` (generative-computing#801),
not to generative-computing#1504. That one is fixed in the following commit; see generative-computing#1529.

Also renames `_pep563_fixtures.py` to `_postponed_annotation_samples.py` with
its call sites, per review feedback on this PR: the module holds no
`@pytest.fixture`, and the PEP number does not belong in the filename. The
backends equivalent was renamed on that basis; this one merged under the old
name via generative-computing#1504. The import and an assertion embedding the full module path are
both updated.

Verified: both new tests fail against the pre-fix code with `NameError`.

Assisted-by: Claude Code
Signed-off-by: Nigel Jones <[email protected]>
psschwei pushed a commit to psschwei/mellea that referenced this pull request Aug 12, 2026
…eturn types (generative-computing#1509)

* fix(backends): resolve postponed annotations in ollama tool schema

convert_function_to_ollama_tool read raw inspect.signature() annotations,
which are unresolved strings under `from __future__ import annotations`
(PEP 563). Pydantic could not build a schema for any non-builtin parameter
type, raising PydanticUserError. Resolve with eval_str=True, matching the
fix already applied to genstub.py for the same root cause.

Assisted-by: Claude Code
Signed-off-by: Nigel Jones <[email protected]>

* fix(backends): resolve postponed annotations per-parameter to avoid return annotation regression

Assisted-by: opencode
Signed-off-by: Nigel Jones <[email protected]>

* test(backends): fold postponed-annotation tests into existing tool test module

Addresses review feedback on generative-computing#1509. The PEP 563 regression tests were moved
into test_discriminated_union_tools.py, already the only module exercising
convert_function_to_ollama_tool, rather than living in a second module for
the same function. The previous change only renamed the standalone file
instead of moving the tests, which did not address the review.

Also renames the samples module to _postponed_annotation_samples.py, dropping
the PEP number from the filename as requested. The module-level
'from __future__ import annotations' still requires the sample code to sit in
its own module; only the tests move.

Verified the moved tests are not vacuous: against the pre-fix baseline 2 of 4
fail, and against parameter-blind eval_str=True resolution 3 of 4 fail.

Assisted-by: Claude Code
Signed-off-by: Nigel Jones <[email protected]>

* test(backends): guard TC-only postponed-annotation tests against silent no-op

Adds the same precondition assert the first test in
TestPostponedAnnotations already has to the three TYPE_CHECKING-only
cases, confirming their sample annotations are still postponed
strings. Without it, dropping `from __future__ import annotations`
from _postponed_annotation_samples.py would make these tests pass
without exercising the resolution path at all.

Ref generative-computing#1507

Assisted-by: Claude Code
Signed-off-by: Nigel Jones <[email protected]>

* fix(backends): resolve tool annotations in the wrapped function's module

`inspect.signature` follows `__wrapped__`, so the annotations reaching the
per-parameter fallback can belong to a function in a different module than the
object passed in. Reading globals from that object meant a `functools.wraps`
decorator's module supplied the resolution namespace, so a colliding type name
resolved to the wrong type and produced a silently incorrect tool schema where
the previous code raised `PydanticUserError`.

Take the namespace from `inspect.unwrap(func, stop=...)`, using the same stop
predicate `inspect.signature` itself uses, so both read the same object. This
is a no-op for undecorated functions.

Also from review:

- correct the lead comment, which described the per-parameter loop as being
  used instead of `eval_str=True` rather than as its fallback
- log the unresolved annotation at debug rather than swallowing it silently
- record why the `eval` is bounded, next to its noqa
- guard the TYPE_CHECKING-only tests so they fail instead of passing vacuously
  if the sample module's import moves out of `if TYPE_CHECKING:`
- match on the unresolved name in the `PydanticUserError` assertion

Assisted-by: Claude Code
Signed-off-by: Nigel Jones <[email protected]>

* refactor(backends): log why the tool annotation fallback engaged

The outer `except` around `inspect.signature(func, eval_str=True)` discarded
the exception entirely, while the per-parameter handler inside it logs at
debug. That asymmetry meant there was no way to tell why the fallback had
engaged for a given tool without attaching a debugger.

Log the exception type and message at debug, matching the inner handler.

Assisted-by: Claude Code
Signed-off-by: Nigel Jones <[email protected]>

* test(backends): cover a colliding type name in wrapped tool resolution

`test_decorated_tool_resolves_in_wrapped_functions_module` covers a type name
absent from the decorator's module, which degrades loudly to
`PydanticUserError`. It does not cover the worse case the namespace fix exists
for: a name that is present in the decorator's module but bound to a different
type, where resolving in the wrong namespace succeeds and emits a
plausible-looking schema for entirely the wrong type.

Add `Zone` to the samples module and a shadowing `Zone` with a different field
in the test module, so a wrapper defined in the test module resolves against
the wrong binding under the previous behaviour. Verified the new test fails
without the `inspect.unwrap` namespace fix, producing a schema with
`wrong_field: integer` in place of `identifier: string` and raising nothing.

Assisted-by: Claude Code
Signed-off-by: Nigel Jones <[email protected]>

* refactor(backends): extract postponed-annotation resolution into a helper

The try-`eval_str`-then-resolve-per-parameter logic is needed by more than one
call site, so move it out of `convert_function_to_ollama_tool` into
`mellea/helpers/annotation_helpers.resolve_signature_annotations`.

Imported directly from the submodule rather than re-exported through
`mellea/helpers/__init__.py`, matching how `tools.py` already imports
`_run_async_in_thread`. That keeps it out of the public API surface.

No behavioural change: the existing tool-conversion tests pass unmodified.

Assisted-by: Claude Code
Signed-off-by: Nigel Jones <[email protected]>

* test(backends): cover an unannotated parameter in the annotation fallback

In the per-parameter fallback an unannotated parameter arrives as
`inspect._empty` rather than a string, so it takes the branch that skips
resolution. Nothing exercised that branch, leaving the helper at 75% branch
coverage.

Add a sample with one bare and one annotated parameter alongside a
TYPE_CHECKING-only return, and assert the bare one still reaches the schema
defaulting to `str`. Takes the helper to 100% statement and branch coverage.

Assisted-by: Claude Code
Signed-off-by: Nigel Jones <[email protected]>

* fix(stdlib): resolve genstub annotations without failing on TYPE_CHECKING returns

generative-computing#1504 fixed generative-computing#1503 by switching two `genstub.py` call sites to
`inspect.signature(func, eval_str=True)`. That resolves postponed parameter
annotations, but it also evaluates the return annotation, so an unresolvable
return type — a `TYPE_CHECKING`-only import, or a forward reference — raises
`NameError` at both sites even when every parameter resolves cleanly:

- `get_argument` reads only the named parameter's annotation, so the return
  annotation is incidental and resolving it should never fail the call.
- `describe_function` renders the signature into the prompt via
  `GenerativeStub.jinja2`, so the return annotation *is* consumed by the model.
  An unresolvable one is therefore left as its postponed string and renders
  quoted — `-> 'Decimal'` — which still names the type, rather than being
  dropped from the prompt. The alternative, omitting it entirely, tells the
  model less.

Both now use the shared `resolve_signature_annotations` helper. The generative-computing#1503
behaviour is unchanged for resolvable annotations: the existing assertions that
no parameter renders quoted still pass.

Scope of what generative-computing#1504 actually broke: only *direct* calls to these two functions,
which previously returned a quoted string rather than raising. No `@generative`
user could observe it, because `create_response_format` already failed earlier
in `GenerativeStub.__init__` — a separate defect dating to `88a4d754` (generative-computing#801),
not to generative-computing#1504. That one is fixed in the following commit; see generative-computing#1529.

Also renames `_pep563_fixtures.py` to `_postponed_annotation_samples.py` with
its call sites, per review feedback on this PR: the module holds no
`@pytest.fixture`, and the PEP number does not belong in the filename. The
backends equivalent was renamed on that basis; this one merged under the old
name via generative-computing#1504. The import and an assertion embedding the full module path are
both updated.

Verified: both new tests fail against the pre-fix code with `NameError`.

Assisted-by: Claude Code
Signed-off-by: Nigel Jones <[email protected]>

* fix(stdlib): survive an unresolvable return type at stub decoration time

`create_response_format` resolves annotations with `get_type_hints`, which
evaluates every annotation including the return type. `GenerativeStub.__init__`
calls it, so a `@generative` stub whose return type exists only under
`if TYPE_CHECKING:` raised `NameError` at decoration time — meaning the
containing module could not be imported at all, with no model call involved.

Only the return type is read here, and an unannotated function already falls
back to `Any` via `type_hints.get("return", Any)`. Degrade an unresolvable
return to that same `Any` rather than failing the decoration. The response model
then parses the result as `Any` instead of the declared type, which is the
behaviour an unannotated stub already gets.

The earlier commit in this PR fixed `describe_function` and `get_argument` but
missed this site, and CI passed regardless: both tests called those functions
directly, so nothing exercised the `@generative` decoration path. Add a test at
that entry point as well as one for `create_response_format` itself.

Assisted-by: Claude Code
Signed-off-by: Nigel Jones <[email protected]>

---------

Signed-off-by: Nigel Jones <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

slot -> stub?

3 participants