Skip to content

feat: per-requirement chunking strategies #1441

Closed

Description

@ajbozarth

Follow-up to #1440. Move chunking from a single shared call-site concern to a per-validator one: each Requirement declares how the stream should be chunked for it, so different validators can validate at different granularities (sentence vs. paragraph vs. custom) instead of sharing one strategy.

Motivation

Chunking exists to break the stream into units a validator can check. Different validators want different units to validate optimally; forcing them to share one strategy (as #1440 does) is a compromise. Letting each validator choose its own chunking lets each validate on the boundary that suits it.

Fixed decisions

The open question: who holds the Chunker

The Chunker is the stateful object (pending fragment between deltas). The strategy is on the Requirement either way; the question is where the live Chunker instance lives. This is the crux, and the two proposals map to the two sides of the design discussion.

The deciding criterion — lifecycle mismatch

  • A Chunker is inherently per-stream: its pending-fragment state is meaningless across streams.
  • A Requirement is reusable across streams: built once, used in many calls.

So the real question is what the Chunker's lifecycle binds to. Option 1 must manage the mismatch (per-stream state on a reusable object); option 2 has no mismatch (per-call object holds per-stream state).

Option 1 — Requirement holds the Chunker

The Requirement carries both its strategy and its live Chunker. stream() feeds deltas to each Requirement's Chunker.

  • For: Requirement is already stateful (_output) and already cloned per attempt via copy(req); a Chunker rides that same isolation. Keeps chunking + validation co-located on the object that owns both concerns. Leverages state the Requirement already has.
  • Against: binds per-stream state to a reusable object. Requires the copy(req)/reset discipline to hold rigorously or state leaks between streams. Concern raised that a validator object should not carry stream-lifecycle state.

Option 2 — Stream holds a per-validator Chunker table

The Requirement carries only its strategy. stream()/Streamer builds a Chunker per validator at stream start (a lookup keyed by validator) and owns them for the stream's lifetime. Deltas are dispatched to each validator's Chunker via the table.

Author lean: Option 2

Leaning Option 2, on the lifecycle argument above: the Chunker is per-stream state, so binding it to the per-call Stream (option 2) fits its nature, whereas binding it to a reusable Requirement (option 1) creates a mismatch that has to be managed with reset/clone discipline. Not a settled decision — still needs team buy-in.

Notes

  • Per-validator chunking and chunk-state ownership are one decision, not two: moving the strategy per-validator is what creates per-validator state, which is what forces the ownership question. That is why refactor: replace stream_with_chunking with single-task stream() #1440 keeps a single shared Chunker and defers both to this issue together.
  • Needs team buy-in before implementation; the two options are the pitch to decide between, not a settled design.
  • Whichever option: the Chunker object itself (from refactor: replace stream_with_chunking with single-task stream() #1440) is unchanged — only its owner and multiplicity move. The state division (Streamer owns accumulated; Chunker owns pending fragment) also carries over unchanged.

Activity

  1. added
    enhancement
    area/streaming
    area/requirement
    on Jul 24, 2026
  2. ajbozarth commented on Aug 6, 2026

    @ajbozarth
    MemberAuthor

    After running into issues writing #1440 @jakelorocco @planetf1 and I had a short design call to spec this out in more detail in order to unblock my work on the refactor. I'll do my best to loosely summarize the design below so for reference when I get to this next issue.

    Rather than "moving" the new Chunker to Requirement we'll be adding it. The Streamer will still have the option to set its own clunker that determines the chunks its iterations return. In addition Requirement will now ALSO have a Chunker that lets it handle its own chunking specific to its validation needs. It will be in charge of its own state, whether it saves the accumulated text, how it chunks, etc. By default it would chunk subsets of whatever chunks the iterator passes to it, as such we will introduce a new neutral state where validation did not fail but was unable to successfully pass either. Initially this state could be caused by passing too small of chunks in for validation according to its own rules.

    The key take away from the discussion though is that chunking will not move to Requirement but instead be duplicated there

  3. self-assigned this
    on Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/requirementarea/streamingenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions