DeepSeek Harness Long Sessions: Built-in vs Proxy Compaction

Author
DeepSeekAgent.io Editorial Team
Published
Updated

Long-session cost is not determined only by the final answer. Every Agent turn can resend system prompts, history, tool definitions, and tool results. When automatic compaction does not complete in time, per-request context keeps growing and cumulative billing can greatly exceed the token count visible for one turn.

Recent community reports on 0.1.7-rc.2 and 0.2.0-rc.2 describe compaction not triggering, higher late-session cost, and interactions among Goal rounds and truncated tool results. These are reproducible cases in specific environments, not a claim that every Session is affected, but they expose a failure chain worth monitoring.

The DSH compaction path

Compaction is an optional capability outside the Agent Loop core. The automatic path evaluates two triggers before request construction:

  • pressure: estimated context approaches the configured threshold;
  • context-overflow: the provider confirms that the request exceeds its window.

The engine selects a Surface span with balanced tool calls and results, generates a summary, and replaces the old range with a new user message. compaction/start, summary, and end events record the transaction. A failed attempt remains observable instead of being represented as completed.

Why a full window can prevent recovery

Summarization itself requires a model request. If history already fills the context and the configured maximum output reserves a large region, the provider can reject the summary before compaction can save the Session.

With an 80K context and 32K maximum output, the safely usable history is far below 80K. Waiting for a meter to reach 100% is too late; the system needs room for the summary request, tool declarations, and the next output.

How 0.2.1-alpha.1 reserves headroom earlier

v0.2.1-alpha.1 makes the active LLM Adapter route authoritative for model capacity and lets proactive compaction combine context window W, current request-output reservation O, and additional headroom:

floor(min(W × thresholdRatio, W − O − headroomTokens))

The defaults are thresholdRatio: 0.8, headroomTokens: 65,536, and retainRatio: 0.16. The summary call's maxTokens follows headroomTokens by default and includes reasoning tokens charged by the Provider.

This change is about timing, not a more optimistic context meter. Even before history reaches 80% of the window, DSH uses the earlier threshold when reserving one full output and summary room leaves a smaller budget. Capacity is resolved again after a Provider or model switch, and identical model IDs under different Providers remain separate routes.

A custom model must declare its real contextWindow or inherit an accurate defaultContextWindow. Inflating the local value only delays compaction until the Provider rejects the request. For a small-window model, reduce headroomTokens or lower thresholdRatio, while preserving contextWindow > O + headroomTokens.

Why dsh-compact takes a different path

The community project dsh-compact, published on October 19, 2026, does not modify the local DSH Session or replace built-in compaction. It runs a transparent proxy on 127.0.0.1 between DSH and an OpenAI-compatible provider and changes only the request sent upstream.

The proxy first performs a model-free pass that strips Base64 images and shrinks old tool results. If the request still exceeds its threshold, it calls a compaction model to summarize older history while retaining recent turns verbatim. The author reports that a plain-chat fixture fell from about 195,000 tokens to 97,965 while retaining five of five facts and all seven summary headings. This is one project-provided fixture, useful for understanding the mechanism rather than predicting a universal compression rate.

Built-in compaction versus a local proxy

DimensionDSH built-in compactiondsh-compact local proxy
Modification pointOld spans in Session historyOnly the provider-bound request
Local DSH recordStores summary and eventsPreserves the original transcript
TriggerDSH route, window, and pressureProxy threshold
Provider pathNative DSH model chainOpenAI Chat Completions-compatible endpoint
Primary valueNative Session shrinkage reused by later turnsIndependent request-size control without rewriting local history

Do not stack both paths without understanding their thresholds. A proxy may summarize a request immediately after built-in compaction, losing more detail and making cost or failure attribution harder. Evaluate the Base URL, logs, data boundary, and recovery procedure in an isolated Profile first.

Recovering a Session after context overflow

A community case describes a roughly 190K-token Session in which token underestimation triggered compaction too late, the summary request overflowed again, and failed replay left the Session unusable. Segmenting the history compacted 227 items—about 123,163 tokens—to roughly 9K tokens and restored the Session.

A safer recovery sequence is:

  1. Stop automatic continuation so history cannot grow further.
  2. Copy the Session or export its record.
  3. Split old history on tool-call/result boundaries.
  4. Summarize the oldest spans incrementally and recalculate the remaining window after each step.
  5. Record input size, finish reason, and failure reason per segment.
  6. Resume with read-only checks before repeating side-effecting work.

A local proxy can reduce the next upstream request, but it does not automatically repair invalid or oversized state already persisted in the DSH Session. Data recovery still belongs at the DSH history and compaction-transaction layer.

How truncated tool results amplify loops

Before summarization, DSH can deterministically prune oversized tool results while preserving their beginning and end. If evidence the Agent needs is removed from the middle, it may reread files, rerun commands, or repeat verification. An unfinished Goal can then continue automatic rounds and multiply the cumulative request volume.

Investigate more than “the model reasoned too much”:

  • the first turn containing […] or a spill file;
  • repeated reads of the same path or command;
  • compaction starts without useful summaries;
  • a Goal driver continuing without new progress;
  • Sub-agents copying large context concurrently.

Monitoring signals

MetricWarning sign
Input tokens per turnRapid growth across consecutive turns
Cache-miss inputFrequent changes to schemas, prompts, or prefixes
Tool repetitionThe same resources are read repeatedly
Compaction stateRepeated failures, weak shrinkage, or a stale lock
Goal roundsAutomatic continuation without new progress
Cost per minuteContinued growth disconnected from result quality

Safer configuration and recovery

  1. Set thresholds below the model's hard limit and reserve summary/output room.
  2. Give long tasks independent turn, time, and cost budgets.
  3. Read large files by range instead of reloading them every turn.
  4. Watch pruning markers and preserve critical evidence in a short note.
  5. If automatic compaction fails, stop the Agent, temporarily enlarge the window, run one manual compaction, and restore the normal setting.
  6. Verify possible side effects before resuming or retrying operations.

A reproducible evaluation

Hold the model, Profile, task, and tools constant. Compare average input tokens, cache hits, compaction count, tool calls, and cost over the first and last ten turns. Repeat with a more conservative pressure threshold. Cost differences are meaningful only when both runs meet the same task-success criteria.

Related reading

References