Skip to content

Commit 57687ca

Browse files
committed
fix(ai-cache): guard log() against nil cache key fields on early-MISS
1 parent 6b996cd commit 57687ca

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

apisix/plugins/ai-cache.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ function _M.log(conf, ctx)
215215
return
216216
end
217217

218+
-- Early-MISS paths (body parse / protocol detect / hash failure) skip
219+
-- key computation, so bail out if cache key fields are absent.
220+
if not ctx.ai_cache_prompt_hash or not ctx.ai_cache_prompt_text then
221+
return
222+
end
223+
218224
local upstream_status = core.response.get_upstream_status(ctx) or ngx.status
219225
if not upstream_status or upstream_status < 200 or upstream_status >= 300 then
220226
return

0 commit comments

Comments
 (0)