Skip to content

feat(common-avro,common-json,common-protobuf): reach the metadata envelope from a format-native stage - #2394

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

Copy link
Copy Markdown
Contributor

Description

A stage working over a format's own event stream had no place to read or write data that travels with a value but is not part of its encoding. The engine's metadata channel could not fill the gap either: common-avro, common-json, and common-protobuf do not depend on engine, so none of them can name ModelEnvelope.

Each format layer gains its own channel, and each model module adapts.

AvroEnvelope / JsonEnvelope / ProtobufEnvelope — a named, ordered, repeatable list of byte values per format, all three with the same contract: set accumulates so a repeated call under one name adds a further occurrence rather than overwriting the one before it, get returns null for an absent name or an index past the end, and the bytes are copied out before set returns. Scope is the supplier's to decide; the interface claims only thread confinement, being a property of the pipeline it is bound to.

Bound to a pipeline once, as it is assembled:

Avro.stream(Avro.parser(schema))
    .transform(adapter)
    .lenient(lenient)
    .reporting(reporter)
    .envelope(envelope)
    .into(generator);

and read back from any stage through the format's own controller — AvroController.envelope(), JsonController.envelope(), ProtobufController.envelope() — each defaulting to that format's NONE, which reads as empty and discards writes. A pipeline assembled without one costs a stage that never asks for it nothing.

AvroModelEnvelope / JsonModelEnvelope / ProtobufModelEnvelope bridge the two vocabularies, forwarding each call to the ModelEnvelope the caller supplied at supplyDecoder / supplyEncoder time. Each resolves to its format's own NONE when the caller supplied ModelEnvelope.NONE, so nothing wraps a channel that carries nothing. The adaptation happens once, as the pipeline is assembled, leaving the hot path unchanged — no per-value or per-call adaptation.

Both directions: decode and encode chains each bind the envelope, so a stage appended to either reaches it on the same terms.

Scope

Implements #2389 §3 (per-format interface, the alternative chosen over a shared home), §4, and §5 for the three common-*/model-* pairs.

§2 asked for per-message supply. That is answered rather than built: #2390 binds the envelope at supply time and makes the supplier responsible for turning its contents over, so the pipeline never receives an envelope belonging to a different message by construction. The issue description is amended to match.

model-core is not covered here. Its extension stages take one fully-buffered value with no control handle to reach an envelope through, and its extension handler declares no direction at all — reshaping that contract is #2393, and the envelope for those two models follows from it.

Coverage

AvroEnvelopeTest in common-avro covers the contract itself, NONE in force when a pipeline is assembled without one, and a stage reading and writing through its controller.

AvroModelEnvelopeTest, JsonModelEnvelopeTest, and ProtobufModelEnvelopeTest each cover an extension's format-native stage reading a name the caller supplied on decode, writing one on encode for the caller to drain, one envelope observed identically by a format-native stage and a ModelTransform, and NONE reaching a stage when the caller supplies none.

Verified with ./mvnw clean install — integration tests included — over common-avro, common-json, common-protobuf, model-avro, model-json, and model-protobuf: BUILD SUCCESS, checkstyle and JaCoCo clean across all six.

Fixes #2389


Generated by Claude Code

claude added 2 commits August 16, 2026 18:34
…at-native stage

An AvroStream pipeline could carry no metadata alongside the datum it
transforms, so a stage working over the format's own event stream had no place
to read or write data that is not part of the datum's encoding. The engine's
own metadata channel could not fill the gap either: common-avro does not depend
on engine and so cannot name it.

Add AvroEnvelope, common-avro's own named, ordered, repeatable list of byte
values, with the same accumulating set as any such channel: a repeated call
under one name adds a further occurrence rather than overwriting the one before
it, get returns null for an absent name or an index past the end, and the bytes
are copied out before set returns. It is bound to a pipeline once, through
AvroStream.envelope(...), and read back by any stage through
AvroController.envelope(). The default is AvroEnvelope.NONE, which reads as
empty and discards writes, so a pipeline assembled without one costs a stage
that never asks for it nothing.

model-avro adapts the two vocabularies: AvroModelEnvelope forwards each call to
the ModelEnvelope the caller supplied at supplyDecoder/supplyEncoder time, and
resolves to AvroEnvelope.NONE when the caller supplied ModelEnvelope.NONE, so no
wrapper exists on the path that carries nothing. The adaptation happens once,
as the pipeline is assembled, leaving the hot path unchanged.

Coverage in common-avro for the envelope's own contract, NONE in force when a
pipeline is assembled without one, and a stage reading and writing it through
its controller; in model-avro for an extension's format-native stage reading a
name the caller supplied on decode, writing one on encode for the caller to
drain, one envelope observed identically by a format-native stage and a
ModelTransform, and NONE reaching a stage when the caller supplies none.

Claude-Session: https://claude.ai/code/session_01MZhZD2wyJbgzXrFMbWYY3y

Co-authored-by: Claude <[email protected]>
…e metadata envelope from a format-native stage

Mirrors the avro pair: neither a JsonStream nor a ProtobufStream pipeline could
carry metadata alongside the value it transforms, so a stage working over either
format's own event stream had no place to read or write data that is not part of
the value's encoding, and neither common module can name the engine's own
channel.

Add JsonEnvelope and ProtobufEnvelope, each its own named, ordered, repeatable
list of byte values with the same accumulating set, bound to a pipeline once
through JsonStream.envelope(...) / ProtobufStream.envelope(...) and read back by
any stage through the format's own controller. Both default to NONE, which reads
as empty and discards writes.

model-json and model-protobuf each adapt their format's envelope to the
ModelEnvelope the caller supplied at supplyDecoder/supplyEncoder time, resolving
to the format's own NONE when the caller supplied ModelEnvelope.NONE, so nothing
wraps a channel that carries nothing. The adaptation happens once, as the
pipeline is assembled.

Coverage in each model module mirrors the avro pair: an extension's
format-native stage reading a name the caller supplied on decode, writing one on
encode for the caller to drain, one envelope observed identically by a
format-native stage and a ModelTransform, and NONE reaching a stage when the
caller supplies none.

Claude-Session: https://claude.ai/code/session_01MZhZD2wyJbgzXrFMbWYY3y

Co-authored-by: Claude <[email protected]>
@jfallows
jfallows merged commit a52a6cb 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: supply ModelEnvelope per message, and expose it to a model's format-native transform stages

2 participants