serve: no park of the reply a request replaces

A request that resumes from a checkpoint parks the live branch first. When that checkpoint is the live branch's own turn checkpoint (the history before its last assistant turn), the live branch holds nothing else past it, and the prompt opens the same assistant turn there again, the client has re-sent the history with that reply dropped (an OpenAI-style client sends every earlier reply back without its reasoning), edited, or regenerated. That branch is no longer parked: no request of the client sends the reply back as it was, and the park copied the whole conversation to host memory on the request's path (131-209 ms per turn at 2K-20K on an R9700, lane PERF-AUDIT's chat run) for a copy the next park dropped as superseded.

The rule is live_tail_is_replaced_reply() (include/strata/program/reply_branch.hpp, test src/program/reply_branch_test.cpp): live[resume] and ids[resume] open a turn with the same role token, live has no other turn after it, and both agree before resume. generate.cpp asks it only when nothing else comes in (no parked conversation restored, no borrow, no batch slot, no lent slot, same cvec, no pin sibling) and the live branch has no picture at or past resume. Reuse is unchanged: the request reads from the same checkpoint as before. A real switch to another conversation parks as before. New engine log line [DRAFT]: "conversation cache: the reply this request replaces is not parked (N tokens past the turn checkpoint at M)".

Lane AGENT-TURN, P3.
This commit is contained in:
Niko1221 committed 2026-11-11 15:40:18 +01:00
1 parent 7d4f78242c
commit 5e41f69844
4 files changed
+138 -1

No files matched your search

+21 -1
View File
@@ -110,6 +110,7 @@
#include "strata/program/prefill_plan.hpp"
#include "strata/program/draft_kv_plan.hpp"
#include "strata/program/message_boundary.hpp"
#include "strata/program/reply_branch.hpp"
#include "strata/spec/draft_policy.hpp"
#include "strata/spec/draft_vocab.hpp"
#include "strata/spec/window_rule.hpp"
@@ -16417,6 +16418,25 @@ int main(int argc, char** argv) {
resume == req_pin && live_ok)
for (const ConvCheckpoint& c : checks)
if ((int64_t) c.ids.size() == resume && c.pinned) pin_sibling = true;
// The live branch past this request's resume point is only the reply this prompt replaces: the request resumes from
// the live branch's own turn checkpoint and opens the same assistant turn there again (an OpenAI-style client's
// next turn sends the reply back without its reasoning; an edited reply; a regenerate). That branch is not parked:
// no request of the client sends the reply back as it was, and its park is a copy of the whole conversation on
// this request's path that the next park drops as superseded (reply_branch.hpp). A real switch (another
// conversation, a parked one coming back, a batch slot, a borrow, another cvec) parks as before.
bool reply_replaced = false;
if (!from_live && !incoming && !borrow && slot_source < 0 && lent_slot < 0 && live_ok && !pin_sibling &&
want_cvec == cvec_cached && resume > 0 && imgs_below(live_imgs, resume) == live_imgs)
for (const ConvCheckpoint& c : checks)
if ((int64_t) c.ids.size() == resume && starts_with(c.ids, c.imgs) &&
strata::program::live_tail_is_replaced_reply(live, ids, resume, o.turn_token)) {
reply_replaced = true;
break;
}
if (reply_replaced)
std::fprintf(stderr, "strata serve: conversation cache: the reply this request replaces is not parked (%lld "
"tokens past the turn checkpoint at %lld)\n", (long long) ((int64_t) live.size() - resume),
(long long) resume);
// --conversation-cache-park-gain N: a park now would supersede the entry parked_prefix_tokens() reports (the copy
// this conversation wrote last), so a conversation that advanced fewer than N tokens since then keeps it:
// it still holds this conversation's prefix, and re-parking writes the whole snapshot only for the next
@@ -16461,7 +16481,7 @@ int main(int argc, char** argv) {
return 1;
}
}
} else if ((!from_live || incoming || slot_source >= 0) && !pin_sibling && park_worth &&
} else if ((!from_live || incoming || slot_source >= 0) && !pin_sibling && !reply_replaced && park_worth &&
!park_current(incoming ? incoming->bytes() : 0)) {
std::printf("ERR %s\n", err.c_str());
return 1;