r/PiCodingAgent • • Sep 27 '26

Question New session handoff vs compact. which do you prefer?

I've tried every major compact plugin and I settled just on a new session handoff.

Hard to find benchmarks on this sort of thing.

I started with my own custom compact and after a week of iterating, I eventually just ended up with an auto new session at max token limit.

(Another guy on here had posted a plug-in a few days ago that does just that)

13 Upvotes

34 comments sorted by

22

u/repolevedd Sep 27 '26

Every use case is different. Personally, I prefer a lean approach where the context window stays small and gets summarized regularly, while solid documentation lets me spin up new sessions with fast project context recovery.

  • I avoid large context windows because I don't have much VRAM. Once a task is done, I compress the context using my pi-refine-compact extension, so the LLM stays up to speed on what was done in broad strokes and we can move on.
  • Even when I use a cloud model, I still don't keep a huge window because prompt cache drops on the provider side aren't rare, and I don't want to overpay for someone else's glitches.
  • I document plans and project details as thoroughly as possible. After all, certain tasks, like devops and development, shouldn't really overlap anywhere except through documentation anyway, meaning starting new sessions is a necessity and you need to provide context right away.

Maybe my approach is a bit paranoid, but it gives me peace of mind and focus.

5

u/Equivalent_Idea8839 Sep 27 '26

Winner of this thread. I admire your paranoia.

3

u/4kidsinatrenchcoat Sep 27 '26

I do this too. Combined with mempalace this is just how I live

6

u/Ingaz Sep 27 '26

I'm using pi-blackhole and never had problems with it.

What did you used?

4

u/DistanceAlert5706 Sep 27 '26

I use observational memory and forgot about compaction.

3

u/m02ph3u5 Sep 27 '26

What exactly?

0

u/DistanceAlert5706 Sep 27 '26

Pi has extension, I've built my own for my harness too. IMHO it's a way to go instead of compactions

2

u/spawnsible Sep 27 '26

And you don't care that your input token size explodes if you never compact? That would suck claude usage with a boosted straw

2

u/DistanceAlert5706 Sep 27 '26

Please check how observational memory works. At some point you replace context with observations/reflections. Mastra has really great blog/technical docs about how it works.

2

u/spawnsible Sep 27 '26

Hey, I could use some links if you can share. Thanks

6

u/DistanceAlert5706 Sep 27 '26

3

u/m02ph3u5 Sep 27 '26

I use the built-in memory in omp in my work stack and find it only mildly useful. Especially differentiating what's universally true, universally true for the project, only true for the branch, or just the session or turn seems to be rather impossible.

1

u/spawnsible Sep 27 '26

Yeah, I should've been using this since yesterday. I built a summarization workflow myself but this is actually better. Thanks again

3

u/Santzes Sep 27 '26 edited Sep 28 '26

I used that for weeks at least, then I checked the session logs and turns out the agents had used the recall feature... total of 0 times.

Granted, it might be that the observations are useful by themselves without doing any recalls, but really made me question it's effectiveness

edit: ah you used your own

1

u/Abject-Kitchen3198 Sep 27 '26

I keep it simple. As soon as I notice consistent drop in quality that I might attribute to long context, I instruct a handoff with some directions I deem important. It's probably the best I can do to improve the result without writing handoff myself.

1

u/ea_man Sep 27 '26

I use pi-blackhole, a smart move would be to use an external model eg a free openrouter one to do the summary for the compaction so that you don't have to process / KV cache the whole ctx locally.

Or just don't do the summary, use just the deterministic roll.

1

u/ApprehensiveBag2926 Sep 27 '26

Why not both?
I have a orchestrator mode extension in Pi, where the system prompt instructs the model to update a plan and ledger md in scratch workspace, it can compact how/when it wants, because all the key findings and planned tasks are always tracked in scratch workspace

1

u/b1rdk Sep 28 '26

I prefer new handoff sessions. My way of working starts from the assumption that agents should be ephemeral, and that the task instructions should be reproducible for any agent at any point in time

So, in order to achieve this, I first need to define a Harness that builds a sufficiently descriptive and complete state of the task being carried out, indicating only what has been done and what remains to be done

I also try to make sessions last only as long as a task does, so I try to make each task as atomic as possible, or at least keep it limited to a bounded amount of effort

It’s like when you work in Agile, you take a large task, break it down into smaller subtasks, and regardless of how you wake up that day, you should be able to pick the task back up independently of the mood you’re in and know how to continue working on it

1

u/Ok_Significance_9109 Sep 28 '26

I ended up refining existing extensions and adding my own. Tool call pruning allows the agent to selectively summarize and remove bloated tool call results (they can be retrieved if needed from the archive). Then segmented compacting - it summarizes in chunks to avoid hitting OOM. Finally, if nothing helps anymore, automated handoff. The compacting agent is aware of the pruner so no tool call references are lost. And both compactor and pruner have a cloud mode (Google free api tier, with local fallback) and a local mode. Also made sure summarizing models are with thinking off.
Spent a lot of time fine tuning this… The agent also gets system messages about the state of context and cloud availability, so it makes the choices as part of its work process.

1

