diff --git a/engine/src/program/generate.cpp b/engine/src/program/generate.cpp index cb4752323c8..b72b6875e44 100644 --- a/engine/src/program/generate.cpp +++ b/engine/src/program/generate.cpp @@ -19727,6 +19727,23 @@ int main(int argc, char** argv) { spill.size(), (unsigned long long) (spill.bytes() >> 20)); incoming.emplace(std::move(image)); taken = sp; // (the restore below resumes at the SSD entry's prefix, not at the RAM tier's) + // The entry's live state can be longer than this prompt (a fork reads a prefix of it): the + // resume then lands on the longest common prefix, which is no checkpoint's depth, and the + // admission below asked for a checkpoint of exactly that length and ended the engine with + // "ERR restoring a conversation checkpoint failed" (#7648). Resume at the deepest checkpoint + // at or below the prefix instead; with none, read the prompt from 0 rather than mount a state + // the request overwrites. + if (taken.live) { + int64_t depth = -1; + for (const auto& c : incoming->checkpoints) + if ((int64_t) c.ids.size() <= taken.tokens && (int64_t) c.ids.size() > depth) + depth = (int64_t) c.ids.size(); + if (depth > 0) { + taken.tokens = depth; + } else { + taken.tokens = 0; + } + } } else { std::fprintf(stderr, "strata serve: conversation cache: could not read %zu tokens back from the SSD tier " "(%s); the prompt is read again\n", sp_tokens, why.c_str()); @@ -20115,7 +20132,11 @@ int main(int argc, char** argv) { if ((int64_t) c.ids.size() == parked.tokens) { live = c.ids; live_imgs = c.imgs; } cvec_cached = donor->cvec; resume = parked.tokens; - from_live = false; + // A borrow whose donor matched with its live state mounts that state at this depth: there is no + // checkpoint of exactly this length, and the slot read below asked for one and ended the engine with + // "ERR restoring a conversation checkpoint failed" (#7648). A checkpoint match keeps its depth, + // which IS a checkpoint. + from_live = parked.live; conversations.count_borrow(); std::fprintf(stderr, "strata serve: conversation cache: borrowed %lld tokens from a parked " "conversation, which stays parked, in %.1f ms; parked=%zu bytes=%zu borrowed=%zu\n",