r/PiCodingAgent • u/Miserable_Land_84 • Oct 24 '26
News pi-protokoll – compaction for very long sessions with local models
Pi’s compaction re-reads the whole history and has the model summarize it. With a local model that took me minutes per compaction, and after two to four of them the context was so degraded that I had to start a new session. Building a procedural graphics demo, that happened ten times in five days.
pi-protokoll moves the work to the moment the model still has everything in view: every final answer ends with a short <protocol> block (result, decisions, files, open items, rules, index line, tags). At compaction time, code assembles a tiered, hard-bounded summary from these protocols; the model only updates a short state description.
What it does:
- recent turns verbatim, older turns as your message + protocol, everything before that as a code-built index plus rules, open items and changed files
- one-shot follow-up when the model forgets the block, written from the transcript if it ignores that too
- interrupted turns (Esc, errors, output limit) get their protocol before your next message
protocol_search,protocol_read,protocol_turn: the model can look up any earlier turn instead of guessing- fixed system prompt section, so the server’s prefix cache stays valid
- falls back to Pi’s own compaction if anything fails; the chat never blocks
Measured with Qwen 3.8 Flash Next on a local OpenAI-compatible server, 262k context: one session, 23 compactions, each roughly 213k → 35k tokens in about 30 s. Resuming the session reads about 36–44k tokens. With it, the demo went from ten restarted sessions to a single one: https://github.com/sebion7125/64kdemo (story of how it came about in ENTSTEHUNG.en.md).
Install: pi install git:github.com/sebion7125/pi-protokoll
Repo: https://github.com/sebion7125/pi-protokoll
Only tested with Qwen behind a local server so far. I’d love to hear how it does with other models and providers. I don’t have much time to develop it further myself, so forks and PRs are very welcome.


