-
-
Notifications
You must be signed in to change notification settings - Fork 80.7k
Feature: guarantee last N raw messages in agent context (survive compaction and session reset) #58818
Copy link
Copy link
Open
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.ClawSweeper marked this issue as needing security-sensitive review.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:securitySecurity boundary, credential, authz, sandbox, or sensitive-data risk.Security boundary, credential, authz, sandbox, or sensitive-data risk.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Description
Metadata
Metadata
Assignees
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.ClawSweeper marked this issue as needing security-sensitive review.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:securitySecurity boundary, credential, authz, sandbox, or sensitive-data risk.Security boundary, credential, authz, sandbox, or sensitive-data risk.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Type
Fields
Priority
None yet
Problem
When an agent wakes up in a session, its context window is built from the current session's JSONL transcript. Two mechanisms destroy or compress older messages:
sessionId→ the agent starts with zero messages. Previous conversation is gone from context entirely.This means the agent has no guarantee of seeing the last N actual messages from the conversation. A session that was active yesterday evening starts fresh at 4am with zero raw messages. A long-running session that compacted may have replaced recent-ish messages with a summary.
For personal assistant use cases (and many others), the agent needs continuity: the last N messages should always be present in the context window as raw messages, not summaries, regardless of when they were sent.
Desired Behavior
A configurable
session.minTailMessages(or similar) that guarantees the agent always sees at least the last N raw messages in its context window:Example
Compaction behavior change
Currently compaction summarizes everything older than the internal
keepRecentMessagesthreshold. With this feature:minTailMessagesacts as a floor: compaction must preserve at least N raw messagesReset behavior change
Currently, session reset = clean slate. With this feature:
/new), read the last N messages from the outgoing session's JSONLsession-memorydumpsConfiguration
Interaction with existing features
minTailMessagesensures it can read recent conversation. Both are needed.minTailMessagessets a floor on what compaction can touch. The existing compaction logic already has a concept of "recent messages to keep" — this makes it explicit and configurable.assemble()method should respectminTailMessagesas a contract. Plugins can exceed it but not go below.Why this matters
Personal assistants, coding agents, and any long-running agent benefit from conversational continuity. Today, the daily reset creates an artificial amnesia boundary that forces users to either:
minTailMessagesprovides a clean middle ground: bounded sessions with guaranteed recent context.Edge cases
/new: respectcarryForwardOnResetsetting (user might want a truly clean slate — could add/new --cleanto override)