From 9b38606d5c1f8d4fdee007fe69b6d770d8e5a990 Mon Sep 17 00:00:00 2001 From: Ayaan Zaidi Date: Sun, 19 Apr 2026 23:07:30 +0530 Subject: [PATCH] fix(gateway): preserve cron delivery validation behavior --- src/cron/service-contract.ts | 1 + src/cron/service.ts | 4 ++++ src/gateway/server-methods/cron.ts | 15 ++++++++++----- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/cron/service-contract.ts b/src/cron/service-contract.ts index ee119e2e029..81f47d5018d 100644 --- a/src/cron/service-contract.ts +++ b/src/cron/service-contract.ts @@ -51,5 +51,6 @@ export interface CronServiceContract { run(id: string, mode?: CronRunMode): Promise; enqueueRun(id: string, mode?: CronRunMode): Promise; getJob(id: string): CronJob | undefined; + getDefaultAgentId(): string | undefined; wake(opts: { mode: CronWakeMode; text: string }): CronWakeResult; } diff --git a/src/cron/service.ts b/src/cron/service.ts index e1fa82d7cf3..00ee049d005 100644 --- a/src/cron/service.ts +++ b/src/cron/service.ts @@ -70,6 +70,10 @@ export class CronService implements CronServiceContract { return this.state.store?.jobs.find((job) => job.id === id); } + getDefaultAgentId(): string | undefined { + return this.state.deps.defaultAgentId; + } + wake(opts: { mode: "now" | "next-heartbeat"; text: string }) { return ops.wakeNow(this.state, opts); } diff --git a/src/gateway/server-methods/cron.ts b/src/gateway/server-methods/cron.ts index d2f124ed569..0e165a81143 100644 --- a/src/gateway/server-methods/cron.ts +++ b/src/gateway/server-methods/cron.ts @@ -1,4 +1,3 @@ -import { resolveDefaultAgentId } from "../../agents/agent-scope.js"; import { listPotentialConfiguredChannelIds } from "../../channels/config-presence.js"; import { loadConfig } from "../../config/config.js"; import type { OpenClawConfig } from "../../config/types.openclaw.js"; @@ -29,6 +28,12 @@ import { } from "../protocol/index.js"; import type { GatewayRequestHandlers } from "./types.js"; +function listConfiguredAnnounceChannelIds(cfg: OpenClawConfig): string[] { + return listPotentialConfiguredChannelIds(cfg, process.env, { + includePersistedAuthState: false, + }).filter((channelId) => cfg.channels?.[channelId]?.enabled !== false); +} + function assertConfiguredAnnounceChannel(params: { cfg: OpenClawConfig; channel?: string; @@ -38,9 +43,7 @@ function assertConfiguredAnnounceChannel(params: { return; } - const configuredChannels = listPotentialConfiguredChannelIds(params.cfg, process.env, { - includePersistedAuthState: false, - }).toSorted(); + const configuredChannels = listConfiguredAnnounceChannelIds(params.cfg).toSorted(); const normalizedChannel = normalizeMessageChannel(params.channel); if (!normalizedChannel) { if (configuredChannels.length <= 1) { @@ -90,6 +93,7 @@ function assertValidCronCreateDelivery(cfg: OpenClawConfig, jobCreate: CronJobCr function assertValidCronUpdateDelivery(params: { cfg: OpenClawConfig; + defaultAgentId?: string; currentJob: CronJob | undefined; patch: CronJobPatch; }) { @@ -99,7 +103,7 @@ function assertValidCronUpdateDelivery(params: { const nextJob = structuredClone(params.currentJob); applyJobPatch(nextJob, params.patch, { - defaultAgentId: resolveDefaultAgentId(params.cfg), + defaultAgentId: params.defaultAgentId, }); assertValidCronAnnounceDelivery({ cfg: params.cfg, @@ -295,6 +299,7 @@ export const cronHandlers: GatewayRequestHandlers = { try { assertValidCronUpdateDelivery({ cfg, + defaultAgentId: context.cron.getDefaultAgentId(), currentJob: context.cron.getJob(jobId), patch, });