Skip to content

bug(runtime): manual /compact checkpoint is dropped after next-turn tool-result pruning #6048

Closed

Description

@me2seeks
English

What happened

A successful manual /compact checkpoint can be invalidated before the next ordinary Turn is sent.

The source-level sequence is:

  1. A completed function response (for example, E3) is still unarchived and has a result larger than the archive threshold.
  2. Manual compactHistory() does not run tool-result pruning first. Its summarizer receives the current effective view of the covered events; if E3 has no earlier projection transition, that view includes the full E3 result. The successful checkpoint records coverage for that view.
  3. On the next Turn, prepareContextBudgetPolicy() runs pruneToolResults() before deciding whether to replay the checkpoint. If E3 is archived at this point, its effective representation changes to an archive placeholder.
  4. The checkpoint currency check rejects the checkpoint because its covered effective-history digest no longer matches. The next request is built without that checkpoint and from the effective event history, where E3 is now represented by the placeholder.

Thus the user can receive a successful manual-compaction result, but the very next Turn does not use that summary. This report concerns the cross-Turn sequence; it is not the already-fixed already_compacted fast-path defect from #5929, nor the stale-pruning replay-order defect from #3631.

Expected: a successful manual compaction should remain useful on the next Turn when the only intervening change is Maka's own archive projection of a covered tool result. The implementation should preserve checkpoint correctness while avoiding silently dropping the just-created summary (for example, by coordinating the archive transition and checkpoint, or explicitly rebuilding/replacing the checkpoint from the new effective view).

How to reproduce

Source-derived scenario; not yet reproduced in a live Desktop/TUI session:

  1. Have a completed session with an unarchived function_response whose serialized result exceeds READ_PAGE_MAX_BYTES (7,500 bytes). This can occur when the result predates pruning being enabled, or when no archive transition was committed at the time.
  2. Run /compact. Confirm it returns success and its checkpoint covers the large result.
  3. Start a new ordinary user Turn with tool-result pruning enabled and archive services available.
  4. Inspect the checkpoint decision and outgoing model history. If that Turn archives the covered result, the old checkpoint is rejected for effective-history drift; the outgoing history has no compact checkpoint block and uses the archive placeholder for that result.

Relevant source paths: AiSdkCompaction.compactHistory(), prepareContextBudgetPolicy(), and AiSdkTurn pre-send context preparation.

Environment

  • Maka version or commit: upstream main in the checked-out source at report time
  • Surface: Runtime; manual compaction exposed through Desktop/TUI
  • Reproduction status: source-path confirmed; no live-session reproduction yet

Logs, screenshots, or additional context

中文

发生了什么

手动 /compact 成功写入的 checkpoint,可能在下一次普通 Turn 发送前就失效。

按当前源码,时序如下:

  1. 已完成的工具响应(例如 E3)尚未归档,且结果大于归档阈值。
  2. 手动 compactHistory() 不会先执行工具结果裁剪。摘要器读取被覆盖事件当时的有效模型视图;如果 E3 尚无更早的投影转换,该视图就包含完整的 E3 结果。成功后 checkpoint 按这个视图记录覆盖范围。
  3. 下一次 Turn 开始时,prepareContextBudgetPolicy() 会先运行 pruneToolResults(),再判断是否重放 checkpoint。如果此时 E3 被归档,它的有效表示就变成归档占位符。
  4. checkpoint 的覆盖范围摘要指纹不再匹配,于是 checkpoint 被拒绝。下一次模型请求不带这个摘要块,而是根据有效事件历史构建;E3 在其中表现为归档占位符。

因此用户可能看到手动压缩成功,但紧接着的下一 Turn 并没有使用刚生成的摘要。本 issue 讨论的是跨 Turn 时序;它不同于已由 #5931 修复的 #5929(手动压缩快路径误报 already_compacted),也不同于 #3631 的旧 checkpoint 与过期裁剪顺序问题。

期望行为:如果下一 Turn 唯一的变化是 Maka 自己归档了 checkpoint 覆盖范围内的工具结果,刚成功的手动压缩仍应对下一 Turn 有效。实现需要在保持 checkpoint 正确性的同时,避免悄悄丢弃刚创建的摘要(例如协调归档转换与 checkpoint,或基于新的有效视图明确重建/替换 checkpoint)。

如何复现

以下是源码推导场景;尚未在真实 Desktop/TUI 会话中复现:

  1. 准备一个已完成会话,其中有尚未归档的 function_response,序列化结果超过 READ_PAGE_MAX_BYTES(7,500 字节)。例如该结果产生于启用裁剪之前,或当时没有成功提交归档转换。
  2. 执行 /compact,确认成功返回,且 checkpoint 覆盖了该大结果。
  3. 开始新的普通用户 Turn,并确保工具结果裁剪已启用、归档服务可用。
  4. 检查 checkpoint 决策和发出的模型历史。如果该 Turn 归档了被覆盖结果,旧 checkpoint 会因有效历史漂移而被拒绝;发出的历史不含该压缩 checkpoint 块,工具结果则显示为归档占位符。

相关源码路径:AiSdkCompaction.compactHistory()、prepareContextBudgetPolicy()、以及 AiSdkTurn 的发送前上下文准备。

环境

  • Maka 版本或提交:报告时检视的 checkout 对应 upstream main
  • 使用界面:Runtime;Desktop/TUI 暴露手动压缩入口
  • 复现状态:已确认源码路径,尚无真实会话复现

日志、截图或其他上下文


Drafted with AI-agent assistance from source inspection at the reporter's request; the reporter should review the issue after submission.

Activity

  1. self-assigned this
    on Oct 10, 2026
  2. ggbdpq commented on Oct 10, 2026

    @ggbdpq
    Contributor

    take

  3. github-actions commented on Oct 10, 2026

    @github-actions

    Issue #6048 is already assigned to me2seeks, so it was not reassigned.

  4. added a commit that references this issue on Oct 11, 2026
    a357fb5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions