Back to Blog

Deep Dive

Session Compaction: Keeping Long Conversations Alive

Every model has a context window. Every long conversation eventually hits it. Arcana handles this with automatic session compaction: a process that summarizes older parts of the conversation while preserving the information that matters.

This is one of those problems that is invisible until it is not. You are having a productive conversation with your agent, building on context from 30 minutes ago, and suddenly the agent starts forgetting earlier instructions. That is the context limit. The model physically cannot hold more text. Without compaction, the only option is to start a new session and re-explain everything.

Compaction solves this by intelligently reducing the conversation history. The agent loses the details of early conversation but retains the decisions, conclusions, and key context. It is like taking notes during a long meeting: you do not remember every word, but you remember what was decided.

How Compaction Works

When a session approaches the context limit, Arcana triggers compaction automatically. The process:

  1. Identify which parts of the conversation are older and less relevant
  2. Summarize those parts into a concise context block
  3. Replace the old messages with the summary
  4. Preserve recent messages, tool outputs, and any explicitly pinned context

The agent is aware of compaction. After compaction, it knows that earlier context has been summarized and can ask for clarification if needed.

What Gets Preserved

Not all context is equal. Arcana's compaction heuristic prioritizes:

  • Recent messages (last N messages are always kept verbatim)
  • Tool outputs from file reads, search results, and code execution
  • User instructions that set goals or constraints
  • Error messages that indicate problems to avoid

What gets summarized: exploratory conversation, intermediate reasoning, repeated confirmations, and back-and-forth that resolved into a final decision.

Manual Control

You can trigger compaction manually with /compact in the TUI. This is useful when you know the context is getting cluttered even if you have not hit the limit yet.

# Trigger manual compaction
/compact

# Check current context usage
/context

Configuration

Compaction behavior is configurable:

  • session.compaction.threshold: When to trigger (default: 80% of context window)
  • session.compaction.preserveRecent: How many recent messages to always keep
  • session.compaction.aggressiveness: How aggressively to summarize

What Gets Lost

Compaction is lossy by design. The information that gets summarized away includes:

  • Exploratory conversation. The back-and-forth where you were figuring out what to do. Once the decision is made, the exploration is less important than the decision itself.
  • Intermediate reasoning. The agent's step-by-step reasoning that led to a conclusion. The conclusion matters; the reasoning trail is less critical.
  • Repeated confirmations. When you said "yes" three times to the same approach, the summary captures the decision once instead of recording each confirmation.
  • Tool output details. Large file contents and search results that are no longer relevant to the current task.

The heuristic is designed to preserve the signal and discard the noise. In practice, after compaction, the agent retains enough context to continue working coherently on the task at hand.

Compaction vs. New Session

You have two options when context gets long: compact or start fresh. The right choice depends on the situation:

  • Compact when you want to continue the current task and the agent has useful context about what you are building.
  • New session when you are switching to a completely different task and the current context is more noise than signal.

Arcana does not force one approach over the other. You decide based on what makes sense for your workflow.

Why It Matters

Without compaction, long sessions hit context limits and the agent starts losing early context. With compaction, a session can run for hours while the agent retains a meaningful understanding of the full conversation history. The tradeoff is that summarized context is lossy, but Arcana's heuristic is designed to lose the right things.

For most developer workflows, compaction is invisible. The agent continues working coherently, the conversation flows naturally, and you do not need to think about context windows. The system works in the background, doing the token math so you do not have to.