this code in my module throws an error:

function module_node_insert($node) {
  if ($node->type == 'main') {
    module_save_sub_node($node); // this programmatically creates a new node of a different type, and CNR is supposed to create references to each other

function module_save_sub_node ($node) {
  builds fields, then...
    $sub->field_node_ref['und'][0]['nid'] = $node->nid;

the error:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '331' for key 'PRIMARY': INSERT INTO {signup}

devel shows the node and field and nodereference build proceeds, but dies at that PDO error. the nodes are never actually created.
i suspect the following:
signup_save_node() runs on node insert with $node as parameter, and $needs_defaults as true, as this is a new node which rightly needs defaults; but then CNR also does a node_save on the same $node to save the reference field, which triggers hook_node_insert again with the same $node.
i cant figure any way around this. any thought?

edit: forgot to mention: commenting out

    // if ($op == 'insert') {
      // $needs_defaults = TRUE;
    // }
    // else {

in signup's line 63 fixes this.