diff --git a/tools/server/server-context.cpp b/tools/server/server-context.cpp index d1fc2fd93..6918f10a8 100644 --- a/tools/server/server-context.cpp +++ b/tools/server/server-context.cpp @@ -4948,6 +4948,23 @@ private: const bool merge_user_starts = userstart_merge && !has_mtmd && slot.task->n_tokens() - slot.prompt.n_tokens() <= n_ubatch; + // [fork F14] merged or not, keep the break at the first user message, the end of + // the system prompt: the checkpoint there is what a new chat with the same system + // prompt restores. The batch only reaches it when the prompt is processed from + // before it (a fresh prompt; checkpoints past the restore point are erased), so + // follow-up turns are not affected. Below 8 tokens there is no system prompt + // worth a checkpoint (only a BOS before the first user message). + int32_t first_user_pos = -1; + for (const auto & s : spans.spans) { + if (s.role == COMMON_CHAT_ROLE_USER) { + first_user_pos = (int32_t) s.pos; + break; + } + } + if (first_user_pos < 8) { + first_user_pos = -1; + } + // add prompt tokens for processing in the current batch while (slot.prompt.n_tokens() < slot.task->n_tokens() && batch.size() < n_batch) { // get next token to process @@ -4991,11 +5008,15 @@ private: slot.prompt.tokens.push_back(cur_tok); // break at the last user message, or at user messages at least min step past the last checkpoint - if (do_checkpoint && !merge_user_starts && spans.is_user_start(slot.prompt.n_tokens())) { + if (do_checkpoint && spans.is_user_start(slot.prompt.n_tokens())) { const auto pos = slot.prompt.n_tokens(); const auto & checkpoints = slot.prompt.checkpoints; - if (pos == last_user_pos || checkpoints.empty() || pos > checkpoints.back()->n_tokens + params_base.checkpoint_min_step) { + if (merge_user_starts) { + if (pos == first_user_pos) { + break; + } + } else if (pos == last_user_pos || checkpoints.empty() || pos > checkpoints.back()->n_tokens + params_base.checkpoint_min_step) { break; } }