From 8cdad437bbc25eeb600f272485eedb00ce31d940 Mon Sep 17 00:00:00 2001 From: giphoo Date: Wed, 2 Dec 2026 15:46:45 +0800 Subject: [PATCH] engine: a restored archive resumes at a checkpoint depth, not at the common prefix (#7648) Two admissions asked the restored image for a checkpoint of exactly the common-prefix length. When the image's live state is longer than the prompt (a fork reading a prefix of it), that length is no checkpoint's depth: the lookup found nothing and the engine ended with "ERR restoring a conversation checkpoint failed". - SSD tier: the resume lands on the deepest checkpoint at or below the prefix; with none, the prompt is read from 0 rather than mounting a state the request overwrites. - Borrowing a parked conversation whose match was its live state: the borrow mounts that state, so the resume is a live mount. A checkpoint match keeps its depth, which is a checkpoint. Fixes #7648. --- engine/src/program/generate.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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",