{"record":{"id":"a98f09f96ffa79a5","repo":"ruvnet/ruflo","slug":"flashattention-empty-input-arrays","errorCode":null,"errorMessage":"FlashAttention: Empty input arrays","messagePattern":"FlashAttention: Empty input arrays","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/neural/src/flash-attention.ts","lineNumber":771,"sourceCode":"        for (let d = 0; d < dimensions; d++) {\n          vectors[i][d] /= norm;\n        }\n      }\n    }\n\n    return vectors;\n  }\n\n  /**\n   * Validate input arrays\n   */\n  private validateInputs(\n    queries: Float32Array[],\n    keys: Float32Array[],\n    values: Float32Array[],\n  ): void {\n    if (!queries.length || !keys.length || !values.length) {\n      throw new Error('FlashAttention: Empty input arrays');\n    }\n\n    if (keys.length !== values.length) {\n      throw new Error(\n        `FlashAttention: Keys and values must have same count. Got ${keys.length} keys, ${values.length} values`,\n      );\n    }\n\n    const qDim = queries[0]?.length ?? 0;\n    const kDim = keys[0]?.length ?? 0;\n    const vDim = values[0]?.length ?? 0;\n\n    if (qDim !== kDim) {\n      throw new Error(\n        `FlashAttention: Query and key dimensions must match. Got Q=${qDim}, K=${kDim}`,\n      );\n    }\n","sourceCodeStart":753,"sourceCodeEnd":789,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/neural/src/flash-attention.ts#L753-L789","documentation":"FlashAttention.validateInputs() runs before every attention computation (attention(), blockAttention(), computeAttention()) and rejects calls where the queries, keys, or values array-of-vectors is empty (zero vectors). Attention over an empty sequence is mathematically undefined, so the library fails fast instead of returning garbage or NaNs.","triggerScenarios":"Passing [] for any of queries/keys/values — e.g. a batching layer that produced an empty batch; a pre-processing filter that removed all tokens/vectors; calling computeAttention() with placeholder arrays before real data has arrived asynchronously.","commonSituations":"Empty-batch edge cases in dataloaders; race conditions where attention runs before embedding finishes; slicing beyond array bounds yielding empty results.","solutions":["Skip the attention call when any input array is empty and return an empty result","Fix the upstream producer so it cannot emit zero vectors","Guard batch loops with `if (batch.length === 0) continue;` before attention"],"exampleFix":"// before\nconst out = computeAttention(queries, keys, values);\n\n// after\nif (queries.length === 0 || keys.length === 0 || values.length === 0) {\n  return []; // nothing to attend over\n}\nconst out = computeAttention(queries, keys, values);","handlingStrategy":"validation","validationCode":"function hasVectors(...sets: Float32Array[][]): boolean {\n  return sets.every(\n    (s) => Array.isArray(s) && s.length > 0 && s.every((v) => v instanceof Float32Array && v.length > 0),\n  );\n}\nif (!hasVectors(queries, keys, values)) {\n  return []; // empty batch - nothing to attend over\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Skip attention for empty batches instead of calling with []","Ensure upstream producers never emit zero-vector sets","Await data arrival before invoking attention in async pipelines"],"tags":["neural","flash-attention","input-shape","validation"],"backgroundTag":"empty-input-array","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}