{"record":{"id":"343384d6395ae5c7","repo":"ruvnet/ruflo","slug":"unknown-algorithm-algorithm","errorCode":null,"errorMessage":"Unknown algorithm: ${algorithm}","messagePattern":"Unknown algorithm: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/neural/src/algorithms/index.ts","lineNumber":96,"sourceCode":"export function createAlgorithm(algorithm: RLAlgorithm, config?: Partial<RLConfig>): unknown {\n  // Use type assertions since config is validated by algorithm switch\n  switch (algorithm) {\n    case 'ppo':\n      return createPPO(config as Parameters<typeof createPPO>[0]);\n    case 'dqn':\n      return createDQN(config as Parameters<typeof createDQN>[0]);\n    case 'a2c':\n      return createA2C(config as Parameters<typeof createA2C>[0]);\n    case 'decision-transformer':\n      return createDecisionTransformer(config as Parameters<typeof createDecisionTransformer>[0]);\n    case 'q-learning':\n      return createQLearning(config as Parameters<typeof createQLearning>[0]);\n    case 'sarsa':\n      return createSARSA(config as Parameters<typeof createSARSA>[0]);\n    case 'curiosity':\n      return createCuriosity(config as Parameters<typeof createCuriosity>[0]);\n    default:\n      throw new Error(`Unknown algorithm: ${algorithm}`);\n  }\n}\n\n/**\n * Get default configuration for an algorithm\n */\nexport function getDefaultConfig(algorithm: RLAlgorithm): RLConfig {\n  switch (algorithm) {\n    case 'ppo':\n      return { ...DEFAULT_PPO_CONFIG };\n    case 'dqn':\n      return { ...DEFAULT_DQN_CONFIG };\n    case 'a2c':\n      return { ...DEFAULT_A2C_CONFIG };\n    case 'decision-transformer':\n      return { ...DEFAULT_DT_CONFIG };\n    case 'q-learning':\n      return { ...DEFAULT_QLEARNING_CONFIG };","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/neural/src/algorithms/index.ts#L78-L114","documentation":"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.","triggerScenarios":"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.","commonSituations":"User-supplied algorithm names; punctuation/case mismatches; JavaScript interop where the union is not enforced; mixed package versions in a monorepo.","solutions":["Use an exact literal: 'ppo' | 'dqn' | 'a2c' | 'decision-transformer' | 'q-learning' | 'sarsa' | 'curiosity'","Normalize input (trim/lowercase) and map aliases before calling createAlgorithm","Validate against an allowlist and fail fast listing the supported names","Align @claude-flow/neural versions across packages if the name is a newer addition"],"exampleFix":"// before\nconst algo = createAlgorithm(cfg.algorithm as RLAlgorithm);\n\n// after\nconst SUPPORTED = ['ppo', 'dqn', 'a2c', 'decision-transformer', 'q-learning', 'sarsa', 'curiosity'] as const;\nconst name = String(cfg.algorithm).trim().toLowerCase() as (typeof SUPPORTED)[number];\nif (!SUPPORTED.includes(name)) {\n  throw new Error(`Unsupported algorithm '${cfg.algorithm}'. Supported: ${SUPPORTED.join(', ')}`);\n}\nconst algo = createAlgorithm(name);","handlingStrategy":"type-guard","validationCode":"const SUPPORTED = ['ppo', 'dqn', 'a2c', 'decision-transformer', 'q-learning', 'sarsa', 'curiosity'] as const;\nconst name = String(rawAlgorithm).trim().toLowerCase();\nif (!SUPPORTED.includes(name as (typeof SUPPORTED)[number])) {\n  throw new Error(`Unknown algorithm '${rawAlgorithm}'. Supported: ${SUPPORTED.join(', ')}`);\n}\nconst algo = createAlgorithm(name as RLAlgorithm);","typeGuard":"const RL_ALGORITHMS = ['ppo', 'dqn', 'a2c', 'decision-transformer', 'q-learning', 'sarsa', 'curiosity'] as const;\nfunction isRLAlgorithm(v: unknown): v is (typeof RL_ALGORITHMS)[number] {\n  return typeof v === 'string' && (RL_ALGORITHMS as readonly string[]).includes(v);\n}","tryCatchPattern":null,"preventionTips":["Normalize case/whitespace and map aliases before passing algorithm names","Never cast config strings to RLAlgorithm without an allowlist check","Keep package versions aligned in monorepos so supported names cannot drift"],"tags":["neural","reinforcement-learning","enum","factory"],"backgroundTag":"unsupported-algorithm","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}