Repository navigation
Description
Describe the desired outcome from the user's perspective
As a Zilla contributor writing a transform stage in a model's own format-native vocabulary, I want to reach the same out-of-value metadata channel a ModelTransform reaches, so that a stage which has to work over the format's structured event stream is not cut off from metadata a stage in the generic vocabulary can already read and write.
Acceptance criteria
1. Two gaps left open by #2384
#2384 added ModelEnvelope. As shipped, a caller supplies one at ModelHandler.supplyDecoder(ModelEnvelope, ModelTransform) / supplyEncoder(...) time, and a stage the caller composes into that ModelTransform chain reaches it because the caller constructs that stage with it. That is as far as it goes. Two things are missing before an envelope with real content in it can reach a stage a caller does not construct:
1a. A caller's own stage is the only stage the supply seam reaches. The envelope is bound to the pipeline, but nothing hands it onward to a stage the model itself folds in. A mediating ModelTransform supplies its own ModelController downstream, so it can steer every stage after it in that chain — which again covers only stages in the ModelTransform chain, and nothing else.
1b. A format-native stage is not in that chain, and is upstream of the adapter that would be. Every model with a *ModelExtFactorySpi (#1681, #1682, #1683, #1684) folds an extension's stages into the format-native stream, ahead of the adapter bridging to the generic vocabulary. From AvroModelHandlerImpl:
extendDecode(Avro.stream(Avro.parser(schema)), schema) // extension stages appended first
.transform(adapter) // AvroModelTransform after
.into(generator);AvroTransformable.transform appends "in data-flow order", so those stages run before the adapter. The controller such a stage receives is AvroPipelineImpl.Control — a private class inside common-avro holding the parser and nothing else. AvroModelTransform.Control is constructed inside model-avro and handed downstream, so a format-native stage never sees it, and the mediating-stage seam in 1a cannot reach one either. common-json and common-protobuf have the same shape.
2. Per-message supply — answered by #2384's supply-time binding
Give the caller driving a ModelPipeline a way to supply the envelope for the message being transformed, with the same lifetime authorization has — per message, not per stream.
Resolved without a further signature change. #2384 binds the envelope to the pipeline at supply time and makes the supplier own its lifecycle: the supplier decides the scope its contents describe and clears or repoints them through its own type as that scope turns over, while the pipeline reads and writes what it holds and never resets it. A value is therefore never transformed against contents belonging to a different message, by construction rather than by enforcement, and a caller that supplies nothing leaves ModelEnvelope.NONE in place.
Binding at supply time is also what makes §3 tractable: a model adapts the envelope into its own internals once, as the pipeline is assembled, rather than pushing it through a per-value callback every format-native stage would have to carry.
3. Reaching a format-native stage
Whatever a model is supplied in §2 must reach a stage in its own format-native vocabulary. Two shapes, and this issue should settle which:
- Per-format interface.
common-avrodeclares its ownAvroEnvelopewith the same three methods, exposed onAvroController;model-avroadapts one to the other.common-jsonandcommon-protobufrepeat it. Keeps eachcommon-*module's dependencies as they are — none of them depends onengine— at the cost of three identical interfaces and three adapters, each free to drift. - Shared home. Move the interface somewhere both layers already see.
ModelEnvelopeneeds onlyDirectBufferEx, socommon-agronacarries it with no new dependency. One interface, no adapters, no drift; the cost is a model-layer concept sitting in a buffer module.
Whichever is chosen, a format-native stage reads and writes named metadata exactly as a ModelTransform does, with the same accumulating set, and a stage that never asks for the envelope costs nothing.
4. Both directions
Decode and encode alike. A model drives separate pipelines for each, and a stage appended to either reaches the envelope on the same terms.
5. Coverage
A format-native stage reading a name the caller supplied on decode; one writing a name on encode and the caller draining it afterwards; repeated set under one name accumulating in call order, seen identically from a format-native stage and a ModelTransform; a caller supplying nothing leaving ModelEnvelope.NONE and no observable change; a stage that never touches the envelope incurring no cost. Coverage in each common-*/model-* pair for §3.
6. Scope
The three models whose format-native stages live in a common-* module: avro, json, protobuf.
model-core's bytes/string extension stages are excluded. They take one fully-buffered value with no control handle an envelope could be reached through, and their extension handler declares no direction at all, so there is nothing to attach this to until that contract is reshaped — #2393. The envelope for those two models follows from it.
Additional context
Follows #2384. This adds the reach #2384 left to each format layer; the supply seam it also once needed is now covered by #2384 itself, per §2.
Related: #2311 (block reporting, the other channel a stage uses for data outside the value), #1689 (a storage layer populating and draining an envelope against its own out-of-band data), #2393 (reshaping model-core's stage contract, which this depends on for bytes/string).
Activity
jfallows commentedon Aug 16, 2026
Description amended against what #2384 actually shipped, since this was written a couple of hours before that PR took its final shape. Four corrections, and one addition:
§1 no longer claims there is no supply seam.
ModelHandler.supplyDecoder(ModelEnvelope, ModelTransform)/supplyEncoder(...)carry it, with the no-argument overloads removed so both arguments are always explicit. What survives of 1a is narrower and is the real gap: the supply seam reaches a stage the caller constructs, and nothing else.§1 and §3 no longer build on
ModelController.envelope(). That accessor did not ship. It would only ever have reached 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, and an unused SPI accessor is easier to add later than to remove.§2 is answered rather than implemented. Supply-time binding makes the supplier own the envelope's lifecycle, so a value is never transformed against contents belonging to a different message by construction rather than by enforcement — no
ModelPipeline.transform(...)widening. Worth noting it is also what makes §3 tractable at all: a model adapts the envelope into its own internals once, as the pipeline is assembled, instead of pushing it through a per-value callback that every format-native stage would have to carry, which for provider-supplied stages would mean a new lifecycle callback on each ext SPI.§5 drops "an envelope supplied for one message not visible while transforming the next." That criterion described the per-message design; under supply-time binding the envelope deliberately persists across values and the supplier turns its contents over.
§6 added, recording that
model-coreis out of scope. Its bytes/string extension stages are whole-value calls —int transform(value, index, length, dst, dstIndex)— with no control handle to reach an envelope through, andBytesModelExtHandler/StringModelExtHandlerdeclare a singletransform(...)with no direction at all, so decode-only there comes from handler wiring rather than the contract. Reshaping that is #2393; the envelope for those two models falls out of it, and retrofitting one onto today's signature would mean stage-construction injection, which #2393 replaces.§3 settled on the per-format interface:
AvroEnvelope,JsonEnvelope,ProtobufEnvelope, each adapted in its model module. Implemented in #2394, along with §4 and §5.Generated by Claude Code