openclaw - ✅(Solved) Fix systemEvent cron jobs fail with TypeError: Cannot read properties of undefined (reading 'trim') [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#52804Fetched 2026-04-08 01:19:09
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
0
Timeline (top)
commented ×1cross-referenced ×1

Error Message

TypeError: Cannot read properties of undefined (reading 'trim')

Fix Action

Workaround

None known. Moving to isolated session with agentTurn works but loses channel context (WeChat delivery requires main session).

PR fix notes

PR #52858: [Bug] Fix legacy systemEvent cron payloads loaded with message instead of text

Description (problem / solution / changelog)

Summary

Fix main-session cron jobs that load legacy systemEvent payloads stored as payload.message instead of payload.text.

Without this, those jobs can hit undefined.trim() during execution and fail immediately instead of enqueueing the system event.

Fixes: https://github.com/openclaw/openclaw/issues/52804

What changed

  • normalize legacy systemEvent.message payloads into canonical text
  • keep a defensive runtime fallback when reading persisted cron payloads
  • add regression tests for store migration and execution of legacy-loaded jobs
  • track migrated legacy systemEvent.message payloads in store issue reporting

Testing

  • corepack pnpm test -- src/cron/normalize.test.ts src/cron/store-migration.test.ts src/cron/service.store-load-invalid-main-job.test.ts src/cron/service.store.migration.test.ts

Changed files

  • src/cron/normalize.ts (modified, +16/-0)
  • src/cron/service.store-load-invalid-main-job.test.ts (modified, +56/-0)
  • src/cron/service/normalize.ts (modified, +3/-1)
  • src/cron/store-migration.test.ts (modified, +23/-0)
  • src/cron/store-migration.ts (modified, +15/-0)

Code Example

TypeError: Cannot read properties of undefined (reading 'trim')

---

{
  "id": "254045f3-1b09-4b1e-a88b-92ef85308fa1",
  "name": "morning-news",
  "sessionTarget": "main",
  "payload": {
    "kind": "systemEvent",
    "message": "晨间新闻提醒"
  }
}
RAW_BUFFERClick to expand / collapse

Bug Description

Cron jobs with sessionTarget: 'main' and payload.kind: 'systemEvent' fail with the error:

TypeError: Cannot read properties of undefined (reading 'trim')

This affects the built-in morning-news and evening-news cron jobs. The error occurs immediately (duration 1ms) indicating a code path failure rather than a timeout.

Environment

  • OpenClaw: 2026.3.13
  • Channel: stable
  • OS: Linux 6.8.0
  • Node: v22.22.0
  • Deploy type: VPS (Gateway only, no local UI)

Cron Job Config

{
  "id": "254045f3-1b09-4b1e-a88b-92ef85308fa1",
  "name": "morning-news",
  "sessionTarget": "main",
  "payload": {
    "kind": "systemEvent",
    "message": "晨间新闻提醒"
  }
}

Expected Behavior

systemEvent jobs targeting the main session should fire normally and deliver the message.

Actual Behavior

  • Status: error
  • Duration: 1ms (instant failure)
  • Error: TypeError: Cannot read properties of undefined (reading 'trim')

Workaround

None known. Moving to isolated session with agentTurn works but loses channel context (WeChat delivery requires main session).

Related

  • Root session can receive and deliver messages normally
  • Gateway is functional (RPC reachable from local)
  • Isolated agentTurn cron jobs execute correctly

extent analysis

Fix Plan

The fix involves modifying the cron job handler to properly handle sessionTarget: 'main' and payload.kind: 'systemEvent'.

  • Update the cron job handler to check if the payload object has a message property before attempting to trim it.
  • Add a null check for the message property to prevent the TypeError.

Example code snippet:

// In the cron job handler function
if (payload.kind === 'systemEvent' && payload.message) {
  const trimmedMessage = payload.message.trim();
  // Proceed with the trimmed message
} else {
  // Handle the case where message is undefined or console.error('Message is undefined or null');
}

Verification

To verify the fix, run the morning-news and evening-news cron jobs again and check for any errors. The jobs should now complete successfully without throwing a TypeError.

Extra Tips

  • Make sure to test the cron jobs with different types of payloads to ensure the fix is robust.
  • Consider adding additional logging to help diagnose any future issues with the cron job handler.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix systemEvent cron jobs fail with TypeError: Cannot read properties of undefined (reading 'trim') [1 pull requests, 1 comments, 2 participants]