Repository navigation
feat(engine): add ModelEnvelope, bound to a pipeline at supply time - #2390
Merged
Merged
Conversation
ModelTransform's contract describes the value being transformed and nothing else, so a stage has no place to read or write data that travels with a message but is not part of the value's own encoding. Adding an accessor shaped after one transport's out-of-band channel would tie the model SPI to that transport's vocabulary, which the SPI-neutrality convention exists to prevent. Add ModelEnvelope, a named, ordered, repeatable list of byte values that never interprets its own contents: count(name), get(name, index), and a set(name, value) that accumulates, so a repeated call under one name adds a further occurrence rather than overwriting the one before it. The caller driving the pipeline supplies the implementation and decides where its contents come from on the way in and end up on the way out, so a transform written against the interface works wherever an envelope is supplied. ModelController gains envelope(), mirroring how authorization() exposes something message-scoped without widening ModelTransform.transform(...). The accessor defaults to ModelEnvelope.NONE, an empty envelope that reads as empty and discards writes, so the addition is source-compatible with every existing ModelController implementation and a stage reaches for the envelope the same way whether or not one is backing it. Adds unit coverage for accumulation under a repeated name, count zero and no value for an absent name or an index past the end, the bytes being copied out of the caller's buffer on set, a transform reading and writing named metadata through ModelController.envelope(), the NONE defaults, and an envelope left untouched by a transform that never reads or writes it. Claude-Session: https://claude.ai/code/session_01MZhZD2wyJbgzXrFMbWYY3y Co-authored-by: Claude <[email protected]>
Replace ModelController.envelope() with a supply-time seam: supplyDecoder and supplyEncoder now take the ModelEnvelope the pipeline is bound to, ahead of the ModelTransform, since the envelope covers the whole pipeline while the transform is one stage within it. A controller accessor only reaches stages the caller composes itself, and a caller that composes a stage can equally construct it with the envelope directly, so the accessor carried no capability of its own. Binding at supply time instead lets an implementation adapt the envelope into its own internals once, as the pipeline is built, rather than pushing it through a per-value callback every stage would have to carry. Drop the no-argument supplyDecoder/supplyEncoder overloads so neither argument can be left implicit: both are documented as never null, implementations assert the envelope, and every call site passes ModelEnvelope.NONE and ModelTransform.NONE explicitly. Threads the new parameter through every ModelHandler implementation (model-core, model-json, model-protobuf, model-avro, engine's TestModelHandler) and every call site (binding-sse, binding-http, binding-mqtt, binding-mcp, binding-kafka's cache read/write paths). ModelEnvelope's own contract loses its per-message scope claim: scope is the supplier's to decide, since it owns the envelope's lifecycle and clears or repoints its contents through its own type as that scope turns over, while a pipeline reads and writes what it holds and never resets it. Thread confinement stays, being a property of the pipeline the envelope is bound to. The engine's test model writes each extracted field into the supplied envelope, so the seam has coverage end to end: fields written under their own paths, and a second value accumulating alongside the first to show the binding survives a pipeline reset. Claude-Session: https://claude.ai/code/session_01MZhZD2wyJbgzXrFMbWYY3y Co-authored-by: Claude <[email protected]>
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.
Description
ModelPipeline's contract describes the value being transformed and nothing else, so nothing reaching a pipeline has a place to read or write data that travels with a value but is not part of its own encoding. Shaping an accessor after one transport's out-of-band channel would tie the model SPI to that transport's vocabulary, which the SPI-neutrality convention exists to prevent.ModelEnvelope— a named, ordered, repeatable list of byte values that never interprets its own contents:setaccumulates: a repeated call under one name adds a further occurrence rather than overwriting the one before it, so each stays retrievable by its ownget(name, index). The Javadoc says so explicitly, since "set" read in isolation more commonly connotes overwrite.getreturnsnullfor an absent name or an index past the end, per the engine's null-defaults convention; the buffer it returns is a non-owning view, andsetcopies the bytes out before returning so the caller may reuse its buffer immediately.Scope is the supplier's to decide, and the interface makes no claim of its own: the supplier owns the envelope's lifecycle and clears or repoints its contents through its own type as the scope it describes turns over — per message where the transport carries per-message metadata, per stream where the metadata describes the stream. A pipeline reads and writes whatever the envelope holds and never resets it. Thread confinement is the one invariant the SPI does state, being a property of the pipeline the envelope is bound to.
Bound at supply time.
ModelHandler.supplyDecoderandsupplyEncodertake the envelope ahead of theModelTransform, since the envelope covers the whole pipeline while the transform is one stage within it:Binding as the pipeline is built lets an implementation adapt the envelope into its own internals once, rather than pushing it through a per-value callback that every stage would have to carry. The no-argument overloads are gone so neither argument can be left implicit: both are documented as never
null, implementations assert the envelope, and every call site passesModelEnvelope.NONE/ModelTransform.NONEexplicitly.ModelEnvelope.NONEreads as empty and discards writes, so a caller with no metadata channel is spelled out rather than inferred.Threads the new parameter through every
ModelHandlerimplementation (model-core,model-json,model-protobuf,model-avro, engine'sTestModelHandler) and every call site (binding-sse,binding-http,binding-mqtt,binding-mcp,binding-kafka's cache read/write paths).ModelPipeline.transform(...)is unchanged.No
ModelControlleraccessor: it would only reach stages the caller composes itself, and such a caller can construct those stages with the envelope directly, so it carried no capability of its own. Adapting the envelope into each format layer's own internals is tracked in #2389.Coverage
ModelEnvelopeTest: accumulation under a repeated name;count() == 0and no value for an absent name and for an index past the end; the bytes being copied out of the caller's buffer onset; a stage reading and writing named metadata through the envelope it was supplied with; theNONEdefaults including a discarded write; and an envelope left with zero reads and zero writes by a transform that never touches it.TestModelHandlerTest: the engine's test model writes each extracted field into the supplied envelope, so the seam is covered end to end — fields written under their own paths, an untouched name still reading zero, and a second value accumulating alongside the first to show the binding survives a pipeline reset.Verified with
./mvnw clean install -DskipITsoverruntime/engine,model-core,model-json,model-protobuf,model-avro,binding-kafka,binding-http,binding-sse,binding-mqtt,binding-mcp(BUILD SUCCESS), pluscheckstyle:checkandlicense:checkclean across all ten and the engine's JaCoCo gate green at 223 tests.Fixes #2384