Repository navigation
Conversation
Owner
…s drained after a budget stop (opt-in STRATA_REPLY_REUSE) PromptEncoder.remember_reply keeps the prompt plus the reply's own ids as one entry whose cuts are the reply's token boundaries (never inside a UTF-8 character or a special tag), so the next prompt takes the ids the engine holds up to where its text really differs instead of leaving them at the first piece BPE would have merged. The tokens the engine sends after a thinking budget's STOP are collected while draining and, when plain text, join the thinking, so the wrap-up continuation extends the session. Both behind STRATA_REPLY_REUSE=1; unset, every prompt is a fresh encode as before.
zsariboga
force-pushed
the
pr-reply-reuse
branch
from
October 17, 2026 10:38
0d5fd29 to
1de969b
Compare
Contributor
Author
eddoursul
added a commit
to eddoursul/Lamina
that referenced
this pull request
Oct 17, 2026
… on by default): the prompt encoder keeps each text request's prompt with every token the engine sent (StrataEngine.held, the drained ones too) as an entry cut at the reply's token boundaries, so the next prompt takes those ids up to where its text differs instead of a fresh encode that parts at the first piece BPE would merge (`())` `);` for `()));`) and makes the engine read the rest of the reply again; a thinking budget's wrap-up keeps the tokens generated past its stop when they are plain text; a prompt that makes the engine read 256+ held tokens again is logged with both sides' pieces where it parts. A pi session of a coding task (UD, 43 requests to 85K tokens) lost 28,566 held cells without it, 26,530 and 1,940 at two such pieces; a second session of the same task (34 requests to 70K, replies up to 28,603 tokens) lost none. Tests: ReplyReuse, ServedReply (fails without the change), ThinkingBudget's drained tokens Claude-Session: https://claude.ai/code/session_019XsrN8Zv3y7DHzXC9STsiV
ksanislo
added a commit
to ksanislo/Strata
that referenced
this pull request
Oct 24, 2026
…e next turn, keep the tokens drained after a budget stop (opt-in STRATA_REPLY_REUSE) (by @zsariboga) Squashed from Niko1221/Strata pull/1536/head (1de969b), diff against its fork point 477ac13. (cherry picked from commit c15ffb1)
ksanislo
added a commit
to ksanislo/Strata
that referenced
this pull request
Oct 24, 2026
…e next turn, keep the tokens drained after a budget stop (opt-in STRATA_REPLY_REUSE) (by @zsariboga) Squashed from Niko1221/Strata pull/1536/head (1de969b), diff against its fork point 477ac13. (cherry picked from commit c15ffb1)
ksanislo
added a commit
to ksanislo/Strata
that referenced
this pull request
Oct 24, 2026
…e next turn, keep the tokens drained after a budget stop (opt-in STRATA_REPLY_REUSE) (by @zsariboga) Squashed from Niko1221/Strata pull/1536/head (1de969b), diff against its fork point 477ac13. (cherry picked from commit c15ffb1)
ksanislo
added a commit
to ksanislo/Strata
that referenced
this pull request
Oct 24, 2026
…e next turn, keep the tokens drained after a budget stop (opt-in STRATA_REPLY_REUSE) (by @zsariboga) Squashed from Niko1221/Strata pull/1536/head (1de969b), diff against its fork point 477ac13. (cherry picked from commit c15ffb1)
ksanislo
added a commit
to ksanislo/Strata
that referenced
this pull request
Oct 24, 2026
…e next turn, keep the tokens drained after a budget stop (opt-in STRATA_REPLY_REUSE) (by @zsariboga) Squashed from Niko1221/Strata pull/1536/head (1de969b), diff against its fork point 477ac13. (cherry picked from commit c15ffb1)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rebased on #1852's
PromptEncoder(the encoder now onmain), as asked. The branch is one commit onmain(477ac13c). It no longer depends on #1455.What it changes
Everything new is opt-in behind
STRATA_REPLY_REUSE=1. With the variable unset, every prompt is a fresh encode and the server behaves exactly asmaindoes.PromptEncoder.remember_reply(prompt_ids, gen_ids)(tools/strata_tokenizer.py, +48 lines). After a reply, the server keeps the prompt plus the reply's own ids as one encoder entry._straddles).encode, a prompt that shares the text past the reply's start may cut at those boundaries without themax_special_len - 1margin. The engine holds those ids, and the text from the cut on is encoded afresh.serve/server.py). The engine sends a few tokens after the budget's STOP before it sees it, and keeps them in its session. They are now collected while draining (StrataEngine.drained). With the switch, they join the thinking when they are plain text (no stop token, no<, no split character), so the wrap-up continuation extends the session instead of reading the thinking again.STRATA_PROMPT_DUMPdiagnosis and the raised encoder limits are gone. serve: tokenise the prompt from the last shared prefix, not from the start #1852's encoder has no such limits.Why
In agent sessions the engine often read a whole reply again on the next turn, although the reply's state was still in its session. The model writes some text in pieces BPE would merge (Turkish letters, digits, code), so the next turn's fresh encode leaves the engine's ids at the first such piece. A reply has no checkpoint inside it, so the engine went back to the turn's start. One real case: 364 tokens reused and 1903 read, where about 885 could have been reused.
Measured (the previous version, 0.1.40.3)
Setup: RTX 5070 Ti Laptop 12 GB, Core Ultra 7 255HX, 64 GB DDR5-5600, Windows 11, Swift 1.5 abliterated IQ3_XXS, opencode.
Not re-measured end to end on this rebase. The unit tests below check the encoder and the budget path. I run the same encoder change on 0.1.45 locally.
Tests
serve/test_prompt_encoder.pyReplyReuse(4 new, with a small BPE vocabulary where 'ab' / 'abc' / ' a' merge):serve/test_server.pyThinkingBudget(3 new):python -m unittest discover -s serve -t . -p "test_*.py"(Windows): 855 tests, one failure. It istest_keepawaketest_service_holds_for_the_whole_request_including_early_close, which also failed on unchangedmainhere and passes when run on its own (timing).Python only: no engine, HIP or SYCL file is touched.