Skip to content

feat(core): add stream_validate() to Requirement #900

Closed

Description

@planetf1

What

Add stream_validate() to the Requirement class in mellea/core/requirement.py (class at line 104):

async def stream_validate(
    self, backend, ctx, chunk: str
) -> PartialValidationResult:
    return PartialValidationResult(success="unknown")

Why

validate() (line 143) operates on complete output. Streaming validation needs per-chunk processing with different semantics: incremental input, tri-state result, and stateful accumulation across calls within a single attempt.

The method is named stream_validate, not avalidate. In mellea, the a-prefix means "async version of the same operation" — this is a different operation and should be clearly distinct.

In Phase 1, requirements receive chunks as plain strings passed by the streaming orchestrator. They never touch the MOT stream directly. Stateful requirements maintain their own incremental state across stream_validate calls (e.g. a running counter, an incremental parser). The streaming orchestrator clones each requirement (copy(req)) before every attempt, so streaming state is isolated to the clone and the original is never mutated.

The default is safe for all existing requirements. ALoraRequirement and LLMaJRequirement need no changes — they return "unknown" on every chunk and receive the full output via validate() at stream end.

Returning "pass" from stream_validate() does not short-circuit final validation in Phase 1. The orchestrator always calls validate() at stream end for any requirement that did not return "fail" — "pass" mid-stream is informational only.

Acceptance criteria

  • stream_validate(self, backend, ctx, chunk: str) -> PartialValidationResult exists on Requirement with the default returning PartialValidationResult(success="unknown")
  • ALoraRequirement and LLMaJRequirement work correctly with the default — no override required
  • Unit tests in test/core/:
    • Default stream_validate returns "unknown" for any chunk
    • A stateful subclass (e.g. counts bullet points) accumulates state correctly across multiple stream_validate calls
    • The same subclass starts from a clean state on a fresh clone — confirms orchestrator clone pattern works
  • Google-style docstring on stream_validate() stating: (a) default returns "unknown"; (b) returning "pass" is informational in Phase 1 and does not skip final validate(); (c) implementations may accumulate state on self — the orchestrator clones the requirement before each attempt so state does not bleed across retries; (d) mutable container fields should be reassigned not mutated in place to be safe under shallow copy

Blocked by #898
Part of #891

Activity

  1. added
    enhancement
    on Apr 22, 2026
  2. self-assigned this
    on Apr 22, 2026
  3. added this to the Release 0.5.0 milestone on Apr 22, 2026
  4. changed the title [-]feat(core): add stream_validate() and reset() to Requirement[/-] [+]feat(core): add stream_validate() to Requirement[/+] on Apr 24, 2026
  5. planetf1 commented on Apr 24, 2026

    @planetf1
    ContributorAuthor

    Clarification: no reset() in Phase 1. The title previously mentioned reset() — this has been removed. State isolation is handled entirely by the orchestrator cloning requirements (copy(req)) before each attempt, consistent with how validate() already works at requirement.py:178. No lifecycle hook needed.

    The docstring on stream_validate() should note the shallow-copy caveat: mutable container fields (e.g. self._buffer = []) are shared by reference under copy(). Implementations should reassign (self._buffer = self._buffer + [chunk]) rather than mutate in place (self._buffer.append(chunk)), or override __copy__ for proper isolation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions