{"record":{"id":"4a5b458b6065bfcc","repo":"ruvnet/ruflo","slug":"moe-invalid-expert-expert","errorCode":null,"errorMessage":"[MoE] Invalid expert: ${expert}","messagePattern":"\\[MoE\\] Invalid expert: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/neural/src/moe-router.ts","lineNumber":457,"sourceCode":"      loadBalanceLoss,\n      entropy: routingEntropy,\n    };\n  }\n\n  /**\n   * Update expert weights based on reward signal\n   *\n   * Uses REINFORCE-style gradient update:\n   * gradient = reward * d_log_prob / d_weights\n   *\n   * @param expert - Expert that received the reward\n   * @param reward - Reward signal (-1 to 1, positive = good)\n   */\n  updateExpertWeights(expert: ExpertType | number, reward: number): void {\n    const expertIdx = typeof expert === 'number' ? expert : EXPERT_NAMES.indexOf(expert);\n\n    if (expertIdx < 0 || expertIdx >= NUM_EXPERTS) {\n      console.warn(`[MoE] Invalid expert: ${expert}`);\n      return;\n    }\n\n    if (!this.lastInput || !this.lastHiddenActivated || !this.lastProbs) {\n      console.warn('[MoE] No cached forward pass for gradient computation');\n      return;\n    }\n\n    // Clamp reward to [-1, 1]\n    const clampedReward = Math.max(-1, Math.min(1, reward));\n\n    // Compute gradients using REINFORCE\n    // For softmax: d_log_p_i / d_logit_j = delta_ij - p_j\n    // gradient = reward * (1 - p_expert) for selected expert\n    // gradient = reward * (-p_j) for other experts\n\n    // Clear gradient buffers\n    this.gradW2.fill(0);","sourceCodeStart":439,"sourceCodeEnd":475,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/neural/src/moe-router.ts#L439-L475","documentation":"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.","triggerScenarios":"Thrown at v3/@claude-flow/neural/src/moe-router.ts:457 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a valid expert index within the configured expert count."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}