fix: enable haiku 4.5 json - #1999
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughAdded Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
Enables reliable OpenAI-compatible response_format: { type: "json_object" } usage for Claude Haiku 4.5 by declaring the capability in model metadata and normalizing (“healing”) fenced/mixed JSON responses from Anthropic and AWS Bedrock before returning them to clients.
Changes:
- Mark Claude Haiku 4.5 (and its dated mapping) as supporting
json_objectviajsonOutput: true. - Auto-enable JSON response healing for Anthropic and AWS Bedrock when
response_format.type === "json_object"(streaming + non-streaming). - Replace the prior “unsupported JSON mode” e2e with a passing Haiku 4.5 JSON-mode assertion.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/models/src/models/anthropic.ts | Advertises json_object support for Haiku 4.5 provider mappings via jsonOutput: true. |
| apps/gateway/src/chat/chat.ts | Ensures JSON healing runs (and buffering occurs for streaming) for Anthropic/Bedrock json_object responses even without the plugin enabled. |
| apps/gateway/src/api-individual.e2e.ts | Updates e2e coverage to assert Haiku 4.5 json_object returns parseable JSON content. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| expect(() => JSON.parse(content)).not.toThrow(); | ||
| expect(JSON.parse(content)).toHaveProperty("message"); |
There was a problem hiding this comment.
The test parses the JSON content twice (JSON.parse(content) in both assertions). Parse once into an object and assert on that to avoid duplicated work and make failures easier to debug (single parse + single object under test).
| expect(() => JSON.parse(content)).not.toThrow(); | |
| expect(JSON.parse(content)).toHaveProperty("message"); | |
| const parsedContent = JSON.parse(content); | |
| expect(parsedContent).toBeDefined(); | |
| expect(parsedContent).toHaveProperty("message"); |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b213374dba
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| (usedProvider === "anthropic" && | ||
| response_format?.type === "json_object") || | ||
| (usedProvider === "aws-bedrock" && | ||
| response_format?.type === "json_object") || |
There was a problem hiding this comment.
Prevent early finish_reason in buffered JSON streams
Adding Anthropic and AWS Bedrock to shouldBufferForHealing routes response_format: {type:"json_object"} streams into the buffering path, but that path still forwards upstream chunks that contain finish_reason before the healed content is emitted at the end of the stream (see the existing send logic around choices[0].finish_reason and the later healed-content chunk write in chat.ts). For these providers, terminal events are normal, so clients that stop reading on the first non-null finish_reason can terminate before receiving any content, yielding empty/partial results specifically for streamed JSON-object requests.
Useful? React with 👍 / 👎.
Summary
response_format: { type: "json_object" }json_objectresponses so fenced JSON is normalized before returningVerification
pnpm exec vitest run packages/actions/src/prepare-request-body.spec.ts apps/gateway/src/chat/tools/heal-json-response.spec.ts --no-file-parallelismTEST_MODELS="anthropic/claude-haiku-4-5" pnpm test:e2e -- apps/gateway/src/chat-json.e2e.ts apps/gateway/src/api-individual.e2e.tspnpm buildSummary by CodeRabbit
New Features
Bug Fixes / Improvements