Skip to content

[code-review] session time-windowed loading breaks checkpoint restoration — compacted context silently lost for >24h sessions #71

Description

@topcheer

File: internal/session/store.go
Lines: 795-805, 906
Severity: High

Problem

When fullLoad is false and a session has >500 messages, messages before the 24h cutoff are added to postCPEntries but excluded from allMessages (line 800 continue). The checkpoint summary search at line 906 searches allMessages, not postCPEntries. If the summary was written >24h ago, it's excluded, the checkpoint is silently ignored, and the agent receives raw messages instead of compacted context.

Trigger Scenario

  1. Long-running session accumulates 500+ messages over >24h
  2. Checkpoint compaction writes summary message + checkpoint record to JSONL
  3. User continues session, adding messages within last 24h
  4. On session reload: findMessageCutoff computes cutoff at lastMessageTime - 24h
  5. Summary message is before cutoff → excluded from allMessages
  6. Checkpoint record sets lastCpSummaryMsgID (no cutoff check on checkpoint records)
  7. Summary search at line 906 iterates allMessages → not found (summaryIdx = -1)
  8. Falls through to no-checkpoint path → agent gets raw recent messages instead of compacted context
  9. Comment at line 695 claims "ContextMessages is unaffected" — this is incorrect

Expected vs Actual

  • Expected: Checkpoint summary is found and used even if written >24h ago
  • Actual: Checkpoint is silently ignored; agent loses compacted context

Fix

Search for the summary message in postCPEntries (which contains all messages) instead of allMessages, or always include the summary message in allMessages regardless of cutoff.

Activity

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

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions