DEV Community

啦啦啦种太阳
啦啦啦种太阳

Posted on Originally published at dsh-plugin.com

What /compact Actually Does to Your DeepSeek Harness Context

You type /compact during a long DeepSeek Harness session. The context meter drops, and you move on as if nothing was lost. That assumption is the risky part. Compaction replaces a selected range of older model-visible history with a summary. Automatic pressure, overflow recovery, and /compact each have their own trigger, and none guarantees that every detail survives.

This post starts with the manual command, then covers automatic triggers, the token meter, and a routine for compacting a working session while keeping the facts you need.

Pressure, overflow, and manual compaction select a safe range, then replace older surface with a summary

What /compact keeps and what it replaces

With the command component installed, entering /compact in chat requests an immediate reduction between turns, even before the automatic threshold is reached. The commands reference describes the user-command system.

/compact
Enter fullscreen mode Exit fullscreen mode

The basic backend summarizes an older, balanced range. Its normal pressure policy keeps a recent tail verbatim. The manual path selects a balanced range with a zero retention budget, and confirmed overflow recovery also bypasses the normal retention policy. The boundary keeps tool calls paired with their results, but does not have to preserve an entire turn. A single indivisible oversized unit may leave no useful range to compact.

The result replaces an older range on the model-visible surface with a summary message. Compaction events record the selected range, summary, and lifecycle in the durable log. Shadowing does not delete the underlying log, and it does not guarantee that every detail in the old range remains visible to the model. A model generates the summary, which can omit or distort details. Check important decisions after compaction.

Discussion #11217 reports that the native command does not accept a free-form summary focus and proposes adding one. This is a user report and feature request, not documentation for a supported argument. Use the bare command, and save critical facts in a durable project artifact before relying on a summary.

Mechanism Trigger What to expect
Pressure Measured pressure crosses the backend's threshold Older balanced history may be summarized after optional pruning
Overflow recovery Provider confirms context overflow More aggressive reduction may enable a bounded retry
/compact User invokes it while the agent is idle Manual reduction, even before the pressure threshold
Tool-result pruning Optional component after a trigger Oversized results may shrink without a summary call

When compaction runs without you asking

Compaction is an optional capability that depends on a service, a backend, and a user command. The compaction reference describes automatic triggers for pressure and confirmed context overflow. The basic backend documentation says the supplied base configuration enables that backend by default, though other compositions may differ.

For the documented basic backend, the default pressure threshold is floor(min(W × 0.8, W − O − B)), where W is the model context window, O is the effective request output reserve, and B is extra headroom, which defaults to 65,536 tokens. The budget for recent history kept verbatim defaults to 16% of W − O. The policy and model-specific overrides can change these values. This formula is a threshold for this backend, not a universal percentage for every compaction implementation.

A confirmed context overflow follows a separate recovery path. The reference says this path can use a more aggressive reduction and returns a retry action only if the surface replacement generation has advanced. The basic backend documents a limit on overflow retries. If no safe range can be reduced or the summary fails, do not assume a retry will solve the request.

The context window W and output reserve O come from the model you route to, so the threshold changes when you switch models. The model and provider configuration guide explains where to set the context window and maximum output, and why a configured value does not change what the upstream service accepts.

How should you read the token meter?

The token meter reference distinguishes totalTokens, which measures current request-and-response pressure, from surfaceTokens, which sums the prices of the current model-visible surface nodes. They answer different questions and should not be added together as separate usage totals.

The measurement uses a matching recent provider usage anchor when its documented conditions are met. Otherwise, it estimates the full envelope and surface. A signed surface delta accounts for changes since the anchor. Image pricing can depend on the routed model if its adapter declares a visual price; otherwise, the documented heuristic applies. The meter is useful for pressure decisions, but it does not promise exact future provider billing or a byte-for-byte transcript size.

The meter snapshot and session telemetry are separate records. Inspecting model usage telemetry explains which record answers which question.

