@@ -1049,43 +1049,6 @@ export const layer = Layer.effect(
10491049 maxDeliveryAgeMinutes : input . schedule . maxDeliveryAgeMinutes ?? null ,
10501050 }
10511051 : input . schedule ;
1052- const webhook =
1053- input . schedule . type === "webhook"
1054- ? yield * Effect . gen ( function * ( ) {
1055- const existing = existingTask === null ? null : yield * findWebhookCredentials ( id ) ;
1056- const token = existing ?. token ?? ( yield * newWebhookToken ) ;
1057- const signature =
1058- input . schedule . type === "webhook" ? input . schedule . signature : null ;
1059- // A secretRef is a value the user entered for an agent; this
1060- // save consumes it, so it cannot be used again. A replay of a
1061- // save that already used it keeps the secret that save stored.
1062- const replay = input . commandId !== undefined && existing ?. secret != null ;
1063- const fromRef =
1064- signature ?. secretRef === undefined
1065- ? undefined
1066- : yield * secretRequests
1067- . consume ( { ref : signature . secretRef , projectId : input . projectId } )
1068- . pipe (
1069- Effect . catch ( ( error ) =>
1070- replay
1071- ? Effect . succeed ( undefined )
1072- : Effect . fail ( taskError ( error . message , { taskId : id , cause : error } ) ) ,
1073- ) ,
1074- ) ;
1075- // A ref, when given, is the only source: a plain secret sent
1076- // alongside it must not replace what a replayed save stored.
1077- const provided = signature ?. secretRef === undefined ? signature ?. secret : fromRef ;
1078- const secret = signature == null ? null : ( provided ?? existing ?. secret ?? null ) ;
1079- const secretChanged =
1080- signature == null || provided !== undefined || existing === null ;
1081- if ( signature != null && secret === null ) {
1082- return yield * taskError ( "A webhook signature check needs a signing secret." , {
1083- taskId : id ,
1084- } ) ;
1085- }
1086- return { token, secret, secretChanged } ;
1087- } )
1088- : { token : null , secret : null , secretChanged : true } ;
10891052 const scheduleUnchanged =
10901053 existingTask !== null &&
10911054 existingTask . enabled === input . enabled &&
@@ -1123,6 +1086,43 @@ export const layer = Layer.effect(
11231086 ) {
11241087 yield * requireThreadInProject ( task ) ;
11251088 }
1089+ const webhook =
1090+ input . schedule . type === "webhook"
1091+ ? yield * Effect . gen ( function * ( ) {
1092+ const existing = existingTask === null ? null : yield * findWebhookCredentials ( id ) ;
1093+ const token = existing ?. token ?? ( yield * newWebhookToken ) ;
1094+ const signature =
1095+ input . schedule . type === "webhook" ? input . schedule . signature : null ;
1096+ // A secretRef is a value the user entered for an agent; this
1097+ // save consumes it, so it cannot be used again. A replay of a
1098+ // save that already used it keeps the secret that save stored.
1099+ const replay = input . commandId !== undefined && existing ?. secret != null ;
1100+ const fromRef =
1101+ signature ?. secretRef === undefined
1102+ ? undefined
1103+ : yield * secretRequests
1104+ . consume ( { ref : signature . secretRef , projectId : input . projectId } )
1105+ . pipe (
1106+ Effect . catch ( ( error ) =>
1107+ replay
1108+ ? Effect . succeed ( undefined )
1109+ : Effect . fail ( taskError ( error . message , { taskId : id , cause : error } ) ) ,
1110+ ) ,
1111+ ) ;
1112+ // A ref, when given, is the only source: a plain secret sent
1113+ // alongside it must not replace what a replayed save stored.
1114+ const provided = signature ?. secretRef === undefined ? signature ?. secret : fromRef ;
1115+ const secret = signature == null ? null : ( provided ?? existing ?. secret ?? null ) ;
1116+ const secretChanged =
1117+ signature == null || provided !== undefined || existing === null ;
1118+ if ( signature != null && secret === null ) {
1119+ return yield * taskError ( "A webhook signature check needs a signing secret." , {
1120+ taskId : id ,
1121+ } ) ;
1122+ }
1123+ return { token, secret, secretChanged } ;
1124+ } )
1125+ : { token : null , secret : null , secretChanged : true } ;
11261126 yield * saveTask ( task , input . requireExisting === true , webhook ) ;
11271127 return { task : ( yield * findTask ( id ) ) ?? task } ;
11281128 } ) ;
@@ -1147,6 +1147,10 @@ export const layer = Layer.effect(
11471147 if ( row === undefined || row . project_id !== input . projectId ) return Option . none ( ) ;
11481148 yield * checkAuthorizedTask ( row , input ) ;
11491149 const existing = yield * decodeRow ( row , yield * readWebhookOrigin ) ;
1150+ const threadId = input . threadId === undefined ? existing . threadId : input . threadId ;
1151+ if ( threadId !== existing . threadId ) {
1152+ yield * checkAuthorizedTask ( { ...row , thread_id : threadId } , { id : input . id } ) ;
1153+ }
11501154 const workspaceStrategy =
11511155 input . workspaceStrategy ??
11521156 ( input . workspaceStrategyPatch === undefined
@@ -1167,7 +1171,7 @@ export const layer = Layer.effect(
11671171 enabled : input . enabled ?? existing . enabled ,
11681172 schedule : input . schedule ?? existing . schedule ,
11691173 projectId : input . nextProjectId ?? existing . projectId ,
1170- threadId : input . threadId === undefined ? existing . threadId : input . threadId ,
1174+ threadId,
11711175 workspaceStrategy,
11721176 modelSelection : input . modelSelection ?? existing . modelSelection ,
11731177 runtimeMode : input . runtimeMode ?? existing . runtimeMode ,
0 commit comments