u/Remarkable-Car-2821 Sep 28 '26

I had the same experience, I also tried several compaction extensions, including my own, but was happy with none. Too often, a compaction event was visibly an inflection point in longer sessions from when quality deteriorated. I feel that lump summarization is just not the ideal concept. Handoff prompts worked better for me, but they come with their own issues, especially if you want to leave your agent alone for a while with a big chunk of development work.

So I created a fork of Pi (because this seemed beyond an extension) that gives the model itself more direct control over its context. It provides tools for the model to list the messages in the context, remove messages that have become irrelevant for future work packages, and summarize other messages selectively rather than the entire context. This is combined with a system prompt injection encouraging the model to keep its context cleanly focused on the task at hand *regardless* of capacity, since unrelated material causes context dilution and makes its output weaker.

It took a bit of fine tuning of the injected prompts and tool syntax before models picked it up. Recently I have combined it with a separately loaded skill on context management that gives a bit more guidance (e.g. be more conservative about pruning user messages, keep the most recent, quickly drop files you can reload again...) and tells models to self-improve this skill from lessons it learns during long sessions.

I've been working on a couple of large-codebase development projects for many several days now, mainly with Qwen 3.8 flash next (now freshly GuFo hosted) with only 128 context, and it's been working excellently. The harness would theoretically fall back to pi's default compaction if it ever reached the trigger point around 85%, but I haven't seen this happen for days. Qwen keeps its context well focused and below capacity, leading to good project results.

I do have to provide the caveat: It has been working really well only with Qwen (27b, flash next and max all manage their context competently). Other models are more reluctant to pick up the idea. I've been working with GPT-6-sol on another project, and it *does* use the tools and curate its context, but only when it feels capacity pressure, not based on quality and focus alone.

1

u/infectiousstupidity Sep 28 '26

Interesting idea, do you have a link to your fork?

1

u/Remarkable-Car-2821 Sep 28 '26

Disclaimer:

  • This is an experimental PoC, not production code, it is offered without any guarantees
  • The repo has a lot of focus on my thoughts and experiments, but the code is there and builds
  • Most of the code was written by AI, because, while I am an experienced C++ developer in the embedded world, and understand well enough what is going on in the underlying data structures, I have very little experience with javascript and no experience at all with typescript, and, frankly, some of it confuses me 😵

My recommendation if you want to try it, is to also include skills in your projects with additional guidance on what to prune, what to summarize and what to keep, and to encourage the model to self-improve that skill based on bad curation decisions it realized. If I find the time, I can add an example skill from one of my ongoing projects in the repo, but it will not happen before I leave the office tonight.

rxpi can read pi sessions. pi will read rxpi sessions, but since pi ignores rxpi's prune markers (silently) loading any longer rxpi sessions into pi will usually result in an immediate context overflow.

https://github.com/bendelec/reflective-pi

0

u/nippster_ Sep 27 '26

I use OpenAI compaction, it’s amazing

1

u/Mammoth-Most-1103 Sep 27 '26

In pi?

3

u/startassets Sep 27 '26

https://github.com/alexshpunt/pi-codex-compaction or you can use the original, I've made a fork so it works with switching to other models, original doesn't allow you to switch the model after native compaction

1

u/Mammoth-Most-1103 Sep 27 '26

Interesting. I would have bet the farm that openai would prevent callers that weren’t in codex from hitting that endpoint as the “magic” resides on their servers.

2

u/startassets Sep 27 '26

As codex cli is open source you can basically take whatever you want from there to make pi feel as native to openai models as you wish. There are plenty of extensions which try to achieve exactly this to different extents

1

u/Mammoth-Most-1103 Sep 27 '26

I’m saying that I am surprised that openAI is letting callers that aren’t codex, chatgpt desktop app, web app, or codex CLI actually hit those end points and actually get their server side magic.

In other words it is surprising to me that a “pi extension” or any skill, mcp, or plugin in any other harness could actually make that call, have it be actually successful, and actually get the valuable part of the response and then get it into that local pi’s context window

1

u/onerok Sep 27 '26

Curious as well.

I've been reading good things about Codex compaction enhancements recently. Would be nice to port some of that over to Pi if possible.

2

u/nippster_ Sep 27 '26

Ask pi to build a plugin to use the OpenAI compaction api https://developers.openai.com/api/docs/guides/compaction

0

u/Mammoth-Most-1103 Sep 27 '26

Check out cortexkit

I have been running their complete suite for the past week and I forgot about the concept of context and compaction.

I have a nice workflow built up around and preceding the cortexkit suite that provides durable context but.. I will say this, after this week trial I have it I am keeping it on both machines

AFT => replaces pis 4 tools with its own + 3 more that all hinge in the LSP, semantic search embeddings, codebase indexing

Magic-context => their take on caching. Pretty cool. Worth a google search or gh dive

Better yet just ask your agent to break it all down

1

u/m02ph3u5 Sep 27 '26

Idk man, looks like an LLM fever dream. Like the result of promoting: "make a brain but code, with sparkling images"

1

u/Mammoth-Most-1103 Sep 27 '26

Ai slop is ai slop for sure. But try it out is all I will say.