@@ -244,6 +244,12 @@ export class WorkboardWorkflowStore extends WorkboardPromoteStore {
244244 }
245245 }
246246 const summary = normalizeBoundedString ( input . summary , undefined , 2000 , "summary" ) ;
247+ const completionWaiver = normalizeBoundedString (
248+ input . completionWaiver ,
249+ undefined ,
250+ 2000 ,
251+ "completion waiver" ,
252+ ) ;
247253 const proofInput =
248254 input . proof && typeof input . proof === "object" && ! Array . isArray ( input . proof )
249255 ? ( input . proof as WorkboardProofInput )
@@ -286,6 +292,8 @@ export class WorkboardWorkflowStore extends WorkboardPromoteStore {
286292 claim : undefined ,
287293 attempts : closeRunningAttempts ( metadata . attempts , now , "succeeded" ) ,
288294 failureCount : 0 ,
295+ workflowState : undefined ,
296+ ...( completionWaiver ? { completionWaiver } : { } ) ,
289297 automation : normalizeAutomation (
290298 {
291299 ...metadata . automation ,
@@ -545,22 +553,34 @@ export class WorkboardWorkflowStore extends WorkboardPromoteStore {
545553 const existingCardIds = new Set ( ( await this . list ( ) ) . map ( ( card ) => card . id ) ) ;
546554 const children : WorkboardCard [ ] = [ ] ;
547555 const reusedChildSnapshots = new Map < string , WorkboardCard > ( ) ;
556+ const childIdempotencyKeys = new Set < string > ( ) ;
548557 try {
549558 for ( const rawChild of childrenInput ) {
550559 if ( ! rawChild || typeof rawChild !== "object" || Array . isArray ( rawChild ) ) {
551560 throw new Error ( "children must be objects." ) ;
552561 }
553562 const child = rawChild as WorkboardDecomposeChildInput ;
563+ const childIdempotencyKey = normalizeBoundedString (
564+ child . idempotencyKey ??
565+ deriveChildIdempotencyKey ( parentAutomation ?. idempotencyKey , children . length + 1 ) ,
566+ undefined ,
567+ 160 ,
568+ "idempotency key" ,
569+ ) ;
570+ if ( childIdempotencyKey ) {
571+ if ( childIdempotencyKeys . has ( childIdempotencyKey ) ) {
572+ throw new Error ( `duplicate child idempotency key: ${ childIdempotencyKey } ` ) ;
573+ }
574+ childIdempotencyKeys . add ( childIdempotencyKey ) ;
575+ }
554576 const created = await this . createDirect (
555577 {
556578 ...child ,
557579 parents : [ parent . id ] ,
558580 boardId : child . boardId ?? parentAutomation ?. boardId ,
559581 tenant : child . tenant ?? parentAutomation ?. tenant ,
560582 createdByCardId : parent . id ,
561- idempotencyKey :
562- child . idempotencyKey ??
563- deriveChildIdempotencyKey ( parentAutomation ?. idempotencyKey , children . length + 1 ) ,
583+ idempotencyKey : childIdempotencyKey ,
564584 } ,
565585 scope === null ? undefined : scope ,
566586 ) ;
@@ -579,11 +599,22 @@ export class WorkboardWorkflowStore extends WorkboardPromoteStore {
579599 ) ;
580600 }
581601 const summary = normalizeBoundedString ( input . summary , undefined , 2000 , "decompose summary" ) ;
582- const completeParent = input . completeParent !== false ;
602+ const completionWaiver = normalizeBoundedString (
603+ input . completionWaiver ,
604+ undefined ,
605+ 2000 ,
606+ "completion waiver" ,
607+ ) ;
608+ const completeParent = input . completeParent === true ;
583609 const updatedParent = completeParent
584610 ? await this . completeDirect (
585611 parent . id ,
586- { summary, createdCardIds : children . map ( ( child ) => child . id ) } ,
612+ {
613+ summary,
614+ proof : input . proof ,
615+ createdCardIds : children . map ( ( child ) => child . id ) ,
616+ ...( completionWaiver ? { completionWaiver } : { } ) ,
617+ } ,
587618 scope ,
588619 )
589620 : await ( async ( ) => {
@@ -597,6 +628,7 @@ export class WorkboardWorkflowStore extends WorkboardPromoteStore {
597628 : latestParent . status ,
598629 metadata : {
599630 ...latestParent . metadata ,
631+ workflowState : "decomposed" ,
600632 automation : normalizeAutomation (
601633 {
602634 ...latestParent . metadata ?. automation ,
@@ -605,6 +637,16 @@ export class WorkboardWorkflowStore extends WorkboardPromoteStore {
605637 } ,
606638 latestParent . metadata ?. automation ,
607639 ) ,
640+ notifications : [
641+ ...( latestParent . metadata ?. notifications ?? [ ] ) ,
642+ {
643+ id : randomUUID ( ) ,
644+ kind : "decomposed" ,
645+ createdAt : Date . now ( ) ,
646+ sequence : this . nextNotificationSequence ( Date . now ( ) ) ,
647+ message : capText ( summary , 240 ) ?? "Workboard card decomposed." ,
648+ } satisfies WorkboardNotification ,
649+ ] . slice ( - MAX_CARD_NOTIFICATIONS ) ,
608650 } ,
609651 } ,
610652 { enforceStatusHolds : true } ,
0 commit comments