Skip to content

fix: respect caching: false on wrapAISDKModel#396

Open
Sraleik wants to merge 1 commit into
mattpocock:v1from
Sraleik:fix/wrap-aisdk-respect-caching-flag
Open

fix: respect caching: false on wrapAISDKModel#396
Sraleik wants to merge 1 commit into
mattpocock:v1from
Sraleik:fix/wrap-aisdk-respect-caching-flag

Conversation

@Sraleik
Copy link
Copy Markdown

@Sraleik Sraleik commented May 7, 2026

What

Fix the caching: false option on wrapAISDKModel, which was silently ignored.

Closes #395.

Why

wrapAISDKModel(model, { caching: false }) reads the flag at the top of the function but never checks it inside the wrapper. The cache fetch and store paths are gated only on if (cacheContext), so as long as tracing is enabled (default), the cache is read and written regardless of what the user passed.

This is misleading: the API suggests opt-out is supported, but the only way to truly bypass the cache today is to also disable tracing (which makes wrapAISDKModel short-circuit and return the unwrapped model). Users running cross-model baselines or measuring sampling variability across trialCount > 1 silently get cached responses.

Change

Four sites in packages/evalite/src/ai-sdk.ts — two in wrapGenerate, two in wrapStream:

-if (cacheContext) {
+if (cacheContext && enableCaching) {

The early-return if (!enableCaching && !enableTracing) return model; is unchanged. Tracing path is untouched. When caching: true (default), behavior is identical to before.

Tests

  • All four existing ai-sdk-caching.test.ts tests still pass.
  • New test added: Should respect caching: false on wrapAISDKModel even when global cache is enabled.
  • New fixture: packages/evalite-tests/tests/fixtures/ai-sdk-caching-local-disabled/ — same shape as ai-sdk-caching but wraps both task and scorer models with { caching: false }. Asserts that two consecutive runs produce zero [CACHE] log lines, demonstrating that neither cache fetch nor store happened.
✓ tests/ai-sdk-caching.test.ts (5 tests) 2887ms
   ✓ Should cache AI SDK in the task and scorers
   ✓ Should disable cache when cacheEnabled is false
   ✓ Should respect cacheEnabled: false in config
   ✓ Should let runEvalite cacheEnabled override config cacheEnabled
   ✓ Should respect caching: false on wrapAISDKModel even when global cache is enabled

Changeset

patch bump for evalite. See .changeset/wrap-aisdk-respect-caching-flag.md.

Out of scope (mentioned for context)

The companion bug — that the CLI flag --no-cache and config cache: false only short-circuit the reportCacheHit callback in evalite.ts rather than skipping the cacheContextLocalStorage.enterWith() call — is not addressed here. That's a more invasive change touching evalite.ts + types, and I think it deserves its own PR. Happy to follow up if you'd like; flagged as a note in #395.

The local `caching` flag was being read at the top of `wrapAISDKModel`
but never checked inside `wrapGenerate`/`wrapStream`. The cache
fetch/store paths were gated only on the existence of `cacheContext`,
which made `caching: false` a silent no-op as long as tracing was
enabled (the default).

Add `&& enableCaching` to the four cache fetch/store guards in
ai-sdk.ts. Tracing path is unchanged.

Closes mattpocock#395

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 7, 2026

@Sraleik is attempting to deploy a commit to the Skill Recordings Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 7, 2026

🦋 Changeset detected

Latest commit: 8f2deed

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

1 participant