Skip to content

fix: reject incomplete Messages tool-loop streams - #345

Draft
franciscojavierarceo wants to merge 1 commit into
mainfrom
codex/messages-stream-validation
Draft

franciscojavierarceo wants to merge 1 commit into
mainfrom
codex/messages-stream-validation

Conversation

@franciscojavierarceo

Copy link
Copy Markdown
Collaborator

Summary

Require an upstream message_stop before a Messages built-in tool round can dispatch calls or finish successfully. Previously, EOF after stop_reason: tool_use could execute a tool, and truncated text rounds received a synthetic successful completion. The existing accumulator now emits an Anthropic SSE api_error without terminal message_delta or message_stop when the upstream ends early, including via [DONE].

Part of #313 and Enterprise Readiness #316. This is the completion gate only: full content-block lifecycle validation, aggregate retained-data budgets, and bounded tool scheduling remain open. Valid message_stop still ends a round without waiting for HTTP EOF; named-tool compatibility, pass-through requests, and upstream error forwarding retain their behavior.

Test Plan

  • Reproduced the premature-success failure with the new regression test on the original implementation.
  • Core library: 753 passed, 5 ignored. Messages stream integration suite: 8 passed, including ten incomplete-stream scenarios covering text/tool rounds, absent/present terminal deltas, EOF/[DONE], empty bodies, and an incomplete round after successful tool execution. Assertions count actual search calls and upstream requests.
  • HTTP Messages completion suite: 12 passed, including terminal-before-EOF behavior and fragmented UTF-8. HTTP tool-choice suite: 13 passed.
  • Workspace all-target clippy with warnings denied, all-files pre-commit hooks, formatting, and diff checks passed.
  • Tests use local deterministic servers and existing cassette replay; no live inference engine was run. Linux builds used an existing local static OpenSSL installation.

Signed-off-by: Francisco Javier Arceo <arceofrancisco@gmail.com>
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.

1 participant