fix(ai-openrouter): stop forwarding root observability metadata to the wire request#737
Conversation
…e wire request The OpenRouter chat-completions adapter (since 0.13.0) and responses adapter (since 0.9.0) copied chat()'s root-level observability metadata onto the wire as chatRequest.metadata / responsesRequest.metadata. The @openrouter/sdk validates those fields as Record<string, string>, so structured observability metadata (objects, arrays — the documented usage for middleware/devtools consumers) failed client-side Zod validation with "Input validation failed" on every call. The spread also clobbered an intentional, correctly-typed modelOptions.metadata. Root metadata is observability-only again (middleware, devtools, event client) and modelOptions.metadata is the sole source for OpenRouter wire metadata, matching every other adapter. The TextOptions.metadata doc comment now states this contract explicitly. Fixes #735 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughStops forwarding root-level observability ChangesStop Forwarding Root Observability Metadata to OpenRouter Wire
🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers:
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
🚀 Changeset Version Preview5 package(s) bumped directly, 26 bumped as dependents. 🟥 Major bumps
🟨 Minor bumps
🟩 Patch bumps
|
|
View your CI Pipeline Execution ↗ for commit fc581b0
☁️ Nx Cloud last updated this comment at |
@tanstack/ai
@tanstack/ai-anthropic
@tanstack/ai-client
@tanstack/ai-code-mode
@tanstack/ai-code-mode-skills
@tanstack/ai-devtools-core
@tanstack/ai-elevenlabs
@tanstack/ai-event-client
@tanstack/ai-fal
@tanstack/ai-gemini
@tanstack/ai-grok
@tanstack/ai-groq
@tanstack/ai-isolate-cloudflare
@tanstack/ai-isolate-node
@tanstack/ai-isolate-quickjs
@tanstack/ai-mcp
@tanstack/ai-ollama
@tanstack/ai-openai
@tanstack/ai-openrouter
@tanstack/ai-preact
@tanstack/ai-react
@tanstack/ai-react-ui
@tanstack/ai-solid
@tanstack/ai-solid-ui
@tanstack/ai-svelte
@tanstack/ai-utils
@tanstack/ai-vue
@tanstack/ai-vue-ui
@tanstack/openai-base
@tanstack/preact-ai-devtools
@tanstack/react-ai-devtools
@tanstack/solid-ai-devtools
commit: |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/ai-openrouter/tests/openrouter-responses-adapter.test.ts`:
- Line 6: The type-only import OpenRouterResponsesTextProviderOptions is out of
order and violates import/order; move the "import type {
OpenRouterResponsesTextProviderOptions }" line so it matches the repository's
import grouping (e.g., third-party imports first, then internal modules, then
type-only or side-effect imports) or group it with the other local/type imports
in the test file to satisfy the linter; alternatively run eslint --fix to
reorder automatically.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 44df3767-c300-483f-a1b5-f377e80d518c
📒 Files selected for processing (8)
.changeset/root-metadata-not-forwarded.mdpackages/ai-openrouter/src/adapters/responses-text.tspackages/ai-openrouter/src/adapters/text.tspackages/ai-openrouter/tests/openrouter-adapter.test.tspackages/ai-openrouter/tests/openrouter-responses-adapter.test.tspackages/ai/src/types.tstesting/e2e/src/routes/api.chat.tstesting/e2e/tests/root-metadata-wire.spec.ts
…view
modelOptions accepts { metadata } directly in the responses test, so the
OpenRouterResponsesTextProviderOptions assertion (and its out-of-order
type import, flagged by CodeRabbit) are unnecessary.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
🎯 Changes
Fixes #735.
The OpenRouter chat-completions adapter (since 0.13.0, via #660) and responses adapter (since 0.9.0, via #545) copied
chat()'s root-level observabilitymetadataonto the wire aschatRequest.metadata/responsesRequest.metadata. The@openrouter/sdkvalidates those fields asRecord<string, string>, so structured observability metadata (objects, arrays — the documented usage for middleware/devtools/event-client consumers) failed client-side Zod validation withInput validation failedon every call. The spread also sat after...modelOptions, clobbering an intentional, correctly-typedmodelOptions.metadata.metadataforwarding from both adapters' request builders;modelOptions.metadatais the sole source for OpenRouter wire metadata, matching every other adapter.root-metadata-wire.spec.ts+ a test-onlystructuredRootMetadataflag inapi.chat.ts) that exercises the real SDK's outbound validation — verified to fail pre-fix with the exact error from the issue and pass post-fix.TextOptions.metadatadoc comment in@tanstack/aito state the observability-only contract.Observability consumers are unaffected: the event stream metadata is emitted by the
chat()orchestrator, not the adapter.✅ Checklist
pnpm run test:pr.🚀 Release Impact
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Documentation
Tests