Skip to content

feat(model-core): add bytes/string models and ModelExtFactorySpi composition - #2382

Merged
jfallows merged 4 commits into
developfrom
claude/model-core-extensions-bytes-string-571t07
Aug 16, 2026
Merged

jfallows merged 4 commits into
developfrom
claude/model-core-extensions-bytes-string-571t07

Conversation

@jfallows

Copy link
Copy Markdown
Contributor

Description

Adds bytes and string value models to model-core, and a ModelExtFactorySpi composition mechanism (BytesModelExtFactorySpi / StringModelExtFactorySpi) that lets independently-installed extensions transform a model's value on the decode path — analogous to the existing AvroModelExt mechanism, generalized to the core bytes/string models.

Key additions:

  • BytesModelConfig/StringModelConfig and their factories in model-core
  • BytesModelExtFactorySpi/StringModelExtFactorySpi SPI: ModelExtContext → ModelExtHandler → Transformable/Transform, discovered via ServiceLoader and composed unconditionally (every installed extension always applies)
  • CoreExtModelPipeline: buffers a value across FLAGS_INIT/FLAGS_FIN fragments, folds it through installed transforms, and drains OVERFLOW output across multiple decode calls when a transform's output exceeds the available buffer
  • A test-only BytesModelExtFactorySpi (registered under src/test only, never shipped in the production jar) proves the composition mechanism end-to-end through a live engine (CoreModelIT): apply-on-reply, fragment accumulation, OVERFLOW/drain across multiple frames, and reject-on-omit -- independent of any specific extension's own tests
  • Unit test coverage for the one case with no realistic wire-level equivalent (summed padding across multiple simultaneously-installed extensions)

Fixes # (issue)

Test plan

  • ./mvnw install -pl runtime/model-core,runtime/model-core.conf,specs/model-core.spec -am — checkstyle, license headers, unit tests, JaCoCo, and all k3po ITs (including the new client.received.bytes.ext.* scenarios) pass

Generated by Claude Code

claude added 4 commits August 14, 2026 21:45
Adds a new opaque `bytes` model to model-core, treating the value as a raw
byte sequence with no field traversal, no schema, and no catalog. Adds
independent `BytesModelExtFactorySpi`/`StringModelExtFactorySpi` SPIs
(mirroring model-avro's `AvroModelExtFactorySpi`) so an installed module can
contribute its own whole-value pipeline stage to either model. Since bytes
and string have no schema, resolution happens once per model config at
handler construction rather than once per resolved schema.

`BytesTransformable`/`StringTransformable` and their `*Transform` companions
live directly in model-core (no `common-bytes`/`common-string` codec module
exists, since neither model decodes a wire format). Composition folds
installed extensions ahead of the model's own passthrough validate-and-copy
processing; a zero-extension deployment reuses the existing CoreModelHandler/
CoreModelPipeline unchanged. A new CoreExtModelHandler/CoreExtModelPipeline
handles the ext-composed case, buffering the whole value across fragments
(needed since a transform requires the complete value, unlike the existing
per-fragment identity copy) and reporting installed extensions' combined
padding contribution.

Extensions apply on decode only; encode (the write path into the broker)
always delegates to a plain CoreModelHandler so the source of truth is never
altered on produce.
BytesTransform/StringTransform each carried their own padding(), duplicating
BytesModelExtHandler/StringModelExtHandler's own padding() without either
ever being summed together, leaving the handler-level method dead. Mirrors
model-avro's AvroModelExtHandler.padding(schema): a single declaration point
per installed extension, summed once at handler construction.
Picks up #2381, which lets the type: test binding drive a configured value
model's decoder on the reply direction, not just the encoder on initial --
needed so model-core-ext's disclosure IT can exercise the actual decode-time
transform through a live engine instead of only proving encode is a no-op.
…l IT

CoreExtModelPipelineTest exercised the extension-composition mechanism
(apply, fragment accumulation, OVERFLOW/drain, reject-on-omit) only by
calling ModelPipeline.transform(...) directly with hand-sized buffers --
never through a live engine's frame dispatch and buffer lifecycle, so a
passing unit test could still coexist with the mechanism being broken
end-to-end.

Add a test-only BytesModelExtFactorySpi (registered under src/test only,
so it never ships in the production jar) that uppercases a value and
signals OMIT for a single 0x00 byte -- generic and business-agnostic,
exercising only the composition mechanism itself, not any particular
installed extension's behavior. Wire it into three new CoreModelIT
scenarios: a small round trip (apply), a ~100KB round trip (forces the
pipeline's real OVERFLOW/drain-across-calls path, since the engine's
32KB default buffer.slot.capacity -- raised here to 64KB, still smaller
than the value -- would otherwise abort the stream), and a single-byte
sentinel (reject-on-omit). NetworkIT/ApplicationIT gain the matching
peer-to-peer self-consistency checks.

Remove the two CoreExtModelPipelineTest methods this now covers more
faithfully (reject-on-omit, fragment accumulation before OVERFLOW/drain);
keep the multi-extension padding-summing test, which has no realistic
wire-level equivalent. Drop BytesModelFactoryTest.shouldDiscoverNoExtensionsByDefault,
whose "zero installed extensions" premise no longer holds now that a
test-only extension is genuinely registered for the module's own ITs --
shouldCreateReader already covers the same behavior directly via an
explicit empty list, bypassing ServiceLoader discovery entirely.
@jfallows
jfallows merged commit f37844b 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.

2 participants