You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by "me2seeks (via GitHub)" <gi...@apache.org> on 2026/09/05 09:21:02 UTC

[PR] fix(runtime): match history-compact checkpoints against the raw ledger prefix [maka]

me2seeks opened a new pull request, #4845:
URL: https://github.com/apache/maka/pull/4845

   ## Summary
   
   Fixes #4842.
   
   A history-compact checkpoint was pinned at creation over **raw** RuntimeEvents, but pre-turn replay matched it against the **transition-folded** view. Any durable stale tool-result archive transition (enabled by default) inside the covered prefix made the digest mismatch, so the replay silently failed open and the next request sent the full uncompacted history — the transcript showed "Context compacted." while ctx stayed pinned at 100%.
   
   Verified against a live session ledger: digest over the raw prefix matches the checkpoint exactly; over the folded prefix (6 transitions, 6 covered events rewritten) it reports `source_hash_mismatch`; the turn's own diagnostic recorded `decision: 'failedOpen', failOpenReason: 'source_hash_mismatch'` with `droppedEvents: 0`.
   
   ## Fix
   
   In `buildPriorMessages` (pre-turn replay):
   
   - match the durable checkpoint against the **raw** ledger prefix — the only view every creation path (standalone `compactHistory`, mid-turn state) hashes;
   - then fold the projected `[block, tail]` through `reduceEffectiveModelProjections` before materializing messages, preserving the #4283 invariant that the model never sees content a committed transition removed.
   
   This revives every existing raw-hashed checkpoint instead of orphaning them, and the pinned digest can no longer drift when a later transition commits (raw ledger rows are immutable).
   
   ## Tests
   
   New regression test in `ai-sdk-backend.test.ts`: seeds a real stale tool-result archive transition through a first send, runs standalone compaction, then asserts the next send replays through the checkpoint (summary block in the prompt, covered raw history absent). Fails without the fix, passes with it; stable across repeated full-suite runs.
   
   - `@maka/runtime` full dist suite: 3217 tests, 0 failures (3 runs)
   - typecheck + biome lint clean
   
   ## Notes
   
   - Orthogonal to #3029/#3041 (summary content validation) and #4634 (fail-open from the summarizer route on kimi-coding-plan) — this one is `source_hash_mismatch` at replay.
   - The fail-open note (`context_compaction_failed_open`) is only written at send settlement; a stop mid-turn hides it entirely. Left out of scope here, flagged in the issue.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] fix(runtime): match history-compact checkpoints against the raw ledger prefix [maka]

Posted by "jackwener (via GitHub)" <gi...@apache.org>.
jackwener commented on code in PR #4845:
URL: https://github.com/apache/maka/pull/4845#discussion_r3944546557


##########
packages/runtime/src/history-compaction.ts:
##########
@@ -308,18 +318,47 @@ export async function planHistoryCompaction(
     const checkpointMatch = input.previousCheckpoint
       ? matchHistoryCompactCheckpointPrefix(input.previousCheckpoint, coveredRuntimeEvents)
       : undefined;
-    const previousCheckpoint =
+    let previousCheckpoint =
       checkpointMatch && !checkpointMatch.reason ? input.previousCheckpoint : undefined;
+    // Content-currency gate for roll-forward: the inherited summary or
+    // provider state describes the EFFECTIVE view of the previous coverage at
+    // its own creation. A projection transition committed since rewrites that
+    // view without touching the raw prefix, and reusing the stale content here
+    // would launder it into the new checkpoint under the current effective
+    // digest — later replay guards would then pass it (#4845 review). On
+    // drift, discard the checkpoint and re-summarize the whole effective span.
+    if (previousCheckpoint && checkpointMatch && input.projectEffectiveCoverage) {

Review Comment:
   **The red `test` on this head is caused by this change, and here is the attribution.**
   
   `packages/runtime` fails one case — `persists the compaction fail-open note at decision time, before any settlement (#4850)` — at `ai-sdk-backend.test.js:4971`:
   
   ```
   + actual   'effective_history_changed'
   - expected 'coverage_miss'
   ```
   
   `effective_history_changed` is the fail-open reason this PR's roll-forward gate introduces. **So the failure is neither flaky nor inherited: the scenario that used to report `coverage_miss` now takes the new drift path and reports the new reason.** `desktop` passed 2331/2331; only `runtime` failed, which is the package this change touches.
   
   **Two readings, and they need different fixes — worth deciding explicitly rather than just making the suite green:**
   
   1. **The new reason is the more accurate one for that scenario.** Coverage did not miss; the effective history changed underneath a checkpoint that still matched on the raw prefix. If so, the #4850 test's expectation should be updated to the new reason, and that update is itself the record that this PR refined the vocabulary.
   2. **The gate is firing where a genuine `coverage_miss` should still be reported.** Then the drift check is over-triggering and masking a distinct failure behind a new label, and the fix belongs in the gate rather than in the test.
   
   **These are distinguishable**: the #4850 scenario is seeded deliberately, so whether its prefix genuinely drifted in the effective view is a fact about that fixture, not a judgement call.
   
   Worth saying plainly because it is easy to reach for the first reading: **changing an expectation to match new output is only correct once you have shown the new output is right.** A failing assertion that names a *different reason* for the same seeded scenario is exactly the shape that can hide a behaviour change behind a rename.
   
   <details><summary>简体中文</summary>
   
   **本 head 上那条红 `test` 是本次改动造成的,归因如下。**
   
   `packages/runtime` 有一条失败 —— `persists the compaction fail-open note at decision time, before any settlement (#4850)` —— 位于 `ai-sdk-backend.test.js:4971`:
   
   ```
   + 实际   'effective_history_changed'
   - 期望   'coverage_miss'
   ```
   
   **`effective_history_changed` 正是本 PR 的 roll-forward 闸门新引入的 fail-open 原因。** 所以这条失败**既不是偶发,也不是继承来的**:原本报 `coverage_miss` 的那个场景,现在走了新的漂移分支、报了新的原因。`desktop` 2331/2331 全过,**只有 `runtime` 失败,而那正是本次改动所在的包。**
   
   **有两种读法,对应的修法不同 —— 值得明确判定,而不是先把套件弄绿:**
   
   1. **对该场景而言,新原因才是更准确的那个。** 覆盖并没有落空,而是**在一个仍按 raw 前缀匹配成功的 checkpoint 之下,effective 历史发生了变化**。若是如此,应更新 #4850 那条测试的期望值,**而这次更新本身就是「本 PR 细化了这个词表」的记录。**
   2. **闸门在本该仍报 `coverage_miss` 的地方触发了。** 那么漂移检查就是**触发过度**,把一个本来不同的失败藏在了新标签后面,**修法应落在闸门而不是测试上。**
   
   **这两者是可区分的**:#4850 的场景是刻意构造的,所以「它的前缀在 effective 视图下是否真的漂移了」是关于那个夹具的事实,不是判断题。
   
   有一句值得直说,因为很容易顺手取第一种读法:**把期望值改成与新输出一致,只有在你已经证明新输出是对的之后才成立。** 一条对**同一个刻意构造的场景**给出**不同原因**的失败断言,**恰恰是「用改名掩盖行为变化」最容易发生的形状。**
   
   </details>
   
   ---
   
   > **Automated review notice:** This comment was posted by an automated review agent operated by jackwener. It is not an independent human review and does not replace one.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] fix(runtime): match history-compact checkpoints against the raw ledger prefix [maka]

Posted by "me2seeks (via GitHub)" <gi...@apache.org>.
me2seeks commented on PR #4845:
URL: https://github.com/apache/maka/pull/4845#issuecomment-5551094200

   Thanks — both P1s addressed in `dfd53e950b`:
   
   **Finding 1 (summary as restoration authority):** creation still pins coverage identity on the raw prefix (the immutable view both match sites share), but the summarizer now reads the **effective, transition-folded** prefix on both creation paths (standalone `compactHistory` and the mid-turn fold). An echoing-summarizer regression proves the checkpoint block and the next provider prompt carry the archive placeholder, never the transitioned body. Because v2-policy checkpoints were never audited for this, `HISTORY_COMPACT_SOURCE_POLICY_VERSION` moves to v3: existing v2 checkpoints are superseded on load (not corrupt — the session re-summarizes instead of replaying an unverified summary).
   
   **Finding 2 (unreadable targets):** `foldEffectiveModelHistory` now forwards `loaded.unreadableTargets` into the reducer and only fast-paths when both collections are empty, so the post-match fold of `[block, tail]` withholds the body behind the projection-failure sentinel exactly like the pre-match fold. Covered by a pre-turn replay regression with `unreadableTargets = {'<event>::tool_result'}`.
   
   Both new regressions fail without these changes and pass with them; full `@maka/runtime` suite 3219/3219, runtime-host 1698, storage 1128, core 824 — all green; typecheck + biome clean.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] fix(runtime): match history-compact checkpoints against the raw ledger prefix [maka]

Posted by "me2seeks (via GitHub)" <gi...@apache.org>.
me2seeks commented on PR #4845:
URL: https://github.com/apache/maka/pull/4845#issuecomment-5560456577

   Thanks @Astro-Han — the roll-forward P1 is addressed in `2714fb72cf`:
   
   **Finding (roll-forward launders stale content):** `planHistoryCompaction` now validates the previous checkpoint's pinned `coverage.effectiveSourceDigest` against the current effective view of ITS covered span (folded through the same `projectEffectiveCoverage` hook) before any inheritance. On drift the checkpoint is discarded entirely: the summarizer receives no `previousCheckpoint` (so `history-compact-summarizer` cannot prepend the stale text), the codex path receives no stale V3 provider state, the whole current effective prefix is re-summarized, and the new checkpoint records no `previousCheckpointId` lineage — nothing stale is carried under the new effective digest. The gate sits in the planner, so the standalone, pre-turn, and mid-turn creation paths all share it.
   
   **Regressions** (`history-compaction.test.ts`):
   - `discards a previous checkpoint whose effective coverage drifted before roll-forward`: first fold covers through `res-a` with the clean view pinned; a cross-turn transition then archives `res-a` inside that coverage; the second fold must discard the checkpoint, re-summarize the full effective span, and record no lineage. Control: fails without the gate (stale checkpoint inherited).
   - `keeps rolling forward when the effective coverage is unchanged`: the unchanged-view direction still rolls forward (only the new span summarized, lineage recorded).
   
   Full `@maka/runtime` suite green (3215 pass / 0 fail, 7 pre-existing platform skips), typecheck + biome clean.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] fix(runtime): match history-compact checkpoints against the raw ledger prefix [maka]

Posted by "M4n5ter (via GitHub)" <gi...@apache.org>.
M4n5ter commented on code in PR #4845:
URL: https://github.com/apache/maka/pull/4845#discussion_r3940185672


##########
packages/runtime/src/ai-sdk-turn.ts:
##########
@@ -2836,8 +2836,18 @@ export class AiSdkTurn {
       this.deps.backend.modelId,
     );
     let contextBudget = preparedContextBudget.policy;
-    const budgeted = applyRuntimeEventContextBudget(priorRuntimeContext, contextBudget);
-    let runtimeContext = budgeted?.events ?? priorRuntimeContext;
+    // Match the durable checkpoint against the RAW ledger prefix: every
+    // creation path (standalone compactHistory and the mid-turn state) pins
+    // its coverage digest on raw events, so matching the folded view here
+    // lets any durable projection transition inside the covered prefix orphan
+    // the checkpoint and silently fail open into a full-history replay
+    // (#4842). The projected [block, tail] is then folded through the
+    // transition reducer before it becomes messages, so a committed
+    // transition still cannot resurrect content for the model (#4283).
+    const budgeted = applyRuntimeEventContextBudget(rawPriorRuntimeContext, contextBudget);

Review Comment:
   [P1] Do not make a raw-derived checkpoint authoritative after a projection transition. Both checkpoint creation paths still summarize raw RuntimeEvents; the standalone path even exposes them as `source.foldedRuntimeEvents`. I changed this regression's summarizer to echo a real stale Tool Result that had already been archived by a durable transition. On this head, the next provider prompt replayed that value inside the checkpoint block; with only these two changed replay lines restored to the base ordering, the checkpoint failed open and the prompt contained only the archived placeholder. This therefore turns an existing raw-created checkpoint into a persistent content-restoration authority, contrary to the invariant that compaction must consume effective model history. Please separate immutable coverage identity from model-visible summary input (or version the checkpoint contract), make new standalone and mid-turn summaries consume the effective prefix, and add an echoing-result r
 egression that proves later prompts cannot restore the transitioned body.



