fix(gateway): preserve cron delivery validation behavior

This commit is contained in:
Ayaan Zaidi
2026-04-19 23:07:30 +05:30
parent c0563aa532
commit 9b38606d5c
3 changed files with 15 additions and 5 deletions

View File

@@ -51,5 +51,6 @@ export interface CronServiceContract {
run(id: string, mode?: CronRunMode): Promise<CronServiceRunResult>;
enqueueRun(id: string, mode?: CronRunMode): Promise<CronServiceRunResult>;
getJob(id: string): CronJob | undefined;
getDefaultAgentId(): string | undefined;
wake(opts: { mode: CronWakeMode; text: string }): CronWakeResult;
}

View File

@@ -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);
}

View File

@@ -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,
});