Skip to content

Add deterministic snip compact for middle-history context reduction#22

Open
GateJustice wants to merge 1 commit intoLiuMengxuan04:mainfrom
GateJustice:feature/snip-compact
Open

Add deterministic snip compact for middle-history context reduction#22
GateJustice wants to merge 1 commit intoLiuMengxuan04:mainfrom
GateJustice:feature/snip-compact

Conversation

@GateJustice
Copy link
Copy Markdown
Collaborator

@GateJustice GateJustice commented Apr 27, 2026

Summary

为 MiniCode 新增 deterministic snip compact。Snip 会在 tool result storage / budget 处理之后、microcompact 之前运行,删除一段安全的旧中间历史区间,并在当前对话中插入 snip_boundary 标记。

Motivation

长会话中会积累较早的中间历史上下文,这些内容会持续占用 token budget,并可能导致系统过早进入 full compact。Snip compact 提供了一个保守的本地上下文清理步骤,可以在不调用模型的情况下缓解 context 压力。

Implementation

  • 新增 deterministic snip heuristic,不调用模型,也不访问网络。
  • 将 snip compact 接入到 microcompact 之前,使后续 microcompact 和 auto/full compact 基于更新后的 message list 继续运行。
  • 插入 snip_boundary metadata,用于记录被移除的 message ids、数量和大致释放的 tokens。
  • 更新 session persistence 和 restore 逻辑,通过 removedMessageIds 过滤被 snip 的消息,避免 reload 后旧消息重新出现。
  • 新增 /snip 命令支持。
  • 增加 Anthropic message conversion、token estimation 和 compact rendering 对 snip_boundary 的兼容。
  • 增加 snip 行为和 session restore 兼容性的测试。

Testing

  • npm run check
  • npm test
  • npm run lint --if-present

Risks / Notes

  • 当前 heuristic 有意保持保守;如果没有安全的连续中间区间可删除,snip 会跳过。
  • snip_boundary 是内部上下文标记,不代表真实用户请求。
  • 如果 snip 无法安全释放足够上下文,系统会继续使用已有的 microcompact 和 auto/full compact 作为 fallback。

part of #1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant