Skip to content

Cron sessions with deleteAfterRun: true not being deleted — causes context overflow #67718

@clawdieclawdita

Description

@clawdieclawdita

Summary

Cron jobs configured with sessionTarget: "isolated" and deleteAfterRun: true are not being deleted after execution. Sessions accumulate in sessions.json, inherit context from previous runs, and eventually overflow with Context overflow: prompt too large for the model.

This breaks all cron-based automation: backups, health checks, scheduled tasks.

Environment

  • OpenClaw version: 2026.4.12
  • Platform: Linux x64
  • Node: v24.14.0

Cron Configuration

All jobs configured with:

{
  "sessionTarget": "isolated",
  "deleteAfterRun": true
}

Example jobs (various intervals):

  • Health check — every 6h
  • Session cleanup — every 1d
  • Skill updates — every 1d
  • Daily backup — every 1d

Expected Behavior

With deleteAfterRun: true:

  1. Cron job creates an isolated session key
  2. Cron job executes its payload
  3. Session entry is removed from sessions.json after execution
  4. No accumulation across runs

Actual Behavior (Bug)

  1. Cron job creates an isolated session key
  2. Cron job executes its payload
  3. Session entry remains in sessions.json after execution
  4. Sessions accumulate over time
  5. Each cron run loads history from previous cron sessions
  6. Context grows until overflow:
Context overflow: prompt too large for the model

Evidence

Session Accumulation

From the agent's sessions.json, cron sessions persist and accumulate:

Total sessions: 10

Cron sessions (not being deleted):
agent:<agent-id>:cron:<uuid>:run:<uuid>  (×6 entries)

Cron Job State

{
  "lastRunStatus": "ok",
  "lastStatus": "ok",
  "lastDelivered": true,
  "lastDeliveryStatus": "delivered",
  "consecutiveErrors": 0
}

Jobs complete successfully — but sessions are never cleaned up.

Related Version Notes

2026.4.14

2026.4.12 (Current)

  • No sessionTarget: "ephemeral" support
  • deleteAfterRun: true for cron sessions is not working

Impact

  • All cron automation broken
  • Cron jobs fail repeatedly with context overflow
  • Manual session cleanup required
  • Cannot schedule reliable automated tasks
  • Daily backups, health checks, and maintenance all failing

Workarounds

Manual Session Cleanup

# Remove cron sessions from sessions.json
python3 -c "
import json
sessions = json.load(open('sessions.json'))
sessions = {k: v for k, v in sessions.items() if 'cron:' not in k}
json.dump(sessions, open('sessions.json', 'w'), indent=2)
"

Periodic Reset

Running /reset on cron job sessions — temporary, not sustainable.

Additional Error

Gateway logs also show:

request handler failed: TypeError: Cannot read properties of undefined (reading 'startsWith')

This occurred when trying to manage cron jobs via CLI, suggesting broader cron system instability.

Recommendations

  1. Fix deleteAfterRun: true for cron sessions — ensure sessions are removed after execution
  2. Backport sessionTarget: "ephemeral" to 2026.4.12 — or provide it in a patch release
  3. Add automatic cron session cleanup — configurable retention for orphaned cron sessions

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