Skip to content

feat(model-core): realign bytes/string extension stages with the streaming stage design, and make them bidirectional - #2395

Merged
jfallows merged 2 commits into
developfrom
claude/github-issue-2393-2iojh8
Aug 16, 2026
Merged

jfallows merged 2 commits into
developfrom
claude/github-issue-2393-2iojh8

Conversation

@jfallows

Copy link
Copy Markdown
Contributor

Description

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;
  • OMIT conflated withholding a value with rejecting one, surfacing as REJECTED with 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 inside model-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 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 — the plain identity pipeline. padding() splits into decodePadding()/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 omit spec scenario is renamed to withhold, joined by new reject and client.sent.bytes.ext.uppercase scenarios and an event.bytes.yaml asserting the rejection diagnostic end-to-end.

./mvnw clean install over specs/model-core.spec and runtime/model-core is 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/StringModelExtHandler need updating to the new shape.

Fixes #2393

🤖 Generated with Claude Code

https://claude.ai/code/session_01NuGFTLpKmTeqznp9S3Qtpy


Generated by Claude Code

claude added 2 commits August 16, 2026 20:24
…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
@jfallows
jfallows merged commit abcb510 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.

model-core: align bytes/string extension stages with the streaming stage design, and make them bidirectional

2 participants