Skip to content

feat(model-protobuf): add ProtobufModelExt SPI for provider-supplied pipeline stages - #2380

Merged
jfallows merged 8 commits into
developfrom
claude/model-protobuf-extensions-7y9hwr
Aug 16, 2026
Merged

jfallows merged 8 commits into
developfrom
claude/model-protobuf-extensions-7y9hwr

Conversation

@jfallows

@jfallows jfallows commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds a way for an installed module to contribute its own ProtobufTransform stage(s) into model-protobuf's pipeline construction, without model-protobuf needing to know anything about what those stages do — mirroring the AvroModelExt SPI (#2376) exactly, substituted for Protobuf:

  • common-protobuf: ProtobufTransformable<T extends ProtobufTransformable<T>> (append-only, chainable, self-bounded stage builder), with ProtobufStream now extending ProtobufTransformable<ProtobufStream>, so a provider can append transforms to an in-progress stream and get back its own concrete stream type, without depending on ProtobufStream's fuller API or an unchecked cast.
  • model-protobuf: new exported ext package with ProtobufModelExtFactorySpi (extends FactorySpi, so @Incubating gating and ServiceLoader discovery come for free), ProtobufModelExt, ProtobufModelExtContext, ProtobufModelExtHandler — mirroring ModelFactorySpi/Model/ModelContext's worker-scoped, EngineContext-threaded lifecycle exactly, narrowed to Protobuf. Any number of installed extensions compose, each folded into the stream ahead of the existing pipeline construction, at the same point newPipeline already resolves and caches per schema id.
  • ProtobufModelExtHandler.decode(T)/encode(T) are split into two methods (each defaulting to a pass-through), mirroring the decode/encode-suffixed members ProtobufModelHandler already exposes (decodeLenient/encodeLenient, decodePadding()/encodePadding()) — and AvroModelExtHandler's identical split — rather than threading a boolean direction flag through a single method. ProtobufModelHandlerImpl folds installed extensions into both the decoder and encoder pipeline built from the same schema, and encodePadding() now sums the extension padding contribution the same way decodePadding() already did. An extension whose contract only applies to one direction (e.g. a read-side concern like disclosure redaction) overrides just that method and inherits the pass-through default for the other.
  • Each installed extension also contributes a padding() value, summed into the model's Kafka cache capacity sizing contribution, matching model-avro's extPadding() mechanism.
  • protobuf.schema.patch.json: removed the model-protobuf branch's local additionalProperties: false, which is evaluated purely against that branch and can never see properties contributed by a sibling allOf branch such as an installed model extension's schema patch. The shared unevaluatedProperties: false on $defs/models/model (added for model-avro) already enforces the same closed-schema guarantee while seeing annotations from every allOf branch, including extension-contributed ones — without this fix, no installed protobuf model extension could ever validate its own config.

Verified end-to-end through a live engine via a src/test-only TestUppercaseProtobufModelExtFactorySpi, registered solely under META-INF/services so it never ships in the production jar. It uppercases scalar string field values unconditionally, proving the ProtobufModelExtFactorySpi ServiceLoader composition mechanism works end-to-end — independent of any specific installed extension — the same mechanism a real installed extension (e.g. zilla-plus's disclosure) relies on, and now overrides both decode() and encode() to exercise the composition mechanism symmetrically in both directions. The existing ProtobufModelIT scenarios (client.received.protobuf.{json,binary}.ext.uppercase) drive one full round trip through a live engine — request leg (encode) and reply leg (decode) both now fold the extension in, so the application-side scripts were updated to expect the request value already uppercased before it reaches the application — plus their NetworkIT/ApplicationIT self-consistency pairs.

Fixes #1683

Test plan

  • ./mvnw install -pl runtime/common-protobuf,runtime/model-protobuf,runtime/binding-kafka -am — unit tests, including ProtobufModelExtHandlerTest, extension-padding coverage in ProtobufModelDecoderPipelineTest, and the decode/encode split
  • ./mvnw checkstyle:check — clean
  • ./mvnw install -pl specs/model-protobuf.spec — spec module builds against the relaxed schema
  • ./mvnw verify -pl specs/model-protobuf.spec — NetworkIT/ApplicationIT self-consistency, including the ext scenarios updated for the encoder-side fold
  • ./mvnw verify -pl runtime/model-protobuf — ProtobufModelIT against a live engine, including the extension-composition scenarios exercising both decode and encode

Generated by Claude Code

claude added 8 commits August 14, 2026 20:15
…pipeline stages

Mirrors model-avro's AvroModelExt SPI (#2376) exactly, substituting Protobuf
for Avro throughout. Adds ProtobufTransformable to common-protobuf (the
narrower supertype ProtobufStream now extends) and a new
io.aklivity.zilla.runtime.model.protobuf.ext package
(ProtobufModelExtFactorySpi/ProtobufModelExt/ProtobufModelExtContext/
ProtobufModelExtHandler). ProtobufModelHandlerImpl folds every discovered
extension's handler into the decode-only pipeline, ahead of its own
extractor stage, and sums each extension's declared padding() contribution
into the Kafka cache capacity estimate. A deployment with zero installed
extensions pays nothing.

Fixes #1683

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QiMcyVBhRqf8cEmVadRAZ8
The protobuf model's own allOf branch restricted itself with a local
additionalProperties: false, which is evaluated purely against that
branch and can never see properties contributed by a sibling allOf
branch such as an installed model extension's schema patch (already
merged for model-avro's equivalent AvroModelExtFactorySpi). Since the
model extension SPI's whole point is letting an installed module
contribute additional per-model config, a locally-scoped
additionalProperties: false silently blocks every such contribution.

Remove the redundant local restriction; the shared
unevaluatedProperties: false on $defs/models/model (added for
model-avro) already enforces the same closed-schema guarantee while
seeing annotations from every allOf branch, including extension-
contributed ones.
Adds a src/test-only TestUppercaseProtobufModelExtFactorySpi, registered
solely under META-INF/services so it never ships in the production jar,
proving the ProtobufModelExtFactorySpi composition mechanism works
end-to-end through a live engine -- independent of any specific installed
extension. It uppercases scalar string field values unconditionally, with
no configuration of its own, mirroring the ProtobufModelExtDisclosureTransform
withhold-then-substitute pattern over the same ProtobufTransform contract.

New client.received.protobuf.{json,binary}.ext.uppercase scenarios drive
this through ProtobufModelIT's reply-direction decode path (the only
direction extensions attach to), plus their NetworkIT/ApplicationIT
self-consistency pairs.

