fix: include provider in cache key for uniqueness - #947
Conversation
Include the 'provider' field in the cache payload object to store the used provider information. This enhancement improves caching granularity and traceability in the chat module. Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
WalkthroughThe chat OpenAPI caching logic in apps/gateway/src/chat/chat.ts now includes the provider (usedProvider) in the cache payload alongside model, messages, and other fields, altering the cache key composition to distinguish cached responses by provider. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Client
participant G as Gateway Chat
participant K as Cache
participant P as LLM Provider
Note over G: Build cachePayload now includes provider
C->>G: Chat request (messages, model, provider)
G->>K: Get(cache key: model + messages + provider + ...)
alt Cache hit
K-->>G: Cached response
G-->>C: Return cached response
else Cache miss
G->>P: Forward request (provider-specific)
P-->>G: Response/stream
G->>K: Set(cache key incl. provider, response)
G-->>C: Return response
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (4)**/*.{ts,tsx}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
apps/{api,gateway}/**/*.ts📄 CodeRabbit inference engine (CLAUDE.md)
|
❌ Preview Environment deleted from BunnyshellAvailable commands (reply to this comment):
|
Summary
providerfield in the cache payloadChanges
Core Functionality
provider: usedProviderto the cache payload inapps/gateway/src/chat/chat.tsto ensure cache keys are unique across different providersTest plan
🌿 Generated by Terry
ℹ️ Tag @terragon-labs to ask questions and address PR feedback
📎 Task: https://www.terragonlabs.com/task/c20ebd4e-8179-41c6-818c-3cbaa6ab4976
Summary by CodeRabbit