Repository navigation
Description
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
ChunkingStrategymoves onto theRequirementbase class. In both options below, the strategy (stateless config) is declared per-Requirement. This is not the contested part.- refactor: replace stream_with_chunking with single-task stream() #1440's single
Chunkeron theStreamer(fed by the onechunking=param) becomes oneChunkerper validator.
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
Chunkeris inherently per-stream: its pending-fragment state is meaningless across streams. - A
Requirementis 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:
Requirementis already stateful (_output) and already cloned per attempt viacopy(req); a Chunker rides that same isolation. Keeps chunking + validation co-located on the object that owns both concerns. Leverages state theRequirementalready 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.
- For: no lifecycle mismatch — Chunkers are born and die with the per-call Stream, matching their per-stream nature.
Requirementstays free of stream-lifecycle state (only holds the stateless strategy). Extends refactor: replace stream_with_chunking with single-task stream() #1440 minimally — refactor: replace stream_with_chunking with single-task stream() #1440 already holds one Chunker on the Streamer; this is N. - Against: splits chunking config (on Requirement) from chunking state (on Stream) across two owners. The Stream needs a stable per-validator key.
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
Chunkerand 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
Chunkerobject itself (from refactor: replace stream_with_chunking with single-task stream() #1440) is unchanged — only its owner and multiplicity move. The state division (Streamer ownsaccumulated; Chunker owns pending fragment) also carries over unchanged.
Activity
ajbozarth commentedon Aug 6, 2026
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
ChunkertoRequirementwe'll be adding it. TheStreamerwill still have the option to set its own clunker that determines the chunks its iterations return. In additionRequirementwill now ALSO have aChunkerthat 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
Requirementbut instead be duplicated therefeat: add per-requirement chunking for streaming validation
feat: add per-requirement chunking for streaming validation
feat: add per-requirement chunking for streaming validation
feat: add per-requirement chunking for streaming validation
feat: add per-requirement chunking for streaming validation
feat: add per-requirement chunking for streaming validation (generati…