openclaw - 💡(How to fix) Fix [Feature] Time-based session context window (send only recent N hours of conversation) [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#57894Fetched 2026-04-08 01:56:26
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Participants
RAW_BUFFERClick to expand / collapse

Problem

In long-running (endless) sessions, every request sends the full conversation history. This wastes tokens on stale context and can hit context limits, forcing users to manually run /new to start a fresh session just to shed old context.

Proposed Solution

Implement a configurable time-based session context window, similar to how Hermes Agent handles it — only include messages from the last N hours when building the prompt context for the AI.

  • Configurable per-agent setting (e.g. contextWindowHours: 4)
  • Default could be 0 (disabled, current behavior) or a sensible default like 4 hours
  • Older messages are excluded from the API request but remain in local session storage for search/memory tools
  • Works alongside existing context pruning and compaction — this would be a pre-prune filter at the session level
  • Should apply to all request types: user prompts, heartbeats, and cron-triggered turns

Use Case

Users who prefer endless sessions (no /new resets) but want to avoid paying for context they no longer need. A 4-hour rolling window keeps conversations fresh and token-efficient without losing the convenience of a persistent session.

Reference

Hermes Agent implements this with a default 4-hour conversation window. It works well in practice — old messages are still searchable via memory tools but are not sent as part of the active prompt context.

Alternatives Considered

  • Manual /new — works but loses session continuity and requires user discipline
  • Context pruning (contextPruning) — helps but still starts with full history before trimming; time-based exclusion avoids loading it at all
  • Compaction — summarizes old context but still costs tokens to maintain; time-based is cheaper (just skip)

extent analysis

Fix Plan

To implement a configurable time-based session context window, follow these steps:

  • Add a contextWindowHours setting to the agent configuration, with a default value (e.g., 4 hours).
  • Modify the session context builder to filter out messages older than the specified window.
  • Update the API request to only include the filtered context.

Example code (in JavaScript):

// Agent configuration
const agentConfig = {
  contextWindowHours: 4, // default value
};

// Session context builder
function buildContext(session) {
  const windowHours = agentConfig.contextWindowHours;
  const cutoffTime = Date.now() - (windowHours * 60 * 60 * 1000);
  const filteredContext = session.messages.filter((message) => message.timestamp >= cutoffTime);
  return filteredContext;
}

// API request
function sendRequest(context) {
  const prompt = {
    context: context,
  };
  // Send the request with the filtered context
}

Verification

To verify the fix, test the following scenarios:

  • Endless session with default contextWindowHours setting (e.g., 4 hours).
  • Endless session with custom contextWindowHours setting (e.g., 2 hours).
  • Session with manual /new reset.
  • Session with context pruning and compaction enabled.

Check that the API requests only include the filtered context and that older messages are excluded but still searchable via memory tools.

Extra Tips

  • Consider adding a contextWindowHours validation to ensure the value is a positive integer.
  • Make sure to update the documentation to reflect the new contextWindowHours setting and its default value.
  • Test the fix with different types of requests (user prompts, heartbeats, and cron-triggered turns) to ensure it works as expected.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING