Skip to content

Cron sessions not closing after agent turn completes #12374

@marcomarandiz

Description

@marcomarandiz

Cron sessions not closing after agent turn completes

Summary:
Cron job sessions remain open indefinitely after the agent completes its turn, instead of auto-closing when the work is done.

Steps to reproduce:

  1. Configure a cron job with agentTurn payload
  2. Let it run (agent completes turn successfully in ~1-2 seconds)
  3. Observe session remains open for 30+ minutes with no activity

Expected behavior:
Session should auto-close after the agent's turn completes.

Actual behavior:
Session stays open indefinitely until manually killed or health monitor detects inactivity.

Example:

{
  "schedule": { "kind": "cron", "expr": "*/5 * * * *" },
  "sessionTarget": "isolated",
  "payload": {
    "kind": "agentTurn",
    "message": "Read HEARTBEAT.md if it exists..."
  }
}

Observed pattern:

  1. Gateway spawns cron session → agent turn executes
  2. Agent completes turn successfully (~1.3s runtime)
  3. Gateway writes final assistant message to JSONL
  4. Session should close but stays open
  5. Session sits idle for 30+ minutes (no new messages, no activity)
  6. Eventually killed by external health monitor

Impact:

  • Resource leak (sessions accumulate over time)
  • Requires external cleanup to prevent session buildup
  • Affects all agentTurn cron jobs

OpenClaw version:
Commit: bc475f0 (backup-before-sync-20260208)

Workaround:
Add timeoutSeconds to payload forces session closure, but this is a hard timeout rather than proper cleanup.

Logs:
Session logs show clean completion (exit/finish message), but session lifecycle doesn't close the session file or remove from active 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