Repository navigation
feat(model-core): realign bytes/string extension stages with the streaming stage design, and make them bidirectional - #2395
Merged
Conversation
…aming stage design, and make them bidirectional BytesTransform and StringTransform were whole-value calls returning a length or OMIT. Four limits followed from that shape: the whole value had to be materialized before any stage ran; a chain of N stages cost N copies through alternating scratch buffers; an int return could not express "destination full, resume me", so a transformed value had to fit the destination in one call; and OMIT conflated withholding a value with rejecting one, surfacing as REJECTED with no diagnostic either way. Give these stages the shape every other model's stages have. A stage now consumes one event with a read-only view of the current value, forwards what it keeps to its downstream, steers its upstream through a control handle, and reports a status. The event vocabulary is the strict subset a value with no internal structure needs -- value-start, segment, value-end, no field event -- declared per model, with the machinery shared internally. Chains bind sink-to-sink at assembly, so a composition is one streaming pass with no intermediate materialization, and a bounded destination suspends and resumes rather than capping the value size. Withholding and rejecting become distinct outcomes on the control handle: rejecting supplies the diagnostic the model reports, withholding raises nothing at all. The extension handler splits into decode and encode with pass-through defaults, matching the other models, and installed stages fold into the encode pipeline too. An extension applying on only one direction overrides that method alone and leaves the other exactly as it would be with no extension installed. padding() splits per direction, so a stage that expands a value on write has its own accounting. The metadata channel reaches a stage through an accessor on the control handle, defaulting to the empty envelope. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NuGFTLpKmTeqznp9S3Qtpy
…nce per draining call A stage whose output is a function of the whole value emits it at value end. Against a bounded destination that emission suspends, and the pipeline keeps returning OVERFLOW against a window whose input was already fully consumed -- so the final-fragment flag reached the validator again on every one of those calls, re-running the model's own end-of-value checks. Track INIT and FIN as delivered-once per value, so the validator sees each exactly once however many calls the value's output takes to drain. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NuGFTLpKmTeqznp9S3Qtpy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
BytesTransformandStringTransformwere whole-value calls returning a length orOMIT. Four limits followed from that shape:intreturn could not express "destination full, resume me", so a transformed value had to fit the destination in one call;OMITconflated withholding a value with rejecting one, surfacing asREJECTEDwith no diagnostic either way.This gives these stages the shape every other model's stages have.
Stage contract (§2). A stage consumes one event with a read-only view of the current value, forwards what it keeps to its downstream, steers its upstream through a control handle, and reports a
ModelStatus. The event vocabulary is the strict subset a value with no internal structure needs — value-start, segment, value-end, no field event — declared per model (BytesEvent/StringEvent,*Source,*Controller,*Sink), with the pump, validation, and back-pressure accounting shared internally. Chains bind sink-to-sink at assembly, so a composition of any number of stages is one streaming pass with no intermediate materialization, and a bounded destination suspends and resumes rather than capping the value size. The machinery stays insidemodel-core, so these types name the engine's own vocabulary directly.Because a streaming stage holds the in-flight state of one value, the chain is now folded per stream rather than once per model configuration.
Withhold vs reject.
*Controller.reject(diagnostic)supplies the reason the model reports;*Controller.withhold()declines to deliver a value the stage found nothing wrong with and raises nothing at all. Both terminate delivery, and the two are distinguishable by the event each does or does not produce.Directionality (§3). The extension handler splits into
decodeandencodewith pass-through defaults, matching the other models, and installed stages fold into the encode pipeline too. An extension applying on only one direction overrides that method alone and leaves the other exactly as it would be with no extension installed — the plain identity pipeline.padding()splits intodecodePadding()/encodePadding(), so a stage that expands a value on write has its own accounting.Metadata envelope (§4). Reached through an accessor on the control handle, defaulting to the empty envelope.
Coverage (§5). A stage observing a value delivered across fragments; a bounded destination suspending and resuming until drained; a chain applied in one pass; withholding distinguished from rejecting with a diagnostic; an extension applying on encode, and one overriding only decode leaving encode unchanged; the identity fast path preserved when no stage is installed; per-direction padding; and the envelope reaching a stage. The
omitspec scenario is renamed towithhold, joined by newrejectandclient.sent.bytes.ext.uppercasescenarios and anevent.bytes.yamlasserting the rejection diagnostic end-to-end../mvnw clean installoverspecs/model-core.specandruntime/model-coreis green: 104 unit tests, 23 model-core ITs, 44 spec ITs, 9 spec unit tests.This changes an exported extension SPI, so out-of-tree implementations of
BytesModelExtHandler/StringModelExtHandlerneed updating to the new shape.Fixes #2393
🤖 Generated with Claude Code
https://claude.ai/code/session_01NuGFTLpKmTeqznp9S3Qtpy
Generated by Claude Code