Skip to content
MyDSHMy DSH Field Notes
中文
Independently maintained; not affiliated with DeepSeek. No association with mydsh.dev or other MyDSH sites.

Home/Modes & context/Context & compaction

How compaction happens: three log-only events and one real replacement

A long session suddenly forgets earlier context or degrades, and you cannot tell whether it is the model or compaction.

VerifiedVersion and environmentChecked 2026-11-14
Source
docs/subsystems/compaction.zh.md
Checked
2026-11-14

Compaction is an optional capability, outside the agent loop — meaning it may not be installed at all (minimal preset has none). When installed, the mechanism is:

EventPayload highlightsPurpose
compaction/start{ turn }Takes the log lock; a number means an automatic turn, null means a manual attempt
compaction/summarySummary, shadowed range and seqs, estimated tokens, model envelopeRecords the summary and which span it shadows
compaction/end{ turn, error? }Releases the lock; error records a failed attempt

The key design: none of these reach the surface

The docs are explicit: all three are log-only and never enter the surface. The model never sees that a compaction happened.

What actually changes what the model sees is a separate step: the summary rides on a user/message carrying surfaceOp: { op: 'replace', start, end }. That is the only surface change compaction makes.

This explains a common confusion: after compaction the model does not act as if it was compacted; it simply behaves as though the earlier history changed. It received no notification, only a replacement message.

Why the lock matters: crashes are detectable

The three events form a lock: start takes it, summary is generated, the record is written, the replacement message lands, end releases. A crash mid-way looks like an orphan lock (a start with no end) — detectable.

Had end been written before the work, a crash would look like 'compaction completed' when it did not. The designer treated 'a crash must tell the truth' as a hard requirement.

What this means for you

  • After compaction, earlier detail may survive only as a summary: exact numbers, file paths, corrections you made may not all be in it.
  • Restate important constraints; do not assume they cross a compaction.
  • Split fidelity-critical work: several short sessions on a long document beat one long session.

What counts as working

Check every line. All of them pass or the job is not done.

  • You know whether compaction is available in this session (minimal has none)
  • You know the model gets a replacement message, not a notice
  • Important constraints are restated in long sessions

Where it fails

Symptom, cause, what to do — written in the order it actually happens.

SymptomCauseWhat to do
It forgot a key constraint after compactionThe constraint lived only in the shadowed spanRestate it, and put it at the top of the instruction
You think compaction never ranIts events are log-only; the UI may not surface themCheck the session event log for compaction/* rather than the UI

Sources

Verified means measured here. Compiled means every line carries a source.