{"record":{"id":"7a5d40e10a6bab57","repo":"ruvnet/ruflo","slug":"invalid-rvfa-magic-expected-rvfa-got-magic","errorCode":null,"errorMessage":"Invalid RVFA magic: expected \"RVFA\", got \"${magic}\"","messagePattern":"Invalid RVFA magic: expected \"RVFA\", got \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/appliance/rvfa-format.ts","lineNumber":318,"sourceCode":"export class RvfaReader {\n  private buf: Buffer;\n  private header: RvfaHeader;\n\n  private constructor(buf: Buffer, header: RvfaHeader) {\n    this.buf = buf;\n    this.header = header;\n  }\n\n  /** Parse an RVFA image from an in-memory Buffer. */\n  static fromBuffer(buf: Buffer): RvfaReader {\n    if (buf.length < PREAMBLE_SIZE) {\n      throw new Error('Buffer too small to contain RVFA preamble');\n    }\n\n    // Magic\n    const magic = buf.subarray(0, MAGIC_SIZE).toString('ascii');\n    if (magic !== 'RVFA') {\n      throw new Error(`Invalid RVFA magic: expected \"RVFA\", got \"${magic}\"`);\n    }\n\n    // Version\n    const version = buf.readUInt32LE(MAGIC_SIZE);\n    if (version !== RVFA_VERSION) {\n      throw new Error(\n        `Unsupported RVFA version: ${version} (expected ${RVFA_VERSION})`,\n      );\n    }\n\n    // Header length\n    const headerLen = buf.readUInt32LE(MAGIC_SIZE + VERSION_SIZE);\n    if (headerLen > MAX_HEADER_JSON_SIZE) {\n      throw new Error(\n        `Header JSON exceeds maximum size (${headerLen} > ${MAX_HEADER_JSON_SIZE})`,\n      );\n    }\n    if (PREAMBLE_SIZE + headerLen > buf.length) {","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/ruvnet/ruflo/blob/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/v3/@claude-flow/cli/src/appliance/rvfa-format.ts#L300-L336","documentation":"Thrown by RvfaReader.fromBuffer() when the first 4 bytes are not ASCII 'RVFA'. The buffer passed the preamble-size check but its identity bytes do not match the appliance format. This distinguishes a genuinely malformed file from a format mismatch (e.g. an RVFP patch or unrelated binary).","triggerScenarios":"Passing an RVFP patch buffer, a gzip stream, a text file, or random bytes to fromBuffer/fromFile. The first 4 bytes are anything other than 0x52 0x56 0x46 0x41.","commonSituations":"Pointing fromFile() at a .rvfp patch instead of a .rvfa appliance; reading a file that was overwritten; feeding a decompressed stream that lost its magic; cross-format confusion in a deploy pipeline.","solutions":["Confirm the input is an RVFA appliance produced by RvfaWriter.build().","If the file is an RVFP patch, use RvfaPatcher.parsePatchHeader instead.","Validate magic bytes (buf.subarray(0,4).toString('ascii') === 'RVFA') before parsing.","Re-acquire the appliance from a known-good source if the file is wrong."],"exampleFix":"// before\nconst reader = await RvfaReader.fromFile(path);\n\n// after\nconst head = await fs.open(path, 'r').then(h => { const b = Buffer.alloc(4); h.read(b,0,0,4); h.close(); return b; });\nif (head.toString('ascii') !== 'RVFA') throw new Error('Not an RVFA appliance');\nconst reader = await RvfaReader.fromFile(path);","handlingStrategy":"validation","validationCode":"function hasRvfaMagic(buf: Buffer): boolean {\n  return buf.length >= 4 && buf.subarray(0, 4).toString('ascii') === 'RVFA';\n}","typeGuard":"function isRvfaBuffer(buf: unknown): buf is Buffer {\n  return Buffer.isBuffer(buf) && buf.length >= 4 && buf.subarray(0, 4).toString('ascii') === 'RVFA';\n}","tryCatchPattern":"try {\n  const reader = RvfaReader.fromBuffer(buf);\n} catch (e) {\n  if (/Invalid RVFA magic/.test((e as Error).message)) {\n    throw new Error('Input is not an RVFA appliance; if this is a .rvfp patch, use RvfaPatcher instead');\n  }\n  throw e;\n}","preventionTips":["Check the first 4 bytes equal 'RVFA' before calling fromBuffer/fromFile.","Use distinct file extensions (.rvfa vs .rvfp) and validate them in pipelines.","Do not feed decompressed streams that may have lost the magic bytes.","Confirm the file was produced by RvfaWriter.build()."],"tags":["rvfa","magic","binary-format","validation"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}