Skip to content

fix(session): handle type validation errors gracefully#33645

Open
Haohao-end wants to merge 1 commit into
anomalyco:devfrom
Haohao-end:mcp-message-validation
Open

fix(session): handle type validation errors gracefully#33645
Haohao-end wants to merge 1 commit into
anomalyco:devfrom
Haohao-end:mcp-message-validation

Conversation

@Haohao-end

Copy link
Copy Markdown

Issue for this PR

Closes #31324

Type of change

  • Bug fix

What does this PR do?

When the AI SDK receives a non-standard response chunk (e.g. from MCP-related tool calls), it emits a TypeValidationError (name: "AI_TypeValidationError"). The previous code called Effect.fail(event.error) which crashed the stream, leaving the assistant message in a broken state.

Two changes:

  1. ai-sdk.ts: TypeValidationError errors are now converted to LLMEvent.providerError events instead of failing the stream. Other error types (e.g. APICallError) still use Effect.fail so retry/classification logic is unaffected.

  2. processor.ts: The provider-error handler now checks the retryable flag. Retryable errors still throw to trigger the retry policy. Non-retryable errors call halt() which flushes partial fragments, sets the error on the assistant message, publishes the error event, and sets session status to idle — the same graceful shutdown path used for other terminal errors.

How did you verify your code works?

  • bun typecheck — passes
  • bun test test/session/ — 362 pass, 0 fail
  • All 15 processor-effect.test.ts tests pass (including retry, context-overflow, and error-classification tests)
  • All 26 llm.test.ts tests pass

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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.

Message structure breaks when asking MCP-related questions (Type validation error)

1 participant