fix(cron): guard against undefined sessionTarget in startsWith calls#63402
fix(cron): guard against undefined sessionTarget in startsWith calls#63402arbaleast wants to merge 1 commit intoopenclaw:mainfrom
Conversation
Fixes TypeError: Cannot read properties of undefined (reading 'startsWith') when a cron job has payload.kind='agentTurn' but is missing sessionTarget. Adds null-safe operator in: - src/cron/delivery-plan.ts (resolveCronDeliveryPlan) - src/gateway/server-cron.ts (runIsolatedAgentJob) Fixes openclaw#63383
Greptile SummaryThis PR adds optional chaining guards at two Confidence Score: 5/5Safe to merge — the changes are minimal, targeted, and correctly prevent a crash without altering any other behavior. Both changes are correct: the delivery-plan.ts guard evaluates to false when sessionTarget is undefined, keeping isIsolatedAgentTurn false and the delivery mode as none. The server-cron.ts guard is safe because the if body (which calls .slice(8)) is only entered when startsWith returned true, proving sessionTarget is defined. No P0/P1 findings. No files require special attention.
|
|
+1 — confirmed exposure. We run scheduled cron jobs on 4 OpenClaw 2026.4.5 agents (AI news delivery, regulation report sync, file scanner) with We've separately seen the Good fix — optional chaining here is the right approach. Environment: 4 sandboxes, OpenClaw 2026.4.5, multiple cron jobs with exec tools (Typst, TTS). |
Bug
Cron jobs crash with
TypeError: Cannot read properties of undefined (reading 'startsWith')whenpayload.kind='agentTurn'butsessionTargetis missing.Root Cause
Two call sites in the cron runtime assume
job.sessionTargetis always defined:src/cron/delivery-plan.ts—job.sessionTarget.startsWith("session:")src/gateway/server-cron.ts—job.sessionTarget.startsWith("session:")Fix
Add optional chaining + nullish coalescing:
job.sessionTarget?.startsWith("session:") ?? falseFixes #63383