Custom Claims are not added after initial sign up

I could not reproduced the situation with a slightly modified version of the rule. For example, when using the following rule:

function (user, context, callback) {
  var namespace = 'https://example.com/claims/';

  context.idToken[namespace + "roles"] = user.roles || ];
  
  callback(null, user, context);
}

I would always obtain a https://example.com/claims/roles claim in the issued ID token independently of the user authenticating being an already existing user or someone who just signed up. This rule defaults the claim to an empty array ] when user.roles is falsy so it may be possible that in your case user.roles is just not set and as such there is no claim to be set.

If the situation persists and you do not trace its source then you should include additional information as a question update; for example, when it does not work what’s the value of user.roles.