Skip to content

fix(model-avro): fold installed extensions into the encoder pipeline too - #2383

Merged
jfallows merged 11 commits into
developfrom
claude/zilla-issue-2302-7wu9ht
Aug 16, 2026
Merged

jfallows merged 11 commits into
developfrom
claude/zilla-issue-2302-7wu9ht

Conversation

@jfallows

Copy link
Copy Markdown
Contributor

Description

TestBindingFactory (the type: test binding backing k3po *IT.java tests engine-wide) only ever applied a configured value model as an encoder, on the initial/produce direction — reply-direction data was always forwarded raw. That meant no k3po IT anywhere could exercise a model's decode-time behavior through a live engine. Fixing that surfaced a real gap in AvroModelExt's own contract: nothing in AvroModelExtHandler/AvroModelExtContext restricts an installed extension to one direction, but AvroModelHandlerImpl only ever folded installed extensions into the decoder pipeline — the encoder pipeline built its stream without extend(), and encodePadding() never accounted for extension padding. An extension meant to participate in both directions had no way to actually contribute on encode.

Changes

  • TestBindingFactory: reassembles fragmented DATA frames on both the initial and reply direction (previously only implemented for one), draining and re-presenting not-yet-consumed bytes across both the destination and source windows, with a growable decode slot per direction. Fixes an IndexOutOfBoundsException from writing past the destination buffer's reserved header region, and a silent drop of partially-consumed bytes on UNDERFLOW.
  • AvroModelHandlerImpl: extend() (which folds every installed extension's stage into the pipeline, in discovery order) is now applied to both the decoder and encoder pipeline built from the same schema, instead of the decoder pipeline only; encodePadding() now sums each installed extension's padding contribution the same way decodePadding() already did.
  • New test-only TestUppercaseAvroModelExtFactorySpi (registered only under src/test/resources/META-INF/services, never shipped in the production jar) exercises the AvroModelExt composition mechanism end-to-end through a live engine: apply, fragment accumulation across multiple STRING chunks, drain across a SUSPENDED terminal generator at 100k scale, and reject via AvroPipeline.Status.REJECTED — independently for both the encode and decode direction, now that both are wired.
  • Matching k3po scenario scripts and AvroModelIT/NetworkIT/ApplicationIT test methods (10 tests total, up from 4) covering both directions.

Test plan

  • ./mvnw clean verify -pl runtime/engine — 215 unit tests + k3po ITs, all green
  • ./mvnw clean verify -pl runtime/model-avro — unit tests, 10 AvroModelIT tests (4 pre-existing unaffected + 6 new), checkstyle, JaCoCo all pass
  • ./mvnw clean verify -pl specs/model-avro.spec — 10 NetworkIT + 10 ApplicationIT self-consistency tests, all pass
  • Confirmed the new tests fail for the right reason against the prior AvroModelHandlerImpl (encode-side transform never applied) before implementing the fix

Fixes # (none — surfaced while adding live-engine test coverage for the AvroModelExt composition mechanism, not tied to a specific issue)


🤖 Generated with Claude Code

https://claude.ai/code/session_01GKWELiLVoasTwsuvaXg2Y3


Generated by Claude Code

claude added 7 commits August 15, 2026 01:06
The type:test binding applied its configured model pipeline to each
incoming DATA frame independently, hardcoding FLAGS_INIT|FLAGS_FIN
regardless of the frame's actual flags. Any value whose encoded bytes
spanned more than one DATA frame (due to a bounded WINDOW) was fed to
the pipeline as a truncated, standalone value instead of a single
fragmented one, and transform() had no state to carry produced bytes
or pipeline progress across calls.

Track pending transformed bytes and drive the model pipeline with the
frame's real flags, looping while the pipeline reports OK/OVERFLOW and
stopping on COMPLETE/REJECTED/UNDERFLOW, so a value that spans several
DATA frames -- or needs more destination room than modelBuffer holds
in one pass -- is reassembled and transformed correctly on both the
initial and reply directions.
…TestBindingFactory

The prior commit accumulated a whole value into one fixed-size buffer and
only flushed it on FLAGS_FIN, but never drained ModelStatus#OVERFLOW into a
downstream frame -- once accumulated output reached the buffer's capacity,
transform() kept reporting OVERFLOW against a window with no room left,
looping forever. Fix: drain produced bytes into a downstream DATA frame
every time the pipeline produces output, resetting the destination window
each call, matching the drain-then-resume contract on ModelPipeline#transform.

Separately, ModelStatus#UNDERFLOW can be reported after consuming only part
of the given source (e.g. a JSON string value whose closing quote had not
yet arrived within the current DATA frame) -- the unconsumed tail must be
preserved and prepended to the next frame's bytes, not discarded. Adds a
growable per-stream decode slot that accumulates not-yet-consumed source
bytes across onInitialData/onReplyData calls, mirroring the real decodeSlot
buffering pattern used by protocol bindings.

Also reserves DataFW's fixed 85-byte frame header out of the destination
window's capacity -- wrapping a full window as a DataFW payload otherwise
overflows context.writeBuffer() by exactly that amount.
…code slot

TestSource and TestTarget each hold exactly one pipeline/window/decode-slot
triplet for their own direction, so an initial/reply qualifier on the decode
slot fields was redundant -- matches the unqualified pipeline field already
on both classes.
… real IT

Adds a test-only AvroModelExtFactorySpi (registered under src/test only,
mirroring the engine's other type:test SPI implementations) that uppercases
a targeted string field on decode and rejects a sentinel value, exercising
apply-on-decode, fragment accumulation across chunked STRING events, drain
across a suspended terminal generator at 100k scale, and reject via
AvroPipeline.Status.REJECTED -- independent of any specific real extension's
own tests.

Adds paired client/server scenario scripts plus a small AvroFunctions
k3po helper (repeat) to specs/model-avro.spec, with matching coverage in
AvroModelIT (runtime), NetworkIT and ApplicationIT (spec self-consistency).
AvroModelExt had no encode/decode restriction in its own contract, but
AvroModelHandlerImpl only ever folded installed extensions into the decoder
stream -- the encoder pipeline built its stream without extend(), 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.

extend() now folds extensions into both the decoder and encoder pipeline
built from the same schema, in the same discovery order; encodePadding()
sums in the extension padding contribution the same way decodePadding()
already did.

Extends the test-only AvroModelExtFactorySpi coverage in AvroModelIT (and
the matching NetworkIT/ApplicationIT self-consistency scripts) with a
forward-direction (encode) counterpart to the existing reply-direction
(decode) scenarios -- apply, overflow-drain at 100k, and reject -- so both
directions are independently proven through a live engine. Also renames
the test extension's targeted field from "secret" to "text" and its
sample values away from anything evoking the disclosure/secrets-management
feature this mechanism was originally built to support, since the test
here is meant to exercise the composition mechanism generically.
…ry slots

TestSource and TestTarget now acquire real BufferPool slots (decodePool for
receive, encodePool for send) instead of growable heap buffers, matching the
decodeSlot/encodeSlot pattern used by production bindings. The granted window
is clamped to decodePool.slotCapacity() when a model pipeline is attached, and
replenished via a fresh WINDOW frame as decode-slot bytes are drained, so a
value spanning multiple physical DATA frames keeps flowing instead of stalling
once the slot fills. encodePool is a duplicate() of decodePool so the two
one-time-use buffer views never alias each other within a single call.
… extend() cast

AvroTransformable<T extends AvroTransformable<T>> lets AvroModelExtHandler's
transform() return the caller's own concrete stream type instead of the
narrower supertype, removing the unchecked cast previously needed where
AvroModelHandlerImpl folds each installed extension's stage back onto its
AvroStream. The extension-facing surface stays exactly as narrow as before —
transform(AvroTransform): T is still the only method visible on the stream
parameter, so an extension still cannot reach AvroStream's lenient/reporting/
into methods.
claude added 4 commits August 15, 2026 17:25
Adds a CharSequence-returning getStringView() alongside getString() on
both AvroSource and AvroParser, defaulting to getString() for existing
implementers. A caller that only reads or re-encodes characters within
the current call (never retains them) avoids forcing a String to be
materialized.

AvroJsonParserImpl's getStringView() is a direct passthrough of the
CharSequence already produced by its JSON tokenizer. AvroParserImpl's
binary-path getString()/getStringView()/getKey() are rewritten to
decode once through the reusable CharText flyweight (relocated from
internal.json to the parent internal package so both the read and
write sides can share it), replacing a redundant byte[] copy the old
decode() helper made on every call.
AvroSource has a small, closed set of implementers (the pipeline's own
Source view plus each format's synthetic substitute source), so a
default falling back to getString() bought nothing but a silent way to
forget the override. Every implementer now provides its own
getStringView(), matching the prior default's behavior exactly where a
zero-copy view isn't meaningful (the synthetic sources answer with an
already-materialized value regardless).
AvroModelExtHandler.transform(T stream) had no notion of which
direction it was extending, so AvroModelHandlerImpl.extend() folded
every installed extension's stage into both the decoder pipeline
(canonical value -> the view delivered to a reader) and the encoder
pipeline (a caller's value -> its canonical form) identically. An
extension whose contract only makes sense in one direction had no way
to express that.

Split into decode(T transformable) / encode(T transformable), each
defaulting to a pass-through, mirroring the decode/encode-suffixed
members AvroModelHandler already exposes (decodeLenient/encodeLenient,
decodePadding()/encodePadding()) rather than threading a boolean flag
through a single method. AvroModelHandlerImpl.extend() is split the
same way into extendDecode()/extendEncode(), each backing the matching
newPipeline() overload.
…n fragmented reject scripts

The two fragmented-value reject scenarios (missing required field, disallowed
additional property) previously asserted a bare `read aborted` on the
application side, with no preceding data. That coincidentally held only
because TestBindingFactory's prior per-frame transform hard-coded every
DATA frame as self-contained (INIT|FIN), so an incomplete first fragment was
rejected as malformed JSON before genuine cross-frame reassembly ever ran.

Now that TestBindingFactory correctly reassembles a value across DATA
frames, the JSON model's encoder streams out validated-so-far output before
it can determine, upon completing the object, that the value is ultimately
invalid -- a legitimate streaming behavior, not a regression. The peer
client.rpt is updated to write that same literal partial output (mirroring
what the engine actually forwards) so the paired ApplicationIT self-
consistency check stays accurate, and server.rpt asserts it before the abort.
@jfallows
jfallows merged commit 09a2519 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