mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-05 11:59:35 +08:00
The summary was prepended inside the replayed history, so every compaction rewrite changed bytes at the head of the request and threw away the whole cached prefix behind it. Measured on a six-turn session on a custom OpenAI-compatible route: the turn that rewrote the summary dropped the shared prefix to one message and ran 21,629 prompt tokens for 5,888 cached (27.2%). Deliver it where the runtime-snapshot machinery already puts per-turn context: as a trailing role=user message tagged _context_snapshot. A rewrite is then a pure append, and an unchanged revision is a no-op. replay_history no longer injects the summary, which is what kept it mid-request whatever position it was given. Two smaller fixes ride along, both in the same summary path: * The summariser's scratchpad leaked into compressed_summary when the route emits reasoning inline. The stored summary was 6,933 characters, half of them the model's drafting monologue under an unclosed think tag, and the real summary was truncated by it. clean_thinking_tags cannot be used here - it deletes through end of text for an unclosed block - so the tag is honoured only when it is closed, and an unclosed one is cut at the first heading. * _model_tokens counts the summary the way the request carries it. The two regression tests that pinned the summary inside model_history now assert the new delivery: the history starts at the oldest retained turn and the summary still reaches the model.