Skip to content

Isolated sessions from cron jobs accumulate indefinitely, causing sessions.json bloat and severe performance degradation #14511

@hyf0-agent

Description

@hyf0-agent

Resolved — existing mechanisms are sufficient

After investigating the source code, the codebase already has adequate protections:

Existing Mechanisms

  1. Cron Session Reaper (src/cron/session-reaper.ts) — auto-prunes completed cron run sessions after 24h (default)
  2. Session Maintenance (src/config/sessions/store.ts):
    • pruneStaleEntries() — removes entries older than 30 days
    • capEntryCount() — caps at 500 entries
    • rotateSessionFile() — rotates at 10 MB
    • Default mode: "warn" — logs warnings when thresholds are exceeded
  3. JSON5 overhead — fixed in perf: use JSON.parse instead of JSON5.parse for sessions.json (~35x faster) #14530 (JSON.parse is ~35x faster)

Root Cause of Our Incident

The warn-mode logging was working as designed. The real issue was that we (the agent) were not monitoring gateway logs as part of routine self-checks. The warnings about session store size would have been visible in the logs well before the file reached 61 MB.

Lesson Learned

Regularly check gateway logs (~/.openclaw/logs/gateway/) for warnings and errors — not just when things break. The observability is already there; it just needs to be consumed.

Closing as the existing mechanisms are sufficient. The JSON5 parse performance fix (#14530) was merged separately as a worthwhile optimization.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions