Skip to content

fix(cache): include model identity in structured-output cache key (#334)#336

Merged
voorhs merged 1 commit into
devfrom
fix/issue-334-structured-output-cache-key
Jun 22, 2026
Merged

fix(cache): include model identity in structured-output cache key (#334)#336
voorhs merged 1 commit into
devfrom
fix/issue-334-structured-output-cache-key

Conversation

@voorhs

@voorhs voorhs commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #334. StructuredOutputCache built its cache key only from request content (messages + output schema + generation_params), omitting model identity. Two Generators with different model_name/base_url but identical prompt/schema/params collided — the second model was silently served the first model's cached output and made no API call. This corrupted any experiment comparing/ensembling multiple LLMs on the same prompts (a normal online-case bug, high severity).

  • Thread model_name and base_url into the hashed key across all four get/set/get_async/set_async paths and _get_cache_key.
  • Generator passes its existing self.model_name/self.base_url.
  • No backward-compat shim: changing the key naturally invalidates old (potentially wrong) entries.

Test plan

  • New regression tests in tests/generation/structured_output/test_cache_unit.py: different model_name and different base_url do not collide (sync + async); same identity still hits the cache.
  • Verified fail→pass via standalone snippet (network-free, no model loads); ruff + mypy clean.
  • CI runs the full suite.

🤖 Generated with Claude Code

Two Generator instances with different model_name or base_url but
identical messages/output_model/generation_params produced the same
cache key, causing the second model to silently receive the first
model's cached result without making an API call.

Fix: add model_name (str) and base_url (str | None) to _get_cache_key
and propagate them through get/set/get_async/set_async so each
(model, endpoint, request) triple maps to a distinct key.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@voorhs voorhs merged commit a855ef0 into dev Jun 22, 2026
19 checks passed
@voorhs voorhs deleted the fix/issue-334-structured-output-cache-key branch June 22, 2026 09:36
@voorhs voorhs mentioned this pull request Jun 22, 2026
3 tasks
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.

StructuredOutputCache key omits model identity → different models return each other's cached outputs

1 participant