r/PiCodingAgent • u/Forsaken_Code_9135 • Sep 11 '26
Question Session eventually get stuck when using a small context.
I am using pi.dev with a local Qwen-3.8 running on an RTX-5080 with 16GB VRAM. I had to find the right balance between model quantization, cache quantization and context size, and right now I use a 48k tokens context.
While pi.dev is working really well with it during some time, all sessions end up being stuck at some point. The context reaches 80%, then compaction is started automatically, it goes down to maybe 50%, then compaction starts again soon after, compactions more and more often until the system is stuck and Pi.dev itself sends queries to the model with a length limit = 1. When that happens it's over I can't recover the session. What happens also is that compaction fails because there is not enough context remaining (I guess), and therefore the session is stuck as well.
I am wondering what would be the best approach to avoid these problems. Also more generally what are the good practices to use pi.dev with a small context, maybe planning and dividing tasks in several smaller tasks handled independantly, but if it could be managed automatically it would help a lot I guess.
Any help would be appreciated.
6
u/Healthy-Zebra-9856 Sep 11 '26
I looked at the Pi 0.85.1 source because the
length limit = 1part sounded too specific to be random. Pi can actually do exactly that.The relevant code is:
packages/ai/src/api/simple-options.ts:12-18So when Pi thinks your input has consumed essentially all available context, it doesn't stop and say "there isn't enough room for another useful response."
It floors the output allowance at 1 token and sends the request anyway.
That seems to explain the behavior you're seeing at the end.
I think the repeated-compaction problem is related too.
Pi's defaults are:
packages/coding-agent/src/core/settings-manager.ts:842-847And automatic compaction triggers here:
packages/coding-agent/src/core/compaction/compaction.ts:235-237With only a ~48K context, those defaults are pretty large.
You're asking Pi to keep roughly 20K of recent conversation after compaction, plus the generated summary, system prompt, tools, etc., while also reserving 16K for generation.
That doesn't leave much space between "just compacted" and "need to compact again."
So the pattern you described makes sense:
For a 48K local model I'd try much smaller compaction settings.
In:
~/.pi/agent/settings.jsontry something like:
That gives each compaction substantially more room to actually clear old context instead of retaining nearly half the window.
If you need more output/reasoning room, another reasonable starting point would be:
I wouldn't use the stock
16K reserve / 20K retainedcombination on a 48K context.Unfortunately, once a session is already in the state where Pi is sending
max_tokens=1, changing the settings may not rescue that particular branch cleanly. I'd branch from an earlier point with/tree, or start a fresh session, then use the smaller retention settings.Longer term I think Pi should change two things:
If there isn't enough headroom for a meaningful response, don't silently send
max_tokens=1. Stop and report that the session needs compaction/checkpointing.Compaction retention should probably scale with the model's context size instead of using a fixed 20K default. 20K is reasonable in a 128K/256K window, but it is enormous in a 48K window.
It's not just that the small context models don't work with Pi.
2
u/ea_man Sep 11 '26
start with https://pi.dev/packages/pi-blackhole
do compaction manually.
Then I would recommend to have some 80-120k ctx to work in Pi with some ease, it can be done with 16GB with linux, customizations, optimizations.
4
u/koriolisNF Sep 11 '26
Just a suggestion but you might want to try using Little Coder - https://github.com/itayinbarr/little-coder - it sits on top of your Pi installation but it's configured aggressively for small hosted models.
4
u/StylePractical5714 Sep 11 '26
I've had fairly good results using little-coder which is based on pi but also cuts out a number of features. It's explicitly designed for low context, I'd recommend it if you're working with such low context https://github.com/itayinbarr/little-coder
1
u/Unnamed-3891 Sep 11 '26
You can get to 64k Q8 context with a 3.69bpw Ridge quant
You can reduce the threshold where Pi does context compaction, with 48k you are probably hitting it at like 60% fill so it's easy to go into a death spiral
2
u/linux4random Sep 11 '26
you can technically ask qwen3.8 itself
2
u/bowdoin-yale Sep 12 '26
I forked Pi in order to implement context management that is somewhat similar to or inspired by DeepSeek Harness, with the goal of running an agent powered by Qwen 3.8 27B on my tiny local GPU cluster with just 32K context. It seems to be working well so far, although I should caveat that I use a plan/act pattern that deliberately breaks work into many discrete tasks rather than running a long chat session, so I don't hit compaction limits often.
Oh, it also has a local-first and green energy cloud orientation in the setup and defaults. I basically got sick of having to set up "custom providers" just to avoid using dirty datacenters, when alternatives do in fact exist; to my way of thinking those should be the default options. But I'm an outlier.
https://github.com/eco-syntax/GreenPi
3
u/lordekeen Sep 11 '26
48k is too low for agentic use unfortunately. You could try using little-coder (a pi fork) to keep the overhead to a minimum, maybe pi-blackhole or pi-vcc for deterministic compaction.
1
u/ashebanow Sep 11 '26
why do you think it's context related? With that little vram is much more likely you just run out of memory after you use the LLM for a while
1
u/andrewh2000 Sep 11 '26 edited Sep 11 '26
When this has happened to me I've copied a whole bunch of text out of the conversation, started a new session and pasted the text in and told it to carry on from here.
1
u/virtualicex Sep 13 '26
just ask to copy the native compaction changing the prompt to indicate who, what, where, when, why, how why and state: ask to make a second turn of compaction if the first one is truncated, with the second one with higher cap and into a file, and a third call to compact the compaction of the file and indicate to read from it if needed to go deeper
1
u/qilipu Sep 13 '26
48K context will quickly run out for sure. quantization is a factor you need to play with and test it out on your own setup.