Skip to content

feat(engine): add ModelEnvelope, bound to a pipeline at supply time - #2390

Merged
jfallows merged 2 commits into
developfrom
claude/github-issue-2384-0ee74r
Aug 16, 2026
Merged

jfallows merged 2 commits into
developfrom
claude/github-issue-2384-0ee74r

Conversation

@jfallows

@jfallows jfallows commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

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:

public interface ModelEnvelope
{
    int count(String name);
    DirectBufferEx get(String name, int index);
    void set(String name, DirectBufferEx value);
}

set accumulates: a repeated call under one name adds a further occurrence rather than overwriting the one before it, so each stays retrievable by its own get(name, index). The Javadoc says so explicitly, since "set" read in isolation more commonly connotes overwrite. get returns null for 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, and set copies 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.supplyDecoder and supplyEncoder take the envelope ahead of the ModelTransform, since the envelope covers the whole pipeline while the transform is one stage within it:

ModelPipeline supplyDecoder(ModelEnvelope envelope, ModelTransform transform);
ModelPipeline supplyEncoder(ModelEnvelope envelope, ModelTransform transform);

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 passes ModelEnvelope.NONE / ModelTransform.NONE explicitly. ModelEnvelope.NONE reads as empty and discards writes, so a caller with no metadata channel is spelled out rather than inferred.

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). ModelPipeline.transform(...) is unchanged.

No ModelController accessor: 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() == 0 and no value for an absent name and for an index past the end; the bytes being copied out of the caller's buffer on set; a stage reading and writing named metadata through the envelope it was supplied with; the NONE defaults 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 -DskipITs over runtime/engine, model-core, model-json, model-protobuf, model-avro, binding-kafka, binding-http, binding-sse, binding-mqtt, binding-mcp (BUILD SUCCESS), plus checkstyle:check and license:check clean across all ten and the engine's JaCoCo gate green at 223 tests.

Fixes #2384

claude added 2 commits August 16, 2026 16:00
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]>
@jfallows jfallows changed the title feat(engine): add ModelEnvelope for message metadata outside the value feat(engine): add ModelEnvelope, bound to a pipeline at supply time Aug 16, 2026
@jfallows
jfallows merged commit 3fa3a22 into develop Aug 16, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

engine: add ModelEnvelope for message metadata outside the value, exposed via ModelController

2 participants