@@ -14,6 +14,7 @@ import {
1414 onCronJobInactive ,
1515 requestActiveCronJobCancellation ,
1616} from "../active-jobs.js" ;
17+ import { isHeartbeatTaskDeclarationKey } from "../heartbeat-task.js" ;
1718import { cloneCronRuntimeAuthority , type CronRuntimeAuthority } from "../runtime-authority.js" ;
1819import { cronSchedulingInputsEqual } from "../schedule-identity.js" ;
1920import { removeCronJobBaseSession } from "../session-reaper.js" ;
@@ -303,12 +304,15 @@ export async function add(
303304 let pendingSessionCleanup : Promise < void > | undefined ;
304305 return await locked ( state , async ( ) => {
305306 warnIfDisabled ( state , "add" ) ;
306- // Heartbeat monitors are gateway-converged system jobs; without this
307- // boundary any internal caller could upsert the declaration key and
308- // hijack the monitor despite the transport schemas excluding the kind.
307+ const declarationKey = normalizeOptionalString ( input . declarationKey ) ;
309308 if ( input . payload ?. kind === "heartbeat" && opts ?. systemOwned !== true ) {
310309 throw new Error ( "heartbeat payloads are system-owned; jobs cannot be created with them" ) ;
311310 }
311+ if ( isHeartbeatTaskDeclarationKey ( declarationKey ) && opts ?. systemOwned !== true ) {
312+ throw new Error (
313+ 'cron declarationKey namespace "heartbeat-task:" is system-owned; jobs cannot be created with it' ,
314+ ) ;
315+ }
312316 await ensureLoaded ( state , { skipRecompute : true } ) ;
313317 const agentId = resolveEffectiveJobAgentId ( input , resolveCurrentDefaultAgentId ( state ) ) ;
314318 if ( state . deps . isAgentAvailable ?.( agentId ) === false ) {
@@ -326,7 +330,6 @@ export async function add(
326330 }
327331 }
328332 const normalizedInput = normalizedId ? { ...input , id : normalizedId } : input ;
329- const declarationKey = normalizeOptionalString ( input . declarationKey ) ;
330333 const matches = declarationKey
331334 ? ( state . store ?. jobs . filter (
332335 ( job ) => job . declarationKey === declarationKey && ( opts ?. matchesExisting ?.( job ) ?? true ) ,
0 commit comments