Skip to content

fix: expose raw error messages and flatten tool schemas for OpenAI#1276

Merged
larryro merged 2 commits into
mainfrom
fix/chat-errors-and-tool-schema-middleware
Apr 10, 2026
Merged

fix: expose raw error messages and flatten tool schemas for OpenAI#1276
larryro merged 2 commits into
mainfrom
fix/chat-errors-and-tool-schema-middleware

Conversation

@larryro
Copy link
Copy Markdown
Collaborator

@larryro larryro commented Apr 10, 2026

Summary

Closes #1253
Closes #1254

Test plan

  • Verify chat error messages show both the i18n hint and the raw provider error
  • Verify agent tools with z.discriminatedUnion() schemas work correctly with OpenAI models (ChatGPT 5.2, 5.2 Pro, GPT-5.2 Instant)
  • Run sanitize-chat-error unit tests

Summary by CodeRabbit

  • Improvements
    • Chat error messages now display additional raw error details with improved formatting, including better text wrapping and visual hierarchy for secondary content.
    • Enhanced tool schema handling in language model resolution for improved compatibility and processing.

larryro added 2 commits April 10, 2026 09:51
Add rawMessage field to SanitizedError so the UI can display the
original provider error beneath the translated hint, giving users
more context when debugging failures.
…penAI

Work around vercel/ai#7924 where z.discriminatedUnion() produces
top-level oneOf schemas that OpenAI rejects. The middleware merges
variant schemas into a single flat object before sending to the API.
Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@larryro larryro merged commit 0db4c1c into main Apr 10, 2026
23 of 24 checks passed
@larryro larryro deleted the fix/chat-errors-and-tool-schema-middleware branch April 10, 2026 01:59
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 10, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The PR extends error handling across the chat feature by adding a rawMessage field to the SanitizedError type to preserve original error text. The message bubble component is updated to display both sanitized i18n translations and raw error messages with distinct styling. Corresponding tests for the sanitization utility are updated to validate the new field. Additionally, model resolution logic introduces middleware with a schema flattening helper that transforms JSON Schemas containing root-level oneOf/anyOf unions into flat object schemas by merging properties and computing intersection requirements.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR changes do not implement the linked issue #1187 requirements for displaying source citations inline after individual pieces of information. Review if issue #1187 requirements are actually in scope for this PR or if a separate issue should track citation display functionality.
Out of Scope Changes check ⚠️ Warning The PR includes changes to error message handling and tool schema flattening, which are unrelated to the source citations requirements stated in linked issue #1187. Clarify whether issue #1187 is correctly linked or if this PR addresses a different issue that was mislabeled.
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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the two main changes: exposing raw error messages in the chat UI and flattening tool schemas for OpenAI compatibility.

✏️ 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 fix/chat-errors-and-tool-schema-middleware

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

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

Labels

None yet

Projects

None yet

1 participant