3
u/russlixx Oct 24 '26
so it's similar to pi-observational style with ledger systems? The compaction wait time is spreaded across chat's lifetime before compaction instead of concentrated in one time?
2
u/lemonfrommoon 26d ago
Honestly, this deserves more attention. Its a really cool idea (at least for us PP starved people). I tried it on a rather small task (about 6 compactions) and seems to work fine. Will be testing it on a larger task when I get the chance (time).
1
u/Miserable_Land_84 23d ago edited 23d ago
I announce a little update for some minor fixes / enhancements:
pi-protokoll 0.9.7
Two things changed: the model stops inventing a full context window, and switching the extension off no longer costs your prompt cache.
No more invented fill levels
In long sessions a model sometimes claims things like "Context left: 12 %" or "my context is almost full, we should start a new chat" and then advises a fresh session. None of that is real: nothing in Pi, in this extension, or in any installed package prints such a line. The model simply makes it up.
The system prompt section of this extension now carries a short, fixed note with the facts: unless the current turn hands over a fill level, the model has no information about the size of its window, so it states none, never claims it was told to start a new session, and suggests a fresh session only when it can name a concrete, checkable reason - and you decide. Older turns are compacted automatically, so these sessions run almost indefinitely. The note is final, so the prompt cache is invalidated exactly once.
Turning it off keeps the prompt cache
Before,
/protokoll offrewrote the beginning of the prompt, and every later request had to be processed from scratch. Now the prompt and the tool list stay byte for byte: one message at the current position withdraws the rules, and the threeprotocol_*tools stay available and answer "pi-protokoll is disabled"./protokoll onre-applies with a short note. Repeating the command does nothing extra.New escape hatch: /protokoll off --strip
Whether a model follows a withdrawal that sits at the end of a long chat is model dependent. If you want the rules really gone, use
/protokoll off --strip: the section leaves the system prompt and the tools are unregistered, with no withdrawal text. The next request then reads your whole context again, once, so expect a longer wait./protokoll onputs both back. The mode survives restarts.Sessions that started without the extension
Enabling it in the middle of a session does not patch the prompt either; the full rules arrive once as a message, and the status tells you that the older turns can be filled in with
/protokoll repair.After a compaction the prompt matches reality
Switch notes live in the chat and can be cut away by a compaction, which would silently bring the rules back. After a compaction the extension therefore retires notes that contradict the current state. If a needed withdrawal was cut away, the rules leave the prompt instead of leaving the model with rules nobody withdrew.
Honest limits
--stripif you need certainty.Update
bash
Pin the old version:
bash
Docs: https://github.com/sebion7125/pi-protokoll (
README.md,CHANGELOG.md)All 135 tests and the end-to-end script pass.pi-protokoll 0.9.7
Two things changed: the model stops inventing a full context window, and switching the extension off no longer costs your prompt cache.
No more invented fill levels
In long sessions a model sometimes claims things like "Context left: 12 %" or "my context is almost full, we should start a new chat" and then advises a fresh session. None of that is real: nothing in Pi, in this extension, or in any installed package prints such a line. The model simply makes it up.
The system prompt section of this extension now carries a short, fixed note with the facts: unless the current turn hands over a fill level, the model has no information about the size of its window, so it states none, never claims it was told to start a new session, and suggests a fresh session only when it can name a concrete, checkable reason - and you decide. Older turns are compacted automatically, so these sessions run almost indefinitely. The note is final, so the prompt cache is invalidated exactly once.
Turning it off keeps the prompt cache
Before, /protokoll off rewrote the beginning of the prompt, and every later request had to be processed from scratch. Now the prompt and the tool list stay byte for byte: one message at the current position withdraws the rules, and the three protocol_* tools stay available and answer "pi-protokoll is disabled". /protokoll on re-applies with a short note. Repeating the command does nothing extra.
New escape hatch: /protokoll off --strip
Whether a model follows a withdrawal that sits at the end of a long chat is model dependent. If you want the rules really gone, use /protokoll off --strip: the section leaves the system prompt and the tools are unregistered, with no withdrawal text. The next request then reads your whole context again, once, so expect a longer wait. /protokoll on puts both back. The mode survives restarts.
Sessions that started without the extension
Enabling it in the middle of a session does not patch the prompt either; the full rules arrive once as a message, and the status tells you that the older turns can be filled in with /protokoll repair.
After a compaction the prompt matches reality
Switch notes live in the chat and can be cut away by a compaction, which would silently bring the rules back. After a compaction the extension therefore retires notes that contradict the current state. If a needed withdrawal was cut away, the rules leave the prompt instead of leaving the model with rules nobody withdrew.
Honest limits
Whether a model follows the withdrawal note is model dependent - use --strip if you need certainty.
Whether the fill level note actually stops the guessing is not measured yet.
Providers that cannot take system messages in the middle of a chat fold every prompt change into the head of the request, so a change there always costs one full reprocessing.
Update
bash
pi update --extensions
Pin the old version:
bash
pi remove git:github.com/sebion7125/pi-protokoll
pi install git:github.com/sebion7125/pi-protokoll@v0.9.6
Docs: https://github.com/sebion7125/pi-protokoll (README.md, CHANGELOG.md)
All 135 tests and the end-to-end script pass.
1
u/Miserable_Land_84 19d ago
I've made some updates and wanted to share data of one very long session >200 turns.
1
u/Proper-Damage-1777 Oct 24 '26
Will give this a try tomorrow as I'm using pi-vcc for the compaction but your explanation make it sounds like I can let it run non stop without any hand holding all in the same session.
Questions about Esc, I'm using Strata with two models, one is the ISTA-DASLab IQ3_S and the other is Unsloth Q4_K_XL and on my setup, the IQ3_S average 160-200t/s and the Q4 is 40-60t/s. But I found out Q4 generally have lesser edit fail while IQ3_S will have higher edit fail the longer the session is.
So I have a habit of monitoring the reasoning and I prefer to Esc instead of letting Pi fumbling over and over. Does your protokoll handle the Esc moment gracefully? So far Pi and the model do know if I interrupt the reasoning and answer my questions fine. I hardly use steering because by the time my message arrives, it already ran too long and screw up the turn in a nasty way.
1
u/Santzes Oct 24 '26
I really like the idea of <protocol> at the end, interested to see how it works out
1
u/Proper-Damage-1777 Oct 25 '26
So I'm testing it with IQ3_S as I want the faster speed to see how much it can recover after fumbling and so far so good? Well today runs didn't fumble as badly as prior but together with pi-vcc, I can see this to be my permanent extensions.
1
u/cplr Oct 26 '26
I like this idea a lot, about having the model do in-line summarization for later-compacting. Is this a new idea or are there other compaction extensions that do something similar? Just wondering if you were inspired by any previous work or did you come up with this concept? This could solve a lot of problems for me!
1
u/kwokhou 28d ago
It throw this warning when I use it, I'm using `pi-cursor-sdk` (which works fine with pi-blackhole)
```
Warning: protokoll: follow-up request failed (Cursor provider runtime failed: Cursor provider ownership is unavailable: this call has no native session
request receipt. Bare modelRegistry.streamSimple calls are unsupported for Cursor; use the owning AgentSession's stream path or an independent child
AgentSession.)
▸ protocol turn 2: missing
```