openclaw - 💡(How to fix) Fix Feature request: per-pattern session maintenance retention rules [1 comments, 2 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#50900Fetched 2026-04-08 01:06:45
View on GitHub
Comments
1
Participants
2
Timeline
1
Reactions
0
Participants
Timeline (top)
commented ×1

Currently session.maintenance.pruneAfter applies a single uniform age threshold to all session entries. This forces a compromise between aggressive cleanup of ephemeral sessions (cron runs, completed subagents) and conservative retention of interactive sessions (telegram topics, DM sessions).

Root Cause

Currently session.maintenance.pruneAfter applies a single uniform age threshold to all session entries. This forces a compromise between aggressive cleanup of ephemeral sessions (cron runs, completed subagents) and conservative retention of interactive sessions (telegram topics, DM sessions).

Fix Action

Fix / Workaround

Currently, the only workaround is external scripts that modify sessions.json and restart the gateway — which works but introduces concurrency concerns and unnecessary restarts.

  • External script + gateway restart (current workaround — works but inelegant)
  • Very short global pruneAfter (aggressive, risks pruning interactive sessions)
  • Very long global pruneAfter (conservative, ephemeral sessions accumulate)

Code Example

"session": {
  "maintenance": {
    "mode": "enforce",
    "pruneAfter": "14d",
    "rules": [
      { "match": "*:cron:*:run:*", "pruneAfter": "2d" },
      { "match": "*:subagent:*", "pruneAfter": "3d" }
    ]
  }
}
RAW_BUFFERClick to expand / collapse

Summary

Currently session.maintenance.pruneAfter applies a single uniform age threshold to all session entries. This forces a compromise between aggressive cleanup of ephemeral sessions (cron runs, completed subagents) and conservative retention of interactive sessions (telegram topics, DM sessions).

Proposed

Support per-pattern (or per-type) retention rules in session maintenance config:

"session": {
  "maintenance": {
    "mode": "enforce",
    "pruneAfter": "14d",
    "rules": [
      { "match": "*:cron:*:run:*", "pruneAfter": "2d" },
      { "match": "*:subagent:*", "pruneAfter": "3d" }
    ]
  }
}

Rules would be evaluated in order, first match wins. Sessions not matching any rule fall through to the global pruneAfter.

Use case

An OpenClaw instance running cron jobs (REM functions, email checker, browser reaper) accumulates ~70+ cron run sessions that have zero re-entrant value after completion. These clutter session management and waste storage. Meanwhile, telegram topic sessions and interactive sessions need longer retention for context continuity.

Currently, the only workaround is external scripts that modify sessions.json and restart the gateway — which works but introduces concurrency concerns and unnecessary restarts.

Alternatives considered

  • External script + gateway restart (current workaround — works but inelegant)
  • Very short global pruneAfter (aggressive, risks pruning interactive sessions)
  • Very long global pruneAfter (conservative, ephemeral sessions accumulate)

extent analysis

Fix Plan

To implement per-pattern retention rules in session maintenance config, follow these steps:

  • Update the session.maintenance configuration to include a rules array with pattern matching and custom pruneAfter values.
  • Modify the session pruning logic to evaluate the rules in order and apply the first matching rule.

Example configuration:

"session": {
  "maintenance": {
    "mode": "enforce",
    "pruneAfter": "14d",
    "rules": [
      { "match": "*:cron:*:run:*", "pruneAfter": "2d" },
      { "match": "*:subagent:*", "pruneAfter": "3d" }
    ]
  }
}

Example code snippet (in JavaScript) to evaluate the rules:

function evaluatePruneAfter(session, config) {
  const rules = config.session.maintenance.rules;
  for (const rule of rules) {
    if (session.pattern.match(rule.match)) {
      return rule.pruneAfter;
    }
  }
  return config.session.maintenance.pruneAfter;
}

Verification

To verify the fix, test the following scenarios:

  • Create a cron job session and verify it is pruned after 2 days.
  • Create a subagent session and verify it is pruned after 3 days.
  • Create an interactive session and verify it is pruned after the global pruneAfter period (14 days).

Extra Tips

  • Use a consistent naming convention for session patterns to ensure accurate matching.
  • Consider adding a default rule to handle unexpected session patterns.
  • Monitor session pruning activity to ensure the new rules are effective and adjust as needed.

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

openclaw - 💡(How to fix) Fix Feature request: per-pattern session maintenance retention rules [1 comments, 2 participants]