##########
packages/runtime/src/ai-sdk-turn.ts:
##########
@@ -2836,8 +2836,18 @@ export class AiSdkTurn {
       this.deps.backend.modelId,
     );
     let contextBudget = preparedContextBudget.policy;
-    const budgeted = applyRuntimeEventContextBudget(priorRuntimeContext, contextBudget);
-    let runtimeContext = budgeted?.events ?? priorRuntimeContext;
+    // Match the durable checkpoint against the RAW ledger prefix: every
+    // creation path (standalone compactHistory and the mid-turn state) pins
+    // its coverage digest on raw events, so matching the folded view here
+    // lets any durable projection transition inside the covered prefix orphan
+    // the checkpoint and silently fail open into a full-history replay
+    // (#4842). The projected [block, tail] is then folded through the
+    // transition reducer before it becomes messages, so a committed
+    // transition still cannot resurrect content for the model (#4283).
+    const budgeted = applyRuntimeEventContextBudget(rawPriorRuntimeContext, contextBudget);
+    let runtimeContext = await this.deps.compaction.foldEffectiveModelHistory(

Review Comment:
   [P1] Preserve scoped unreadable-target withholding in this second fold. `prepareContextBudgetPolicy()` correctly passes `loaded.unreadableTargets` to the reducer, which replaces a target with the safe projection-failure sentinel because an undecodable record may be the record that removed its raw body. This new path discards that result and refolds from raw through `foldEffectiveModelHistory()`, whose fast path and reducer call both ignore `unreadableTargets`. A backend-level probe with `unreadableTargets = {'rt-result::tool_result'}` therefore sent the raw sentinel value to the provider on this head; the base ordering and a minimal mutation that forwards the set both withheld it. Please make this helper carry `loaded.unreadableTargets` (and only fast-path when both collections are empty), then cover the pre-turn call site rather than only the reducer.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] fix(runtime): match history-compact checkpoints against the raw ledger prefix [maka]

Posted by "me2seeks (via GitHub)" <gi...@apache.org>.
me2seeks commented on PR #4845:
URL: https://github.com/apache/maka/pull/4845#issuecomment-5560315542

   Thanks @Astro-Han — the post-creation drift finding and its V3 extension are addressed in `157a0af3bd`:
   
   **Finding (checkpoint survives later transitions):** replay is now bound to the covered prefix's EFFECTIVE digest, not only the raw one. Creation folds the covered span once through a new `projectEffectiveCoverage` planner hook: the summarizer (and the codex provider request) reads that effective view, and its digest is pinned as `coverage.effectiveSourceDigest`. Pre-turn replay (`prepareContextBudgetPolicy`) recomputes the effective digest over the folded prefix and rejects the checkpoint on drift — fail-open with an `effective_history_changed` diagnostic, so the stale block never materializes and the next fold re-summarizes. The raw identity match stays as the separate boundary/identity gate at apply time. Shape validation now requires the digest on any checkpoint under the current (v3) source policy.
   
   **Finding (V3 provider checkpoints):** V3 state is covered structurally by the same gate — the provider checkpoint carries the same coverage with the pinned effective digest, so a post-creation transition excludes it at load and the `openai.compaction` message is never materialized. The same-turn durable projection path got the matching guard too: on effective drift it replays the current-turn events without the stale block instead of throwing, letting overflow recovery re-fold.
   
   **Regression:** `a transition committed after creation invalidates the checkpoint at pre-turn replay (#4845 review)` in `ai-sdk-backend.test.ts` — checkpoint minted over the clean view (echo summary legitimately quotes the body), a later turn's stale prune commits the transition, and the next send must fail open to the effective history (placeholder visible, summary and transitioned body absent) with the `effective_history_changed` decision on the token-usage diagnostic. Control: the probe fails without the replay gate (stale summary replays, no placeholder).
   
   Full `@maka/runtime` suite green (3213 pass / 0 fail, 7 pre-existing platform skips), typecheck + biome clean.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] fix(runtime): match history-compact checkpoints against the raw ledger prefix [maka]

Posted by "me2seeks (via GitHub)" <gi...@apache.org>.
me2seeks merged PR #4845:
URL: https://github.com/apache/maka/pull/4845


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org