{"record":{"id":"bedb85984a2cfa2f","repo":"ruvnet/ruflo","slug":"invalid-rvfp-magic-magic","errorCode":null,"errorMessage":"Invalid RVFP magic: \"${magic}\"","messagePattern":"Invalid RVFP magic: \"(.+?)\"","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/appliance/rvfa-distribution.ts","lineNumber":193,"sourceCode":"      created: new Date().toISOString(), newSectionSize: payload.length,\n      newSectionSha256: sha256(payload), compression: comp,\n    };\n    if (opts.privateKey && opts.signedBy) {\n      const signable = Buffer.concat([Buffer.from(canonicalJson(header), 'utf-8'), payload]);\n      header.signature = edSign(signable, opts.privateKey);\n      header.signedBy = opts.signedBy;\n    }\n    const hJson = Buffer.from(JSON.stringify(header), 'utf-8');\n    const magic = Buffer.from('RVFP');\n    const ver = Buffer.alloc(4); ver.writeUInt32LE(RVFP_VERSION, 0);\n    const hLen = Buffer.alloc(4); hLen.writeUInt32LE(hJson.length, 0);\n    return Buffer.concat([magic, ver, hLen, hJson, payload, sha256B(payload)]);\n  }\n\n  static parsePatchHeader(buf: Buffer): RvfpHeader {\n    if (buf.length < PRE) throw new Error('Buffer too small for RVFP preamble');\n    const magic = buf.subarray(0, 4).toString('ascii');\n    if (magic !== 'RVFP') throw new Error(`Invalid RVFP magic: \"${magic}\"`);\n    const ver = buf.readUInt32LE(4);\n    if (ver !== RVFP_VERSION) throw new Error(`Unsupported RVFP version: ${ver}`);\n    const hLen = buf.readUInt32LE(8);\n    if (PRE + hLen > buf.length) throw new Error('Buffer too small for declared header');\n    const h = JSON.parse(buf.subarray(PRE, PRE + hLen).toString('utf-8')) as RvfpHeader;\n    if (h.magic !== 'RVFP') throw new Error('RVFP header magic mismatch');\n    return h;\n  }\n\n  static async verifyPatch(buf: Buffer): Promise<PatchVerifyResult> {\n    const errors: string[] = [];\n    let header: RvfpHeader;\n    try { header = RvfaPatcher.parsePatchHeader(buf); } catch (e) {\n      const empty: RvfpHeader = {\n        magic: 'RVFP', version: 0, targetApplianceName: '', targetApplianceVersion: '',\n        targetSection: '', patchVersion: '', created: '', newSectionSize: 0,\n        newSectionSha256: '', compression: 'none',\n      };","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/cli/src/appliance/rvfa-distribution.ts#L175-L211","documentation":"Bytes 0–3 of an RVFP patch must ASCII-decode to 'RVFP'. Anything else fails here — including the sibling appliance magic 'RVFA' — meaning the file is simply not an RVFP patch: wrong artifact type, a text/HTML document saved with a .rvfp name, or corrupted leading bytes.","triggerScenarios":"`parsePatchHeader` on a full .rvf appliance image (magic 'RVFA'); a gateway JSON/HTML error body saved as .rvfp; a binary whose first four bytes were overwritten by corruption or wrong-offset slicing.","commonSituations":"Confusing an appliance image with its patch (both start 'RVF'); downloading from the wrong CID; a proxy injecting an error page with a 200 status.","solutions":["Identify the artifact: appliances start with 'RVFA' (use RvfaReader), patches with 'RVFP' (use RvfaPatcher) — feed each to its own parser","If downloaded, inspect the head of the file (xxd file | head -1) to see what it actually is","Re-download or rebuild via RvfaPatcher.createPatch"],"exampleFix":"// before\nconst header = RvfaPatcher.parsePatchHeader(await readFile(appliancePath)); // actually an RVFA image\n\n// after\nconst buf = await readFile(patchPath);\nif (buf.subarray(0, 4).toString('ascii') === 'RVFA') {\n  throw new Error('This is an appliance image, not a patch — use RvfaReader.fromBuffer');\n}\nconst header = RvfaPatcher.parsePatchHeader(buf);","handlingStrategy":"type-guard","validationCode":"const magic = buf.subarray(0, 4).toString('ascii');\nif (magic !== 'RVFP') {\n  throw new Error(`Expected RVFP patch, got magic \"${magic}\"`);\n}","typeGuard":"function isRvfpPatch(buf: Buffer): boolean {\n  return buf.length >= 12 && buf.subarray(0, 4).toString('ascii') === 'RVFP';\n}","tryCatchPattern":null,"preventionTips":["Check the 4-byte magic before choosing between the RVFA image parser and the RVFP patch parser","Give artifacts unambiguous file names (.rvf vs .rvfp) and verify downloads by magic, not extension"],"tags":["rvfa-distribution","rvfp-patch","magic-number","binary-format"],"backgroundTag":"invalid-magic-number","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}