refactor(runtime): centralize history-compact checkpoint currency validation (#5930) - #5965
Draft
Colafornia wants to merge 1 commit into
Draft
Colafornia wants to merge 1 commit into
Colafornia wants to merge 1 commit into
Conversation
…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>
Colafornia
marked this pull request as draft
October 4, 2026 17:29
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
checkHistoryCompactCheckpointCurrencyinhistory-compact-checkpoint.ts, which takes the raw event list and a caller-suppliedLoadedModelProjectionTransitionsand returnscurrent+ match,raw_mismatch+ reason, oreffective_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 — andcheckpointEffectiveCoverageMatchesis 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 newloadProjectionSnapshotinput after a safe boundary exists.isHistoryCompactContentEventmoved beside the decision (re-exported fromhistory-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,typecheckfor@maka/runtimeand@maka/runtime-host: clean.npm run lint,npm run format:check,npm run build(all workspaces): clean.packages/runtimesuite 3554/3561 — the 7 failures are filesystem-worker sandbox tests that fail identically on the unmodified base (environmental).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 realModelProjectionTransitions instead of fake fold callbacks.npx knipforapps/desktop/packages/ui(no changes in those scopes); no UI change.AI use
Select exactly one:
Tool(s) and scope: Devin (Cognition) implemented the refactor, tests, and verification end to end; the commit carries a
Generated-by: Devintrailer.Checklist
Does this PR entail a change in behavior?
中文
概要
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):通过。packages/runtime全量套件 3554/3561——7 个失败为 filesystem-worker 沙箱测试,在未修改的基线上同样失败(环境问题)。effectiveSourceDigest、覆盖的有效事件不足、through 事件不符、不可读目标、快照之后才提交的过渡记录),另有一个后端级 characterization 测试,证明折叠之后才提交的覆盖区间过渡会在下一次请求时丢弃 mid-turn 检查点块。滚动前进测试改为使用真实的ModelProjectionTransition,不再使用伪折叠回调。apps/desktop与packages/ui的npx knip(相关范围无改动);无 UI 改动。AI 使用
仅选一项:
工具与范围:Devin (Cognition) 端到端完成了本次重构、测试与验证;提交带有
Generated-by: Devintrailer。检查清单
本 PR 是否包含行为变更?