Skip to content

fix: handle output-error parts to prevent session poisoning - #697

Merged
lixun910 merged 1 commit into
mainfrom
xli-fix-handle-output-error-part
Jun 8, 2026
Merged

lixun910 merged 1 commit into
mainfrom
xli-fix-handle-output-error-part

Conversation

@lixun910

@lixun910 lixun910 commented Jun 8, 2026 •

Copy link
Copy Markdown
Collaborator

sqlrooms/ai-core: Updated the handling of output-error tool parts to ensure that incomplete or invalid inputs are cleared, preventing schema validation errors in subsequent sends. The original input is preserved under rawInput, allowing the AI SDK to skip validation and maintain session integrity.

This will avoid "stop" and then continue prompting throws incomplete message parts error.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Enhanced error handling for incomplete tool calls to prevent malformed error states from contaminating message validation pipelines and ensure system stability.
  • Tests

    • Added comprehensive test suite covering tool call error handling across multiple scenarios, including partial data streams and error state edge cases.

@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8ea994c2-4090-4b3b-8fea-fadf9e8aa5f4

📥 Commits

Reviewing files that changed from the base of the PR and between a38155a and cc0becc.

📒 Files selected for processing (2)
  • packages/ai-core/__tests__/fixIncompleteToolCalls.test.ts
  • packages/ai-core/src/utils.ts

📝 Walkthrough

Walkthrough

This PR fixes incomplete tool-call handling in the AI core utils by preventing malformed output-error tool parts from failing downstream validation. The implementation clears partial input and stores it in rawInput, with a comprehensive test suite validating the behavior across multiple tool-call states and types.

Changes

Incomplete Tool Call Error Handling

Layer / File(s) Summary
Output-error input normalization
packages/ai-core/src/utils.ts
Documentation specifies that partial input in output-error tool parts must be moved to rawInput with input set to undefined. The fixIncompleteToolCalls function is reworked to clear input when present while preserving partial data in rawInput, replacing the prior backfill approach.
Test suite for tool call error normalization
packages/ai-core/__tests__/fixIncompleteToolCalls.test.ts
New test suite covers: cancelled output-error tool-query with partial input cleared and moved to rawInput, preservation of existing rawInput fields, conversion of incomplete input-streaming tool calls to output-error with input normalization, verification that completed output-available parts remain unchanged, and the same normalization applied to dynamic-tool parts with tool identity fields preserved.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • sqlrooms/sqlrooms#679: Modifies the same fixIncompleteToolCalls normalization logic in utils.ts for tool output-error parts using input/rawInput/errorText fields.

Suggested reviewers

  • mihajlo-stojkovic
  • ilyabo

Poem

🐰 Hop, hop! Tool calls were incomplete,
Their partial inputs, oh what a feat!
We moved them to rawInput with care,
And left input undefined—validation's fair!
Tests now bound to catch each case,
Errors handled with grace. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: fixing the handling of output-error tool parts to prevent session poisoning, which matches the core objective of clearing invalid inputs and preserving them under rawInput.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch xli-fix-handle-output-error-part

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@lixun910
lixun910 requested a review from ilyabo June 8, 2026 02:09
@lixun910
lixun910 merged commit 48249d3 into main Jun 8, 2026
5 checks passed
@lixun910
lixun910 deleted the xli-fix-handle-output-error-part branch June 8, 2026 17:21
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.

2 participants