Fixes a schemaId=0/NO_SCHEMA_ID collision in value.view.json.yaml and
value.binary.yaml: the test catalog's own resolved id defaulted to the
same sentinel used for "unresolved", so a legitimately-resolved schema on
the decode path was discarded as if no schema had been found. An explicit
catalog id avoids the collision, matching the same fix already applied to
model-avro's equivalent test config.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QiMcyVBhRqf8cEmVadRAZ8
…t-jar

TestUppercaseProtobufModelExtFactorySpi and its META-INF/services
registration exist solely to prove the ProtobufModelExtFactorySpi
ServiceLoader composition mechanism in this module's own ProtobufModelIT.
The test-jar packaged everything under target/test-classes with no
curation, so any consumer depending on model-protobuf:test-jar (e.g. a
real installed protobuf model extension's own test suite) picked up this
fixture too -- and since ProtobufModelExt implementations are discovered
and applied unconditionally, its unconditional uppercase transform
silently stacked on top of that consumer's own extension.

Excludes the fixture's class and service registration from the test-jar
so it stays local to this module's own build, mirroring the curated
test-jar packaging convention already used for the engine module's own
type: test SPI implementations.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QiMcyVBhRqf8cEmVadRAZ8
… transform() signature

ProtobufTransformable<T extends ProtobufTransformable<T>> is now self-bounded,
so ProtobufModelExtHandler.transform() returns the caller's own concrete
stream type instead of the narrower ProtobufTransformable supertype.
Mechanical signature update only, no behavior change. ProtobufModelHandlerImpl
no longer needs to cast the extended stream back to ProtobufStream, and test
doubles that mocked ProtobufTransformable now mock ProtobufStream instead,
since a raw ProtobufTransformable mock can no longer bind to the generic
parameter without an unchecked cast.

Mirrors AvroTransformable's identical self-bounded-generic refactor.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QiMcyVBhRqf8cEmVadRAZ8
…irection

ProtobufModelExtHandler.transform(T stream) had no notion of which
direction it was extending, so ProtobufModelHandlerImpl.extend() folded
every installed extension's stage into the decoder pipeline only --
the encoder pipeline built its stream without any extension folding,
and encodePadding() never accounted for extension padding. A future
extension that must transform both directions (e.g. one applied
symmetrically on write and read) had no way to do so.

Split into decode(T transformable) / encode(T transformable), each
defaulting to a pass-through, mirroring the decode/encode-suffixed
members ProtobufModelHandler already exposes (decodeLenient/encodeLenient,
decodePadding()/encodePadding()) rather than threading a boolean flag
through a single method. ProtobufModelHandlerImpl.extend() is split the
same way into extendDecode()/extendEncode(), each backing the matching
newPipeline() overload; encodePadding() now sums the extension padding
contribution the same way decodePadding() already did.

Updates the two existing client.received.protobuf.*.ext.uppercase IT
scripts: their application-side scripts previously assumed the encode
leg (network client's request reaching the application) passed through
untransformed, which is no longer true now that installed extensions
fold into the encoder pipeline too.

Mirrors AvroModelExtHandler's identical decode/encode split.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QiMcyVBhRqf8cEmVadRAZ8
@jfallows
jfallows merged commit 181b05a 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.

Declare ProtobufModelExtFactorySpi and wire provider-supplied pipeline stages in protobuf model

2 participants