ruvnet/ruflo · error

[MoE] Invalid expert: ${expert}

Error message

[MoE] Invalid expert: ${expert}

What it means

Log warning in updateExpertWeights: the expert argument is neither a valid index nor a known expert name (EXPERT_NAMES lookup failed), so the REINFORCE weight update is skipped entirely — an input guard, not a thrown error.

Source

Thrown at v3/@claude-flow/neural/src/moe-router.ts:457

      loadBalanceLoss,
      entropy: routingEntropy,
    };
  }

  /**
   * Update expert weights based on reward signal
   *
   * Uses REINFORCE-style gradient update:
   * gradient = reward * d_log_prob / d_weights
   *
   * @param expert - Expert that received the reward
   * @param reward - Reward signal (-1 to 1, positive = good)
   */
  updateExpertWeights(expert: ExpertType | number, reward: number): void {
    const expertIdx = typeof expert === 'number' ? expert : EXPERT_NAMES.indexOf(expert);

    if (expertIdx < 0 || expertIdx >= NUM_EXPERTS) {
      console.warn(`[MoE] Invalid expert: ${expert}`);
      return;
    }

    if (!this.lastInput || !this.lastHiddenActivated || !this.lastProbs) {
      console.warn('[MoE] No cached forward pass for gradient computation');
      return;
    }

    // Clamp reward to [-1, 1]
    const clampedReward = Math.max(-1, Math.min(1, reward));

    // Compute gradients using REINFORCE
    // For softmax: d_log_p_i / d_logit_j = delta_ij - p_j
    // gradient = reward * (1 - p_expert) for selected expert
    // gradient = reward * (-p_j) for other experts

    // Clear gradient buffers
    this.gradW2.fill(0);

View on GitHub (pinned to fa13ee4ad6)

Solutions

  1. Pass a valid expert index within the configured expert count.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at v3/@claude-flow/neural/src/moe-router.ts:457 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18). Data as JSON: /api/errors/4a5b458b6065bfcc. Report an issue: GitHub.