#Cronjob Session Pruning
1 messages · Page 1 of 1 (latest)
Yep, that’s possible, and it already has a separate knob.
Use cron.sessionRetention for isolated cron run sessions only. Keep your normal chat/session retention under session.maintenance.
{
cron: {
sessionRetention: "6h", // or "1h", "24h", "7d", false to disable
},
session: {
maintenance: {
mode: "enforce",
pruneAfter: "60d",
maxEntries: 1000,
},
},
}
A couple important details:
cron.sessionRetentiononly applies to completed isolated cron runs- it does not prune normal chat sessions
openclaw sessions cleanupis the broader session-store cleanup path, not the cron-specific one- cron run logs are separate, via
cron.runLog.maxBytesandcron.runLog.keepLines
So for your case, the pattern is:
- short
cron.sessionRetention - longer
session.maintenance.pruneAfter
If you’re still seeing week-over-week buildup, I’d check these first:
openclaw --version- confirm the jobs are really
--session isolated - confirm you didn’t set
cron.sessionRetention: false
Docs:
- https://docs.openclaw.ai/automation/cron-jobs
- https://docs.openclaw.ai/cli/cron
- https://docs.openclaw.ai/reference/session-management-compaction
If you want, paste your cron + session config block and I’ll sanity-check it.
after setting cron.sessionRetention what can i run to force a clean up. or how long do i need to wait to see results?
would that include sub agents the cron spawns? they do not seem to be getting removed.
{
"key": "agent:main:subagent:49a6a60e-4a4b-4930-87d9-5b4155b8e215",
"updatedAt": 1776487280012,
"ageMs": 25249165,
"sessionId": "b1398fdf-7c61-48b1-9349-4ae3168f817d",
"abortedLastRun": false,
"inputTokens": 26984,
"outputTokens": 108,
"totalTokens": 13677,
"totalTokensFresh": true,
"model": "removed",
"modelProvider": "removed",
"contextTokens": 200000,
"agentId": "main",
"kind": "direct"
}
Right, those are different.
cron.sessionRetention only cleans up cron run session keys, basically keys shaped like:
agent:<id>:cron:<jobId>:run:<uuid>
Your example is:
agent:main:subagent:49a6...
So no, cron.sessionRetention will not remove that.
For subagents, the knobs are:
agents.defaults.subagents.archiveAfterMinutes
default is 60cleanup: "delete"on thesessions_spawncall
which archives the child session immediately after completion
So if your cron jobs spawn helper subagents and you do not need to keep their session rows around, the best option is usually:
{
agents: {
defaults: {
subagents: {
archiveAfterMinutes: 15
}
}
}
}
or have the spawned subagents use:
cleanup: "delete"
One important caveat from the docs: subagent auto-archive is best effort, and pending archive timers can be lost on a gateway restart. In that case, old subagent rows can linger until broader session.maintenance cleanup catches them.
So short version:
- cron.sessionRetention → cron run sessions only
- subagent sessions →
archiveAfterMinutes/cleanup: "delete" openclaw tasks maintenance --applyis for task records, not these session rows
Docs:
- https://docs.openclaw.ai/tools/subagents
- https://docs.openclaw.ai/reference/session-management-compaction
- https://docs.openclaw.ai/automation/cron-jobs
If you want, paste one of the cron prompts or the sessions_spawn call shape and I can suggest the cleanest setup.
The agents.defaults.subagents.archiveAfterMinutes is set to 30 minutes.
but "openclaw sessions" shows hours old sessions
direct agent:main:subag...2e38d0 15h ago minimax/minimax-m2.5 16k/197k (8%) id:46c21ba9-c4a1-4cd2-8596-d82006201dbc
direct agent:main:subag...6fe043 15h ago minimax/minimax-m2.5 16k/197k (8%) id:66ac6b45-2d49-467f-bad0-be2788c878e9
direct agent:main:subag...1f4443 15h ago MiniMaxAI/MiniMax-M2.7 13k/200k (7%) id:d094428a-4a66-4610-b9b6-b4246504e14c
Yeah, that explains it.
Based on the current source, archiveAfterMinutes is not a blanket “remove all old subagent sessions from openclaw sessions” knob.
What it appears to do in practice:
- if the subagent was spawned with
cleanup: "delete", it gets a scheduledsessions.delete - if it was spawned with
cleanup: "keep"(the default), the runtime cleans up its internal run bookkeeping, but the session row stays insessions.json
So those 15h-old agent:main:subagent:... rows strongly suggest your cron-spawned subagents are being created with the default:
cleanup: "keep"
If you want them to disappear from openclaw sessions, spawn them like this:
{
cleanup: "delete"
}
So for cron-spawned one-shot helper agents, I’d recommend:
- keep your parent cron run isolated
- set spawned subagents to
cleanup: "delete"
One more caveat:
- even with delete-mode, auto-cleanup is still best-effort, and a gateway restart can interrupt pending timers
Also, what version are you on?
openclaw --version
If you want, paste one sessions_spawn(...) call from the cron flow and I’ll tell you exactly what to change.
If this fixed it, please right-click the solution message → Apps → ✅ Mark Solution. That helps Answer Overflow index it for the next person.
i launch subagents using regular words like this
Launch a subagent with this EXACT task:
"job description listed here" or an md file is passed in
Yep, that’s the gap.
If you say only:
Launch a subagent with this EXACT task...
you’re constraining the task text, but not the spawn options.
So the agent will usually do sessions_spawn(...) with the default:
cleanup: "keep"
That means the subagent session row sticks around.
If you want those cron-spawned helpers cleaned up, make the instruction explicit, for example: