Compaction, token metering, and spill
Not blunt truncation: safely replace the model surface while preserving large results and auditable accounting
measure → prune → summarize → replace surfaceHow do you shorten context without breaking tool call/result pairing or deleting original facts?
An archive does not destroy case files. It adds a summary index for daily use; oversized attachments move to storage while the catalog keeps a locator, size, and retrieval instructions.
Mechanism
TokenMeter prices the current surface node by node. Compaction logs a start lock, optionally prunes tool results, generates a summary plus replacement user/message, then logs end.
Spill policy stores oversized text in a session-private backend during tools/post-execute and gives the model a preview plus opaque locator. If saving fails, it preserves the original result.
Measure pressure
A usage anchor or conservative heuristic produces totalTokens.
What extensions must preserve
- Compaction boundaries preserve tool call/result balance
- start/end lock encloses the whole operation
- Spill locators are opaque handles, not assumed local paths
The tempting wrong turns
- ×Selecting surface nodes by numeric seq interval
- ×Writing a successful end after summary failure
- ×Turning a successful tool call into an error when spill storage fails
Do not trust the conclusion—verify it
These anchors are pinned to official deepseek-harness@47f9438; account for later breaking changes when reading current upstream.
Pause for ten seconds before revealing
Why are compaction/start and end log-only events?
Compaction still rests on the full log. Next we persist it across processes and read efficiently through projections and queries.