Scope Python RPC marketplace responses to the requested distribution#7512
Merged
jkschneider merged 4 commits intomainfrom Apr 29, 2026
Merged
Scope Python RPC marketplace responses to the requested distribution#7512jkschneider merged 4 commits intomainfrom
jkschneider merged 4 commits intomainfrom
Conversation
`discover_recipes()` eagerly walked every `openrewrite.recipes` entry
point on `_get_marketplace()` init and `handle_get_marketplace()`
returned the full singleton, so installing any pip package had its
`RecipeBundle` tagged with every recipe in the process - including the
eight built-in `org.openrewrite.python.*` recipes activated by the
`openrewrite` distribution itself. A visualization-only package like
`moderne-visualizations-misc` ended up "owning" every Python recipe.
Track per-distribution attribution at activation time
(`{distribution_name -> set(recipe_name)}`), have
`handle_install_recipes` return only the rows for the requested
package, and let `handle_get_marketplace` filter by `packageName` when
supplied. `PipRecipeBundleReader` now uses the install response
directly instead of issuing a follow-up `GetMarketplace` call that
would still see the full singleton.
`InstallRecipesResponse` carries the new `recipes` field
backwards-compatibly: older Python servers that don't include it
deserialize to `null`, accessed through `recipesOrEmpty()`.
The number of built-in `org.openrewrite.python.*` recipes will change over time. Drop the hard-coded "eight" from the comments and test docstrings so they don't decay.
`Optional[Dict[str, Set[str]]]` told the reader nothing about what the keys or values mean, and pushed PEP 503 normalization out to every call site. Replace it with a small `RecipeAttribution` dataclass that encapsulates the storage, normalizes distribution names on both record and lookup, and exposes named `record(...)` / `recipes_for(...)` methods. Export it from the package since it's now part of the `discover_recipes` signature.
…ntic - `recipesInstalled` is back to the diff semantic (recipes added by THIS call, zero on idempotent reinstalls), matching the field name's promise and the prior wire contract. The new `recipes` field carries the cumulative per-distribution row list separately. Audit of other language servers (Java in-process, C# LanguageServer, JS, Go) confirms Python is the sole InstallRecipes producer and no consumer reads `recipesInstalled` today, so the diff semantic is the safe default. - Drop `@dataclass` on `RecipeAttribution`. The auto-generated `__init__(_by_package=...)` exposed the internal map through the constructor signature and we don't use the auto `__eq__`/`__repr__`. Plain class with `__init__(self) -> None` keeps the storage truly private. - Replace bare `Dict[str, Set[str]]` with NewType-typed `Dict[NormalizedDistName, Set[RecipeName]]`. `NormalizedDistName` can only be built via `_normalize_package_name`; `RecipeName` propagates through `recipe_name_set`, the attribution API, and `_collect_marketplace_rows`'s filter parameter. Zero runtime cost, type-checker discipline at every site.
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.
Summary
discover_recipes()eagerly walked everyopenrewrite.recipesentry point on_get_marketplace()init, andhandle_get_marketplace()returned the full singleton — so installing any pip package had itsRecipeBundletagged with every recipe in the process, including the eight built-inorg.openrewrite.python.*recipes activated by theopenrewritedistribution itself. A visualization-only package likemoderne-visualizations-miscended up "owning" every Python recipe.{distribution_name -> set(recipe_name)}).handle_install_recipesreturn the rows for just the requested package.handle_get_marketplacefilter bypackageNamewhen supplied; behavior is unchanged when no filter is provided.PipRecipeBundleReadernow constructs its marketplace from the install response directly instead of issuing a follow-upGetMarketplacecall that would still see the full singleton.InstallRecipesResponsecarries the newrecipesfield backwards-compatibly: older Python servers that don't include it deserialize tonull, accessed viarecipesOrEmpty().Pairs with the moderne-saas fix that re-enables the pip flow into the recipe marketplace.
Test plan
pytest tests/— 1,125 passed, 56 skipped../gradlew :rewrite-python:test :rewrite-core:test --tests RewriteRpcTest— BUILD SUCCESSFUL.test_marketplace.py::TestPerPackageAttribution:[], not the eight built-ins.GetMarketplacefilter bypackageNamereturns only that package's recipes; no-filter still returns everything.