How do you compact a working session responsibly?

  1. Before the conversation grows large, record decisions, constraints, unfinished work, and file locations in an appropriate project document. Do not put secrets in a document just to preserve them.
  2. Wait until the agent is idle, then enter /compact if the command component is available. The basic backend reports a busy state during an active turn or an existing compaction.
  3. Read the result and ask the agent to restate the critical constraints and next action. Compare that restatement with your durable notes, and correct any omissions explicitly.
  4. Continue with a small, verifiable step. If the request still overflows, check the model's actual context capacity, output reserve, and large inputs instead of assuming another summary will fix it.
  5. For deployment tuning, consult the backend documentation and validate the configuration against the target model. A headroom value that consumes a small model's entire window is invalid.

The optional pruner may first reduce oversized tool output. If that lowers pressure enough, the basic backend can skip summary generation. A successful pruning step can remain even if later summary work fails. Treat the reported outcome as evidence of what happened, not as a guarantee that all subsequent work used an unchanged surface.

How do you recognize an ineffective compaction attempt?

A reported attempt does not necessarily mean a successful reduction. The service can return no result when there is no effective range to reduce. Its documented manual error classes cover busy, cancellation, changed input, summary, and persistence problems. If the agent is busy, wait for the current turn to finish. If the selected history changes during the attempt or the summary fails, inspect the reported outcome instead of assuming a replacement was made.

The range must preserve tool-call and tool-result pairs. This prevents an arbitrary cut through a pair, but it also means the engine cannot always carve a large item down to the size you want. The basic backend rejects a summary that does not reduce its source. A conversation dominated by one indivisible input, a large fixed prompt, or a tool definition may still exceed capacity after ordinary history is shortened. Consider reducing the input or choosing an appropriate model instead of repeatedly invoking the same command.

What should you carry forward after a summary?

Before compaction, capture the problem statement, accepted constraints, key decisions, paths, and remaining work in a file your team is willing to retain. Distinguish confirmed facts from hypotheses, and note any test failures that still need investigation. After compaction, compare the assistant's understanding with those notes. If a detail is missing, supply the corrected fact explicitly or point to the source document. Do not assume an older message remains model-visible just because it still exists in the event log.

The meter is a snapshot at a consumed log revision, not a guarantee for an arbitrary future request. Different models can price images differently, and the output reserve changes the available budget. The basic backend also evaluates pressure when switching model routes. A smaller target can require a reduction before the new request. If the switch fails, inspect its reported cause and the target capacity instead of treating the previous model's meter as authoritative for the new route.

Keep the privacy distinction clear. A summary may retain sensitive details, and shadowed source events may remain in the durable log. Editing a summary does not replace the deployment's retention or deletion process. Share a sanitized diagnostic when seeking help, and consult the applicable storage policy before putting sensitive material in long-lived notes.

When reviewing a compacted session, distinguish a summary request from an ordinary assistant answer. The backend documentation says the summarizer makes an additional model call, and only the returned text enters the checkpoint. The output is intended to preserve useful context, but that does not prove every original tool result or decision survived. If a task requires exact data, retain and verify the original authoritative artifact separately before continuing.

What are the limits and safety boundaries?

According to the basic backend documentation, compaction cannot shrink the system prompt, tools, or session prefix. It cannot split an indivisible oversized unit. It makes an additional model request for a summary, so it may consume time and tokens. The summary is not a perfect archive.

The service uses a recorded lock and lifecycle events. Failure, cancellation, a changed selection, or a busy session can prevent a replacement. Durable history and the current model-visible surface serve different roles. Do not use compaction as a privacy deletion feature. Verify your deployment's data-retention procedures separately.

Glossary

  • Compaction: reducing model-visible history by summarizing and replacing a selected range.
  • Surface: the ordered messages currently projected to the model, which can differ from the durable event log.
  • Pressure: the token meter's measure of request-and-response context demand.
  • Retention budget: the backend's budget for keeping recent history verbatim.
  • Pruning: optional reduction of oversized tool results without necessarily making a summary request.

Originally published at https://dsh-plugin.com/blog/context-compaction-compact

Top comments (0)