fix: skip system messages in OpenRouter cacheAtDepth calculation (#5230) System messages in the OpenRouter messages array were being counted toward depth and could receive cache_control breakpoints. Since OpenRouter hoists system messages into Claude's separate system parameter, this misplaced breakpoints and could prevent caching entirely if the hoisted content fell below minimum cache size. Closes #5227

15e2f240464d115368eeb01317b4a67ce64e8220

Tony Gies <tgies@tgies.net>

Signed
1 files changed, +5 -0Showing whitespace changes
src/prompt-converters.js+5 -0
@@ -1026,6 +1026,11 @@ export function cachingAtDepthForOpenRouterClaude(messages, cachingAtDepth, ttl)
10261026
1027 passedThePrefill = true;1027 passedThePrefill = true;
10281028
1029 // Skip system messages so they don't affect depth counting or receive cache breakpoints
1030 if (messages[i].role === 'system') {
1031 continue;
1032 }
1033
1029 if (messages[i].role !== previousRoleName) {1034 if (messages[i].role !== previousRoleName) {
1030 if (depth === cachingAtDepth || depth === cachingAtDepth + 2) {1035 if (depth === cachingAtDepth || depth === cachingAtDepth + 2) {
1031 const content = messages[i].content;1036 const content = messages[i].content;