Skip to content

fix(runtime): replay history checkpoint before stale Tool Result pruning #3631

Closed

Description

@Astro-Han

What happened

A durable history-compaction checkpoint can replay successfully at first, then start failing on later turns with:

decision: failedOpen
failOpenReason: source_hash_mismatch

Desktop reports:

Context summary failed; the session continued without a new summary.

The summary request itself succeeded. The failure happens when replaying the checkpoint.

A Tool Result inside the checkpoint's covered prefix can move out of the minRecentTurnsFull window on a later turn. applyRuntimeEventContextBudget() currently applies stale Tool Result pruning before checkpoint replay. The original Tool Result is replaced with an archive placeholder, so checkpoint validation hashes a different representation from the one used to create the checkpoint.

The same checkpoint is retried on each turn, so the warning repeats.

How to reproduce

  1. Create a session containing an oversized Tool Result.
  2. Create a history-compaction checkpoint while that Tool Result is still protected by minRecentTurnsFull.
  3. Add enough turns for the covered Tool Result to become stale.
  4. Replay the checkpoint with a matching Tool Result archive ref.
  5. Observe source_hash_mismatch even though the underlying RuntimeEvents have not changed.

I observed this in two Desktop sessions. In one, the checkpoint replayed successfully before the archive placeholder count increased from 26 to 29. In another, it started failing after the count increased from 11 to 13.

Expected behavior

Checkpoint validation should use the immutable RuntimeEvents from which the checkpoint was created. Stale Tool Result pruning should only shape history that remains after checkpoint replay.

The narrow fix is to apply the checkpoint first, then prune the uncovered remainder. This issue does not include the larger archive design discussed in #3630.

Environment

  • Maka commit: eb2599255
  • OS: macOS 26.5.2
  • Surface: Desktop running from source
  • Node.js: v26.7.0

Related discussion

AI use

I used Maka to inspect the local Runtime database, trace the checkpoint and pruning paths, and prepare this report. I reviewed and approved the issue text.

Activity

  1. Astro-Han commented on Aug 23, 2026

    @Astro-Han
    ContributorAuthor

    I'd like to work on this. I will keep the PR limited to a regression test and the checkpoint/pruning order change. The event-log and ArchiveRead design from #3630 will remain separate.

    Posted by Maka at Yuhan's request.

  2. added
    bug
    on Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions