Skip to content

fix: validate Messages block payloads before assembly - #411

Merged
tjtanaa merged 5 commits into
mainfrom
codex/messages-block-payloads
Oct 8, 2026
Merged

tjtanaa merged 5 commits into
mainfrom
codex/messages-block-payloads

Conversation

@franciscojavierarceo

@franciscojavierarceo franciscojavierarceo commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Malformed Messages content could reach assembly or tool execution: a numeric block payload panicked on a later thinking delta, and missing or non-string delta fragments were silently discarded while the round continued.

Validate block starts and deltas in the existing synchronous ingestion path before buffering or client delivery. Payloads must be objects with non-empty string type fields. Known text, thinking, signature, and input-JSON deltas must carry string fragments. For known block types, the delta must match its block: text with text, thinking/signature with thinking, and input JSON with tool use. Tool-use IDs must also be unique within each upstream round, across built-in and client-executed tools. Invalid payloads return a fixed api_error and stop the round before further tool dispatch.

Empty string fragments and named extension types remain accepted, consistent with the streaming contract. Part of #313 and Enterprise Readiness #316. Full per-kind schema validation and retained-resource limits remain open. No new parser, task, or channel.

Test Plan

  • Reproduced the original numeric-block panic, a malformed delta reaching search dispatch, and an incompatible delta reaching dispatch before the respective fixes.
  • 80 malformed cases across both recorded inference rounds cover missing/null/scalar/array payloads, invalid type fields, and missing/non-string fragments for all four known delta kinds, plus all incompatible known block/delta combinations. Verify one error, no successful terminal, and no subsequent tool dispatch.
  • Controls accept named extension blocks/deltas and empty string fragments across both rounds while preserving one public lifecycle. Exact emitted extension start/delta/text/stop sequences verify opaque payload fidelity and shared rebased indexes.
  • Duplicate-ID regression reproduced two searches with the same call ID; four built-in/mixed cases across initial and later rounds now reject before dispatch. A unit control verifies ID tracking resets each round.
  • Core library: 1016 passed, 5 ignored. Messages streaming integration: 26 passed.
  • Workspace all-target Clippy with warnings denied, formatting, diff check, and all-files pre-commit passed.
  • Existing recordings and deterministic local servers; no live inference or cassette changes.

Latest test-only review update: reran all 26 Messages stream tests, all-target Clippy, and all-files pre-commit. Production code is unchanged.

@franciscojavierarceo
franciscojavierarceo force-pushed the codex/messages-block-payloads branch from aeacba8 to 3ee1e2d Compare October 3, 2026 00:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The scoped validation changes have targeted regression coverage and no unresolved blocking findings.

Review effort: Balanced
Findings: None

What changed in this PR

Hardens Messages streaming validation before assembly or tool dispatch, advancing the lifecycle safeguards tracked in #313.

Changes:

  • Validates block payloads, known delta fragments, and block/delta compatibility.
  • Rejects duplicate tool-use IDs within each upstream round.
  • Adds regression coverage and documents preserved extension compatibility.
File Description
docs/​design/​claude-code-integration.md Documents validation rules and compatibility.
crates/​agentic-server-core/​tests/​messages_stream_test.rs Tests malformed payloads, duplicate IDs, and valid controls.
crates/​agentic-server-core/​src/​executor/​messages_stream/​ingestion.rs Validates payloads and tool IDs before assembly.
crates/​agentic-server-core/​src/​executor/​messages_stream.rs Tracks and resets per-round tool IDs.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

)
})
.collect();
assert_messages_stream_presents_one_message(streams).await;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: could we assert that the injected extension payloads actually reach the client, in addition to checking that the request completes?
assert_messages_stream_presents_one_message() checks the upstream rounds, gateway-tool success, terminal events, and contiguous block indices, but it does not inspect the future_block / future_delta payloads. A regression that silently drops future_delta or changes its opaque extension field could still pass this test.
Please assert the expected extension start/delta/stop events in the emitted SSE, allowing for index rebasing, and check that the injected text_delta references the same client-visible block. This should be possible with the existing mock/cassette setup.

@tjtanaa
tjtanaa merged commit a606214 into main Oct 8, 2026
20 checks passed
avinashsingh77 pushed a commit to avinashsingh77/agentic-api that referenced this pull request Oct 8, 2026
## Summary

Malformed Messages content could reach assembly or tool execution: a
numeric block payload panicked on a later thinking delta, and missing or
non-string delta fragments were silently discarded while the round
continued.

Validate block starts and deltas in the existing synchronous ingestion
path before buffering or client delivery. Payloads must be objects with
non-empty string `type` fields. Known text, thinking, signature, and
input-JSON deltas must carry string fragments. For known block types,
the delta must match its block: text with text, thinking/signature with
thinking, and input JSON with tool use. Tool-use IDs must also be unique
within each upstream round, across built-in and client-executed tools.
Invalid payloads return a fixed `api_error` and stop the round before
further tool dispatch.

Empty string fragments and named extension types remain accepted,
consistent with the [streaming
contract](https://platform.claude.com/docs/en/build-with-claude/streaming).
Part of vllm-project#313 and Enterprise Readiness vllm-project#316. Full per-kind schema
validation and retained-resource limits remain open. No new parser,
task, or channel.

## Test Plan

- Reproduced the original numeric-block panic, a malformed delta
reaching search dispatch, and an incompatible delta reaching dispatch
before the respective fixes.
- 80 malformed cases across both recorded inference rounds cover
missing/null/scalar/array payloads, invalid type fields, and
missing/non-string fragments for all four known delta kinds, plus all
incompatible known block/delta combinations. Verify one error, no
successful terminal, and no subsequent tool dispatch.
- Controls accept named extension blocks/deltas and empty string
fragments across both rounds while preserving one public lifecycle.
Exact emitted extension start/delta/text/stop sequences verify opaque
payload fidelity and shared rebased indexes.
- Duplicate-ID regression reproduced two searches with the same call ID;
four built-in/mixed cases across initial and later rounds now reject
before dispatch. A unit control verifies ID tracking resets each round.
- Core library: 1016 passed, 5 ignored. Messages streaming integration:
26 passed.
- Workspace all-target Clippy with warnings denied, formatting, diff
check, and all-files pre-commit passed.
- Existing recordings and deterministic local servers; no live inference
or cassette changes.

Latest test-only review update: reran all 26 Messages stream tests,
all-target Clippy, and all-files pre-commit. Production code is
unchanged.

---------

Signed-off-by: Francisco Javier Arceo <[email protected]>
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.

3 participants