openclaw/docs
Gustavo Madeira Santana e19a23520c
fix: unify session maintenance and cron run pruning (#13083)
* fix: prune stale session entries, cap entry count, and rotate sessions.json

The sessions.json file grows unbounded over time. Every heartbeat tick (default: 30m)
triggers multiple full rewrites, and session keys from groups, threads, and DMs
accumulate indefinitely with large embedded objects (skillsSnapshot,
systemPromptReport). At >50MB the synchronous JSON parse blocks the event loop,
causing Telegram webhook timeouts and effectively taking the bot down.

Three mitigations, all running inside saveSessionStoreUnlocked() on every write:

1. Prune stale entries: remove entries with updatedAt older than 30 days
   (configurable via session.maintenance.pruneDays in openclaw.json)

2. Cap entry count: keep only the 500 most recently updated entries
   (configurable via session.maintenance.maxEntries). Entries without updatedAt
   are evicted first.

3. File rotation: if the existing sessions.json exceeds 10MB before a write,
   rename it to sessions.json.bak.{timestamp} and keep only the 3 most recent
   backups (configurable via session.maintenance.rotateBytes).

All three thresholds are configurable under session.maintenance in openclaw.json
with Zod validation. No env vars.

Existing tests updated to use Date.now() instead of epoch-relative timestamps
(1, 2, 3) that would be incorrectly pruned as stale.

27 new tests covering pruning, capping, rotation, and integration scenarios.

* feat: auto-prune expired cron run sessions (#12289)

Add TTL-based reaper for isolated cron run sessions that accumulate
indefinitely in sessions.json.

New config option:
  cron.sessionRetention: string | false  (default: '24h')

The reaper runs piggy-backed on the cron timer tick, self-throttled
to sweep at most every 5 minutes. It removes session entries matching
the pattern cron:<jobId>:run:<uuid> whose updatedAt + retention < now.

Design follows the Kubernetes ttlSecondsAfterFinished pattern:
- Sessions are persisted normally (observability/debugging)
- A periodic reaper prunes expired entries
- Configurable retention with sensible default
- Set to false to disable pruning entirely

Files changed:
- src/config/types.cron.ts: Add sessionRetention to CronConfig
- src/config/zod-schema.ts: Add Zod validation for sessionRetention
- src/cron/session-reaper.ts: New reaper module (sweepCronRunSessions)
- src/cron/session-reaper.test.ts: 12 tests covering all paths
- src/cron/service/state.ts: Add cronConfig/sessionStorePath to deps
- src/cron/service/timer.ts: Wire reaper into onTimer tick
- src/gateway/server-cron.ts: Pass config and session store path to deps

Closes #12289

* fix: sweep cron session stores per agent

* docs: add changelog for session maintenance (#13083) (thanks @skyfallsin, @Glucksberg)

* fix: add warn-only session maintenance mode

* fix: warn-only maintenance defaults to active session

* fix: deliver maintenance warnings to active session

* docs: add session maintenance examples

* fix: accept duration and size maintenance thresholds

* refactor: share cron run session key check

* fix: format issues and replace defaultRuntime.warn with console.warn

---------

Co-authored-by: Pradeep Elankumaran <pradeepe@gmail.com>
Co-authored-by: Glucksberg <markuscontasul@gmail.com>
Co-authored-by: max <40643627+quotentiroler@users.noreply.github.com>
Co-authored-by: quotentiroler <max.nussbaumer@maxhealth.tech>
2026-02-09 20:42:35 -08:00
..
.i18n Docs: seed ja-JP translations 2026-02-08 10:18:04 -08:00
assets docs(onboarding): add bootstrapping page (#9767) 2026-02-05 12:08:35 -05:00
automation fix(cron): share isolated announce flow + harden cron scheduling/delivery (#11641) 2026-02-07 19:46:01 -08:00
channels Replace text diagrams with mermaid (#7165) 2026-02-09 10:27:27 -05:00
cli fix(discord): support forum channel thread-create (#10062) 2026-02-08 05:51:10 +00:00
concepts fix(memory): default batch embeddings to off 2026-02-09 22:31:58 -06:00
debug Docs: enable markdownlint autofixables except list numbering (#10476) 2026-02-06 10:08:59 -05:00
diagnostics Docs: add nav titles across docs (#5689) 2026-01-31 15:04:03 -06:00
experiments docs: canonicalize docs paths and align zh navigation (#11428) 2026-02-07 15:40:35 -05:00
gateway fix: unify session maintenance and cron run pruning (#13083) 2026-02-09 20:42:35 -08:00
help refactor: unify peer kind to ChatType, rename dm to direct (#11881) 2026-02-09 09:20:52 +09:00
hooks docs: canonicalize docs paths and align zh navigation (#11428) 2026-02-07 15:40:35 -05:00
images Channels: finish Feishu/Lark integration 2026-02-03 14:27:39 -08:00
install Simplify ownership commands in hetzner.md (#12703) 2026-02-09 10:02:54 -05:00
ja-JP docs: fix ja-JP dashboard URL link 2026-02-09 11:26:27 -06:00
nodes docs: add symptom-first troubleshooting hub and deep runbooks (#11196) 2026-02-07 10:28:19 -05:00
platforms chore(release): 2026.2.9 2026-02-09 11:19:07 -06:00
plugins docs: canonicalize docs paths and align zh navigation (#11428) 2026-02-07 15:40:35 -05:00
providers feat: adding support for Together ai provider (#10304) 2026-02-10 08:49:34 +09:00
refactor refactor: unify peer kind to ChatType, rename dm to direct (#11881) 2026-02-09 09:20:52 +09:00
reference Update contributing, deduplicate more functions 2026-02-09 19:21:33 -08:00
security Centralize date/time formatting utilities (#11831) 2026-02-08 04:53:31 -08:00
start Replace text diagrams with mermaid (#7165) 2026-02-09 10:27:27 -05:00
tools docs(subagents): simplify page and verify behavior/examples (#12761) 2026-02-09 11:50:53 -05:00
web docs: canonicalize docs paths and align zh navigation (#11428) 2026-02-07 15:40:35 -05:00
zh-CN docs: fix broken links checker and add CI docs (#13041) 2026-02-09 18:30:05 -08:00
CNAME refactor: rename to openclaw 2026-01-30 03:16:21 +01:00
brave-search.md Docs: enable markdownlint autofixables except list numbering (#10476) 2026-02-06 10:08:59 -05:00
ci.md docs: fix broken links checker and add CI docs (#13041) 2026-02-09 18:30:05 -08:00
date-time.md Docs: add nav titles across docs (#5689) 2026-01-31 15:04:03 -06:00
docs.json docs: fix broken links checker and add CI docs (#13041) 2026-02-09 18:30:05 -08:00
index.md Docs: enable markdownlint autofixables except list numbering (#10476) 2026-02-06 10:08:59 -05:00
logging.md Docs: add nav titles across docs (#5689) 2026-01-31 15:04:03 -06:00
network.md docs: canonicalize docs paths and align zh navigation (#11428) 2026-02-07 15:40:35 -05:00
perplexity.md Docs: enable markdownlint autofixables except list numbering (#10476) 2026-02-06 10:08:59 -05:00
pi-dev.md Docs: enable markdownlint autofixables except list numbering (#10476) 2026-02-06 10:08:59 -05:00
pi.md fix: align pi-coding-agent typings and docs 2026-02-01 16:08:01 -08:00
prose.md docs: canonicalize docs paths and align zh navigation (#11428) 2026-02-07 15:40:35 -05:00
style.css Docs: streamline start and install docs (#9648) 2026-02-05 10:09:45 -05:00
tts.md Docs: add nav titles across docs (#5689) 2026-01-31 15:04:03 -06:00
vps.md Docs: enable markdownlint autofixables except list numbering (#10476) 2026-02-06 10:08:59 -05:00
whatsapp-openclaw-ai-zh.jpg Docs: add zh-CN landing notice + AI image 2026-02-02 18:35:01 +01:00
whatsapp-openclaw.jpg refactor: rename to openclaw 2026-01-30 03:16:21 +01:00