Skip to content

refactor(runtime): centralize history-compact checkpoint currency validation (#5930) - #5965

Draft
Colafornia wants to merge 1 commit into
apache:mainfrom
Colafornia:refactor/5930-checkpoint-currency
Draft

Colafornia wants to merge 1 commit into
apache:mainfrom
Colafornia:refactor/5930-checkpoint-currency

Conversation

@Colafornia

Copy link
Copy Markdown
Member
English

Summary

Issue #5930 asks for one shared, directly testable decision for history-compaction checkpoint currency. Five call sites independently reassembled the two-layer rule — raw prefix identity plus a digest of the transition-folded effective view — with divergent snapshot timing and coverage; that duplication had already produced a live defect (#5929, fixed pointwise by #5931). This change moves the whole decision into checkHistoryCompactCheckpointCurrency in history-compact-checkpoint.ts, which takes the raw event list and a caller-supplied LoadedModelProjectionTransitions and returns current + match, raw_mismatch + reason, or effective_history_changed.

All five callers now consume it — the pre-send budget gate, the durable mid-turn projection, the roll-forward gate in planHistoryCompaction, conversation copy, and the manual fast path — and checkpointEffectiveCoverageMatches is deleted. Callers keep their own policy per outcome, and ledger-read timing is unchanged: the fast path still loads transitions only when the raw prefix can replay, and the planner loads one snapshot per pass through the new loadProjectionSnapshot input after a safe boundary exists. isHistoryCompactContentEvent moved beside the decision (re-exported from history-compaction.ts) so the module graph stays acyclic. Checkpoint structure, provider compatibility, and compaction trigger conditions are untouched.

Fixes #5930

Verification

  • npm --workspace @maka/runtime run build, typecheck for @maka/runtime and @maka/runtime-host: clean.
  • npm run lint, npm run format:check, npm run build (all workspaces): clean.
  • Runtime suites: focused compaction/copy/handoff suites (~990 tests) pass; full packages/runtime suite 3554/3561 — the 7 failures are filesystem-worker sandbox tests that fail identically on the unmodified base (environmental).
  • New coverage: 8 table-driven cases for the shared decision (raw mismatch, current + match, effective drift, missing effectiveSourceDigest, insufficient covered effective events, through-event miss, unreadable target, post-snapshot transition) plus a backend-level characterization test proving a covered-span transition committed after the fold drops the mid-turn block on the next request. Roll-forward tests now exercise real ModelProjectionTransitions instead of fake fold callbacks.
  • Not run: npx knip for apps/desktop / packages/ui (no changes in those scopes); no UI change.

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Devin (Cognition) implemented the refactor, tests, and verification end to end; the commit carries a Generated-by: Devin trailer.

Checklist

  • Tests cover the change and fail without it
  • Lint, format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No
中文

概要

Issue #5930 要求把历史压缩检查点的时效性判断收敛为一个共享、可直接测试的函数。此前五个调用点各自拼装同一套两层规则——原始前缀身份匹配,加上过渡折叠后有效视图的摘要比对——但快照时机与覆盖范围各不相同;这种重复已经造成过一个真实缺陷(#5929,由 #5931 点对点修复)。本次改动将整个判定收敛到 history-compact-checkpoint.ts 中的 checkHistoryCompactCheckpointCurrency:它接收原始事件列表与调用方提供的 LoadedModelProjectionTransitions,返回 current + match、raw_mismatch + reason 或 effective_history_changed。

五个调用点全部迁移——发送前预算门禁、持久化的回合内投影、planHistoryCompaction 的滚动前进门禁、会话复制以及手动压缩快速路径——并删除了 checkpointEffectiveCoverageMatches。各调用方保留对每种结果的处理策略,账本读取时机不变:快速路径仍只在原始前缀可重放时才加载过渡记录,规划器通过新的 loadProjectionSnapshot 输入在每个轮次内于安全边界存在后加载一次快照。isHistoryCompactContentEvent 移到判定函数所在模块(并从 history-compaction.ts 再导出),以保持模块图无环。检查点结构、provider 兼容性与压缩触发条件均未改动。

修复 #5930

验证

  • npm --workspace @maka/runtime run build、@maka/runtime 与 @maka/runtime-host 的 typecheck:通过。
  • npm run lint、npm run format:check、npm run build(全部 workspace):通过。
  • runtime 测试:聚焦的 compaction/copy/handoff 套件(约 990 个测试)全部通过;packages/runtime 全量套件 3554/3561——7 个失败为 filesystem-worker 沙箱测试,在未修改的基线上同样失败(环境问题)。
  • 新增覆盖:共享判定的 8 个表驱动用例(原始不匹配、current + match、有效视图漂移、缺少 effectiveSourceDigest、覆盖的有效事件不足、through 事件不符、不可读目标、快照之后才提交的过渡记录),另有一个后端级 characterization 测试,证明折叠之后才提交的覆盖区间过渡会在下一次请求时丢弃 mid-turn 检查点块。滚动前进测试改为使用真实的 ModelProjectionTransition,不再使用伪折叠回调。
  • 未运行:apps/desktop 与 packages/ui 的 npx knip(相关范围无改动);无 UI 改动。

AI 使用

仅选一项:

  • 没有生成式工具做出实质性贡献
  • 生成式工具做出了实质性贡献

工具与范围:Devin (Cognition) 端到端完成了本次重构、测试与验证;提交带有 Generated-by: Devin trailer。

检查清单

  • 测试覆盖本改动,且在缺少改动时会失败
  • Lint、format、typecheck 与受影响套件在本地通过

本 PR 是否包含行为变更?

  • 是——见上文概要
  • 否

…idation (apache#5930)

Five call sites independently assembled the two-layer currency rule — raw
prefix identity plus the effective, transition-folded digest pinned at
creation — with divergent snapshot timing and coverage. Centralize the
decision in checkHistoryCompactCheckpointCurrency, which takes the raw
event list and a caller-supplied LoadedModelProjectionTransitions and
returns current+match, raw_mismatch+reason, or effective_history_changed.

- prepareContextBudgetPolicy, loadDurableTurnProjection, planHistoryCompaction
  roll-forward, conversation-copy, and the manual fast path all consume it;
  checkpointEffectiveCoverageMatches is removed.
- Load points are preserved: the fast path still reads the ledger only when
  the raw prefix can replay, and the planner loads one snapshot per pass via
  loadProjectionSnapshot after a safe boundary exists.
- isHistoryCompactContentEvent moves beside the decision (re-exported from
  history-compaction) to keep the module graph acyclic.

Generated-by: Devin

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@github-actions github-actions Bot added the effort/L Under 1000 readable lines label Oct 4, 2026
@Colafornia
Colafornia marked this pull request as draft October 4, 2026 17:29

This branch has not been deployed

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

Labels

effort/L Under 1000 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(runtime): single owner for history-compact checkpoint currency

1 participant