@@ -186,7 +186,7 @@ export function clawCronSchedulerJobFromResult(value: unknown): { id: string } |
186186 return undefined ;
187187}
188188
189- function schedulerJobByDeclarationKey (
189+ function schedulerJobRecordByDeclarationKey (
190190 value : unknown ,
191191 declarationKey : string ,
192192) : Record < string , unknown > | undefined {
@@ -208,6 +208,14 @@ function schedulerJobByDeclarationKey(
208208 return match ;
209209}
210210
211+ function schedulerJobByDeclarationKey (
212+ value : unknown ,
213+ declarationKey : string ,
214+ ) : { id : string } | undefined {
215+ const match = schedulerJobRecordByDeclarationKey ( value , declarationKey ) ;
216+ return match ? { id : match . id as string } : undefined ;
217+ }
218+
211219export function clawCronGatewayInput (
212220 agentId : string ,
213221 ref : PersistedClawCronRef ,
@@ -328,7 +336,7 @@ export async function installClawCronJobs(
328336 await options . gateway . waitUntilAgentAvailable ?.( plan . agent . finalId ) ;
329337 agentAvailable = true ;
330338 }
331- const listedJob = schedulerJobByDeclarationKey (
339+ const listedJob = schedulerJobRecordByDeclarationKey (
332340 await options . gateway . list ( plan . agent . finalId ) ,
333341 pending . declarationKey ,
334342 ) ;
@@ -362,18 +370,10 @@ export async function installClawCronJobs(
362370 agentAvailable = true ;
363371 }
364372 if ( options . gateway . list ) {
365- const listedJob = schedulerJobByDeclarationKey (
373+ result = schedulerJobByDeclarationKey (
366374 await options . gateway . list ( plan . agent . finalId ) ,
367375 pending . declarationKey ,
368376 ) ;
369- if ( listedJob ) {
370- if ( ! clawCronGatewayJobMatchesRef ( plan . agent . finalId , pending , listedJob ) ) {
371- throw new Error (
372- `Cron declaration ${ JSON . stringify ( pending . manifestId ) } changed after an ambiguous write.` ,
373- ) ;
374- }
375- result = { id : listedJob . id as string } ;
376- }
377377 }
378378 result ??= clawCronSchedulerJobFromResult (
379379 await options . gateway . add ( clawCronGatewayInput ( plan . agent . finalId , pending ) ) ,
0 commit comments