Skip to content

fix(ai-openrouter): keep root metadata out of requests#748

Open
slegarraga wants to merge 1 commit into
TanStack:mainfrom
slegarraga:slegarraga/fix-openrouter-root-metadata
Open

fix(ai-openrouter): keep root metadata out of requests#748
slegarraga wants to merge 1 commit into
TanStack:mainfrom
slegarraga:slegarraga/fix-openrouter-root-metadata

Conversation

@slegarraga

@slegarraga slegarraga commented Jun 11, 2026

Copy link
Copy Markdown

🎯 Changes

Fixes #735.

  • Stops forwarding root chat() metadata into OpenRouter chat-completions request metadata.
  • Keeps provider-native OpenRouter request metadata available through modelOptions.metadata.
  • Adds unit and E2E regression coverage for structured root observability metadata.

Test plan

  • corepack pnpm run build:all
  • corepack pnpm --filter @tanstack/ai-openrouter test:lib
  • corepack pnpm --filter @tanstack/ai-openrouter test:types
  • corepack pnpm --filter @tanstack/ai-openrouter test:eslint
  • corepack pnpm --filter @tanstack/ai-e2e exec playwright test tests/chat.spec.ts -g "openrouter root metadata"
  • corepack pnpm --filter @tanstack/ai-e2e build

Full pnpm run test:pr was not run locally.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes

    • Root chat metadata is now retained as observability context instead of being forwarded into the OpenRouter API request, improving metadata isolation.
  • New Features

    • Added support for structured root metadata in observability tracking for OpenRouter chat flows.
  • Tests

    • Added end-to-end tests to verify root metadata handling behavior.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e107f92d-12b7-43f7-b7aa-6ad3a114f0a6

📥 Commits

Reviewing files that changed from the base of the PR and between 984ac3c and 57cedc0.

📒 Files selected for processing (6)
  • .changeset/openrouter-root-metadata.md
  • packages/ai-openrouter/src/adapters/text.ts
  • packages/ai-openrouter/tests/openrouter-adapter.test.ts
  • testing/e2e/src/routes/$provider/$feature.tsx
  • testing/e2e/src/routes/api.chat.ts
  • testing/e2e/tests/chat.spec.ts

📝 Walkthrough

Walkthrough

This PR fixes a regression where OpenRouter's text adapter was forwarding root-level observability metadata to the wire request, causing validation failures on structured metadata. The fix removes the root metadata from the request body, restricts observability metadata to middleware/devtools consumers, and enables structured e2e tests to verify the corrected behavior.

Changes

OpenRouter root metadata observability fix

Layer / File(s) Summary
Adapter fix and unit test updates
packages/ai-openrouter/src/adapters/text.ts, packages/ai-openrouter/tests/openrouter-adapter.test.ts, .changeset/openrouter-root-metadata.md
mapOptionsToRequest no longer spreads options.metadata into the request body. Unit tests confirm root metadata is excluded from the SDK request while modelOptions.metadata is forwarded and validated through the Zod outbound schema. Changeset documents the patch release.
E2E test infrastructure setup
testing/e2e/src/routes/$provider/$feature.tsx, testing/e2e/src/routes/api.chat.ts
Route search validation parses a rootMetadata parameter, chat feature destructures and forwards it via useChat, and the API route constructs a structured observability metadata object and injects it into chat() calls across structured-output branches.
E2E test execution
testing/e2e/tests/chat.spec.ts
New Playwright test for OpenRouter verifies that structured root metadata flows correctly without validation errors.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • KevinVandy
  • tombeckenham

Poem

🐰 Metadata once climbed the wire in haste,
Failing Zod's Record<string, string> taste,
Now it stays home, where middleware may peek,
While modelOptions.metadata flows sleek—
Root observability finds its place!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(ai-openrouter): keep root metadata out of requests' directly and clearly describes the main change: preventing root-level metadata from being forwarded into OpenRouter requests.
Linked Issues check ✅ Passed The PR successfully addresses issue #735 by removing root metadata forwarding, preserving modelOptions.metadata, and adding comprehensive unit and e2e tests for structured root observability metadata.
Out of Scope Changes check ✅ Passed All changes are directly related to the stated objective: the adapter fix, changeset documentation, unit tests, and e2e test infrastructure changes are all within scope of fixing the metadata forwarding issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Tools execution failed with the following error:

Failed to run tools: 14 UNAVAILABLE: read ECONNRESET


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.

❤️ Share

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