Skip to content

Add bounded, validated Messages streaming and tool scheduling #313

Open

Description

@franciscojavierarceo

Problem statement / motivation

Enterprise deployments need predictable memory use and explicit completion semantics for Messages requests that execute built-in tools. Extend the existing native Messages loop with a documented lifecycle and resource contract across all inference rounds.

Proposed solution

  • Validate message and content-block transitions through one Messages ingestion path, keeping transport framing and client delivery separate from semantic validation.
  • Bound retained text, thinking, signatures, tool arguments, tool call outputs, pending calls, and reconstructed history. Distinguish retained bytes from wire bytes so smaller deltas do not consume disproportionate response capacity.
  • Reuse bounded scheduling contracts for built-in tools, with defined timeout, overload, disconnect, cancellation, and task-cleanup behavior.
  • Preserve native Messages content, client-executed function tools, rebased indexes, and one public message lifecycle.

Acceptance criteria

  • Invalid ordering, duplicate indexes/completions, missing identifiers, malformed event data, and open blocks at termination have explicit tested outcomes.
  • Premature EOF cannot dispatch an incomplete tool call or become an apparently successful message. Document any intentional engine-specific tolerance; retain forward compatibility for harmless unknown events.
  • Limits cover accumulated content and pending work across rounds, with deterministic errors and bounded resource release.
  • Tests cover fragmented UTF-8/SSE, many small deltas, large arguments/outputs, slow readers, disconnects during inference/tools, and round-limit exhaustion.
  • Preserve the message_stop completion and forced-tool-choice behavior shipped in fix: finish Messages rounds at message_stop #290 and fix: let Messages answer after forced tool use #296.

Additional context

Enterprise Readiness enhancement. Coordinate with #241/#244 and #288 for shared boundary and budget contracts; this issue owns Messages behavior. No worker-placement change is required without measurements.

Source review at afa6c14, not a new runtime reproduction: Messages streaming and Messages JSON loop.

Enterprise Readiness tracker: #316

Activity

  1. added
    enhancement
    enterprise-readiness
    on Sep 15, 2026
  2. justrightnow commented on Nov 20, 2026

    @justrightnow
    Contributor

    Progress update for #313 ("bounded, validated Messages streaming and tool scheduling"):

    PR #576 (#576) fixes a telemetry inconsistency on the premature-EOF path. When an upstream stream ends cleanly without message_stop, the client already receives an error frame and no successful terminal — but the agentic.execute span was being marked completed. The span outcome is now derived from the same completed-round gate finish() uses, so a clean EOF is recorded as failed with error.type=stream, matching what the client sees. No change to client frames or tool dispatch; the intentional max_tokens mid-call tolerance from #345 is preserved.

    This is a scoped step, not a full close of #313: the broader accumulated-content / pending-call limits across rounds remain.

    Verification: fmt + clippy (-D warnings) clean; Messages stream trace tests (5, incl. a new clean-EOF case) and the full 29-case stream suite pass; full workspace suite passes except two pre-existing 502/504 environment tests.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancemententerprise-readiness

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions