Use canonical source file type in the RPC edit-batch gate#7929
Merged
Conversation
The edit-phase BatchVisit optimization in RecipeRunCycle keyed off the raw src.getClass().getName() in two places: the language gate that decides whether a source can be batched, and flushBatch's getObject call that fetches the batched result. getLanguages() (and every other RPC sourceFileType) uses the canonical, codec-registered type name from DynamicDispatchRpcCodec. Lazily-loaded LSTs (e.g. the Moderne CLI's V3 format) hand the scheduler generated subclasses of the real tree type, whose getClass().getName() is the subclass name. The raw-name comparison therefore never matched for those, so the batch language gate failed and every batched recipe but the last was silently skipped (the trailing recipe falls through to the non-batch path). Compare and fetch by canonical source file type instead.
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.
What's changed
RecipeRunCycle's edit-phaseBatchVisitoptimization keyed off the rawsrc.getClass().getName()in two places:currentRpc.getLanguages().contains(src.getClass().getName()); andflushBatch'srpc.getObject(id, originalBefore.getClass().getName())that fetches the batched result.Both now use
DynamicDispatchRpcCodec.canonicalSourceFileType(...)instead.Why
getLanguages()advertises canonical, codec-registered type names (e.g.org.openrewrite.xml.tree.Xml$Document), and every other RPCsourceFileTypeis derived viaDynamicDispatchRpcCodec.canonicalSourceFileType(...).The net effect: a multi-recipe composite of same-RPC recipes (e.g. a language migration) applied only its last sub-recipe when run against a lazily-loaded LST. Recipes ran correctly standalone and in-process (
InMemoryLargeSourceSet, where sources are the real type), which masked the issue.DynamicDispatchRpcCodec.canonicalSourceFileTypealready walks a subclass up to its registered supertype (seeSubclassCodecDispatchTest), so using it here makes the gate and the result fetch agree with the rest of the RPC pipeline.Test plan
CompositeBatchVisitSubclassTest(rewrite-xml) runs a two-recipe composite (ChangeTagValue+ChangeTagAttribute) over an RPC peer against aLazyXmlDocument(a subclass ofXml.Document, mirroring a lazy LST proxy), and asserts both recipes applied../gradlew :rewrite-xml:test --tests "org.openrewrite.xml.rpc.CompositeBatchVisitSubclassTest"green.