Skip to content

fix(nim): NVIDIA NIM provider hardening and response normalization#27830

Open
Zireael wants to merge 2 commits into
anomalyco:devfrom
Zireael:feat/nim-provider-hardening
Open

fix(nim): NVIDIA NIM provider hardening and response normalization#27830
Zireael wants to merge 2 commits into
anomalyco:devfrom
Zireael:feat/nim-provider-hardening

Conversation

@Zireael
Copy link
Copy Markdown

@Zireael Zireael commented May 16, 2026

Issue for this PR

Closes #10884, #6290, #19947, #25786, #13900, #24264, #22493

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

NVIDIA NIM returns OpenAI-incompatible responses in several ways that crash agent sessions: numeric or missing tool_call.id, malformed JSON arguments, thinking tokens leaking into message content, and HTTP 200 payloads that look like errors but pass through as valid responses. Reasoning models like DeepSeek V4 also hang without chat_template_kwargs in the right place.

This adds a defense layer in the provider fetch pipeline that fixes these at the transport level. It works in three parts: normalize outgoing requests (inject kwargs, fix model IDs), normalize incoming responses (fix IDs, repair JSON, strip thinking leakage), and retry transient failures (HTTP 429, 5xx, HTTP 200 errors).

The normalization intercept runs after the raw HTTP response comes back but before the AI SDK validates it. Response reconstruction preserves original headers. Streaming passes through untouched.

How did you verify your code works?

58 unit tests cover the normalizer, JSON repair, request enrichment, and retry wrapper. The full provider test suite passes (393/394, one pre-existing timeout in unrelated plugin config tests). Typecheck is clean.

Screenshots / recordings

Not a UI change.

Checklist

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

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label May 16, 2026
@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Related PRs Found

Here are PRs addressing overlapping issues that PR #27830 consolidates:

  1. fix(provider): inject chat_template_kwargs for Nvidia NIM deepseek-v4 models #24262 - fix(provider): inject chat_template_kwargs for Nvidia NIM deepseek-v4 models

  2. fix(provider): coerce numeric tool call IDs for OpenAI-compatible providers #24026 - fix(provider): coerce numeric tool call IDs for OpenAI-compatible providers

    • Handles numeric tool_call.id coercion (part of Ring 2 response normalization)
  3. fix: generate fallback tool call IDs for providers missing id field #12585 - fix: generate fallback tool call IDs for providers missing id field

  4. fix(provider): propagate options.extraBody for openai-compatible providers #26233 - fix(provider): propagate options.extraBody for openai-compatible providers

    • Related to request body enrichment for NIM providers

Note: PR #27830 appears to be a comprehensive consolidation that addresses all these issues in a unified defense layer (nim-defense.ts). These older PRs may be superseded or complementary to the current PR's approach.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label May 16, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@Zireael Zireael force-pushed the feat/nim-provider-hardening branch from a5be9f0 to 1829ec4 Compare May 16, 2026 06:45
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.

[FEATURE]: Add Support for MCP Apps in the desktop app

1 participant