ruvnet/ruflo · error · Error

Unknown algorithm: ${algorithm}

Error message

Unknown algorithm: ${algorithm}

What it means

createAlgorithm() maps an algorithm name to a factory; the switch covers exactly 'ppo', 'dqn', 'a2c', 'decision-transformer', 'q-learning', 'sarsa' and 'curiosity', and anything else hits the default branch. The parameter is typed as the RLAlgorithm union, so a runtime hit means an unchecked string (JS caller, `as` cast, or config/env value) reached the function.

Source

Thrown at v3/@claude-flow/neural/src/algorithms/index.ts:96

export function createAlgorithm(algorithm: RLAlgorithm, config?: Partial<RLConfig>): unknown {
  // Use type assertions since config is validated by algorithm switch
  switch (algorithm) {
    case 'ppo':
      return createPPO(config as Parameters<typeof createPPO>[0]);
    case 'dqn':
      return createDQN(config as Parameters<typeof createDQN>[0]);
    case 'a2c':
      return createA2C(config as Parameters<typeof createA2C>[0]);
    case 'decision-transformer':
      return createDecisionTransformer(config as Parameters<typeof createDecisionTransformer>[0]);
    case 'q-learning':
      return createQLearning(config as Parameters<typeof createQLearning>[0]);
    case 'sarsa':
      return createSARSA(config as Parameters<typeof createSARSA>[0]);
    case 'curiosity':
      return createCuriosity(config as Parameters<typeof createCuriosity>[0]);
    default:
      throw new Error(`Unknown algorithm: ${algorithm}`);
  }
}

/**
 * Get default configuration for an algorithm
 */
export function getDefaultConfig(algorithm: RLAlgorithm): RLConfig {
  switch (algorithm) {
    case 'ppo':
      return { ...DEFAULT_PPO_CONFIG };
    case 'dqn':
      return { ...DEFAULT_DQN_CONFIG };
    case 'a2c':
      return { ...DEFAULT_A2C_CONFIG };
    case 'decision-transformer':
      return { ...DEFAULT_DT_CONFIG };
    case 'q-learning':
      return { ...DEFAULT_QLEARNING_CONFIG };

View on GitHub (pinned to fa13ee4ad6)

Solutions

  1. Use an exact literal: 'ppo' | 'dqn' | 'a2c' | 'decision-transformer' | 'q-learning' | 'sarsa' | 'curiosity'
  2. Normalize input (trim/lowercase) and map aliases before calling createAlgorithm
  3. Validate against an allowlist and fail fast listing the supported names
  4. Align @claude-flow/neural versions across packages if the name is a newer addition

Example fix

// before
const algo = createAlgorithm(cfg.algorithm as RLAlgorithm);

// after
const SUPPORTED = ['ppo', 'dqn', 'a2c', 'decision-transformer', 'q-learning', 'sarsa', 'curiosity'] as const;
const name = String(cfg.algorithm).trim().toLowerCase() as (typeof SUPPORTED)[number];
if (!SUPPORTED.includes(name)) {
  throw new Error(`Unsupported algorithm '${cfg.algorithm}'. Supported: ${SUPPORTED.join(', ')}`);
}
const algo = createAlgorithm(name);
Defensive patterns

Strategy: type-guard

Validate before calling

const SUPPORTED = ['ppo', 'dqn', 'a2c', 'decision-transformer', 'q-learning', 'sarsa', 'curiosity'] as const;
const name = String(rawAlgorithm).trim().toLowerCase();
if (!SUPPORTED.includes(name as (typeof SUPPORTED)[number])) {
  throw new Error(`Unknown algorithm '${rawAlgorithm}'. Supported: ${SUPPORTED.join(', ')}`);
}
const algo = createAlgorithm(name as RLAlgorithm);

Type guard

const RL_ALGORITHMS = ['ppo', 'dqn', 'a2c', 'decision-transformer', 'q-learning', 'sarsa', 'curiosity'] as const;
function isRLAlgorithm(v: unknown): v is (typeof RL_ALGORITHMS)[number] {
  return typeof v === 'string' && (RL_ALGORITHMS as readonly string[]).includes(v);
}

Prevention

When it happens

Trigger: Algorithm name read from config/env/CLI with wrong case or spelling ('DQN', 'decision_transformer', 'A3C'); version skew where code targets a newer @claude-flow/neural that supports an algorithm an older build lacks; data-driven pipelines selecting algorithms by string.

Common situations: User-supplied algorithm names; punctuation/case mismatches; JavaScript interop where the union is not enforced; mixed package versions in a monorepo.

Related errors


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