Skip to content

test(node): Cover Vercel AI v7 cache tokens from the SDK usage object - #24358

Merged
mydea merged 2 commits into
fix/vercel-ai-channel-cache-tokensfrom
feat/vercel-ai-cache-tokens-node-test
Sep 14, 2026
Merged

mydea merged 2 commits into
fix/vercel-ai-channel-cache-tokensfrom
feat/vercel-ai-cache-tokens-node-test

Conversation

@mydea

@mydea mydea commented Sep 14, 2026

Copy link
Copy Markdown
Member

Stacked on #24350. Adds an end-to-end node integration test that exercises the cache-token fix against the real ai@^7 package, not just the unit test in the base PR.

The scenario drives generateText through a mock model whose usage carries cache read/write counts in the v7 shape (inputTokens.{cacheRead,cacheWrite}) while providerMetadata is keyed gateway — the Vercel AI Gateway shape that has no provider-specific cache key. Without the base PR the channel subscriber drops these counts; the test asserts they land on both the generate_content and invoke_agent spans. It's skipped on v6, whose OTel-processor path derives cache counts from providerMetadata alone and can't see the gateway case.

🤖 Generated with Claude Code

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 58c1aaa. Configure here.

})
.start()
.completed();
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cache token test not skipped on v6

Medium Severity

The new cache-token test is registered for both matrix versions, but v6 cannot derive cache counts from this gateway scenario. Nearby version-specific cases use test.skipIf, so the v6 entry will assert gen_ai.usage.input_tokens.cache_read and cache_creation values that that path never writes.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 58c1aaa. Configure here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this seems to work just fine

@github-actions

github-actions Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 28.96 kB - -
@sentry/browser - with treeshaking flags 27.26 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.15 kB - -
@sentry/browser (incl. Tracing) 50.51 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 50.52 kB - -
@sentry/browser (incl. Tracing, Profiling) 53.5 kB - -
@sentry/browser (incl. Tracing, Replay) 90.07 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 79.16 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 94.77 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 107.73 kB - -
@sentry/browser (incl. Feedback) 46.46 kB - -
@sentry/browser (incl. sendFeedback) 34.01 kB - -
@sentry/browser (incl. FeedbackAsync) 39.12 kB - -
@sentry/browser (incl. Metrics) 29.98 kB - -
@sentry/browser (incl. Logs) 30.24 kB - -
@sentry/browser (incl. Metrics & Logs) 30.91 kB - -
@sentry/react 30.72 kB - -
@sentry/react (incl. Tracing) 52.81 kB - -
@sentry/vue 36.2 kB - -
@sentry/vue (incl. Tracing) 52.76 kB - -
@sentry/svelte 28.98 kB - -
CDN Bundle 30.7 kB - -
CDN Bundle (incl. Tracing) 51.01 kB - -
CDN Bundle (incl. Logs, Metrics) 32.98 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 52.99 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.67 kB - -
CDN Bundle (incl. Tracing, Replay) 88.56 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 90.53 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 94.64 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 96.63 kB - -
CDN Bundle - uncompressed 90.83 kB - -
CDN Bundle (incl. Tracing) - uncompressed 152.33 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 97.41 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 158.29 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 226.82 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 271.9 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 277.85 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 285.6 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 291.54 kB - -
@sentry/nextjs (client) 55.13 kB - -
@sentry/sveltekit (client) 50.93 kB - -
@sentry/core/server 37.13 kB - -
@sentry/core/browser 13.66 kB - -
@sentry/node 129.93 kB +0.11% +130 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 81.83 kB - -
@sentry/node - without tracing 89.62 kB +0.04% +32 B 🔺
@sentry/node - without channel injection 108.82 kB +0.13% +141 B 🔺
@sentry/aws-serverless 97.83 kB +0.02% +18 B 🔺
@sentry/cloudflare (withSentry) - minified 203.36 kB - -
@sentry/cloudflare (withSentry) 506.44 kB - -

View base workflow run

@mydea
mydea marked this pull request as ready for review September 14, 2026 08:48
@mydea
mydea requested a review from a team as a code owner September 14, 2026 08:48
@mydea
mydea requested review from JPeer264, RulaKhaled, isaacs and sergical and removed request for a team September 14, 2026 08:48
Comment on lines +833 to +843
const invokeAgent = container.items.find(
span => span.attributes['sentry.op']?.value === 'gen_ai.invoke_agent',
)!;
expect(invokeAgent).toBeDefined();
expect(invokeAgent.attributes[GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS]?.value).toBe(80);
expect(invokeAgent.attributes[GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS]?.value).toBe(20);
},
})
.start()
.completed();
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: The test 'reads cache token counts from the SDK usage object' is missing a test.skipIf(version === '6') condition, causing it to fail for the v6 test matrix.
Severity: LOW

Suggested Fix

Wrap the test case 'reads cache token counts from the SDK usage object' with a skip condition to prevent it from running against v6. Use test.skipIf(version === '6') around the test definition, similar to other version-specific tests in the suite.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location:
dev-packages/node-integration-tests/suites/tracing/vercelai/v6_v7/test.ts#L820-L843

Potential issue: The integration test `'reads cache token counts from the SDK usage
object'` is intended to run for both v6 and v7 of the Vercel AI SDK. However, the test
is missing a required skip condition for v6. The test asserts that cache token counts
are derived from the SDK's usage object, a feature specific to v7. The v6 OTel
integration derives these counts from `providerMetadata` and cannot handle the `gateway`
provider metadata shape used in this test scenario. As a result, the test will
incorrectly execute and fail during CI runs for v6.

Did we get this right? 👍 / 👎 to inform future reviews.

mydea and others added 2 commits September 14, 2026 11:39
Add a node integration test that runs the real `ai@^7` package through the
channel subscriber with `providerMetadata` keyed `gateway` (the AI Gateway
shape), asserting cache read/write counts are still derived from the SDK's
normalized usage. Skipped on v6, whose OTel processor only reads
`providerMetadata`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mydea
mydea force-pushed the feat/vercel-ai-cache-tokens-node-test branch from 58c1aaa to 27897d2 Compare September 14, 2026 09:39
@mydea
mydea merged commit f63422b into develop Sep 14, 2026
50 of 79 checks passed
@mydea
mydea deleted the feat/vercel-ai-cache-tokens-node-test branch September 14, 2026 10:06
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.

2 participants