| 399 | std::pair<int, int> PrefixCache::lookup_impl( |
| 400 | const std::vector<int32_t> & prompt_ids, |
| 401 | int max_prefix_tokens, |
| 402 | bool record_hit) { |
| 403 | if (disabled_ || max_prefix_tokens <= 0) return {-1, 0}; |
| 404 | |
| 405 | auto boundaries = find_all_boundaries(prompt_ids, markers_); |
| 406 | int best_slot = -1, best_len = 0; |
| 407 | int best_idx = -1; |
| 408 | |
| 409 | for (int cut : boundaries) { |
| 410 | if (cut > max_prefix_tokens) continue; |
| 411 | auto key = hash_prefix(prompt_ids.data(), cut); |
| 412 | int idx = find_entry(key); |
| 413 | if (idx >= 0) { |
| 414 | const int committed = (int)entries_[idx].ids.size(); |
| 415 | if (committed != cut) { |
| 416 | // Slot was refreshed in-place at a deeper boundary; a shallow |
| 417 | // hash→slot entry would restore the wrong cur_pos. |
| 418 | std::fprintf(stderr, |
| 419 | "[pc] lookup stale slot=%d key_cut=%d committed=%d — evicting\n", |
| 420 | entries_[idx].slot, cut, committed); |
| 421 | erase_inline_entry(idx); |
| 422 | continue; |
| 423 | } |
no test coverage detected