{"record":{"id":"11db87323ea87ff4","repo":"ruvnet/ruflo","slug":"unsupported-kv-cache-version-version","errorCode":null,"errorMessage":"Unsupported KV cache version: ${version}","messagePattern":"Unsupported KV cache version: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/appliance/gguf-engine.ts","lineNumber":394,"sourceCode":"    const header = Buffer.alloc(44);\n    header.writeUInt32LE(RVKV_MAGIC, 0);\n    header.writeUInt32LE(RVKV_VERSION, 4);\n    modelHash.copy(header, 8);\n    header.writeUInt32LE(this.kvCache.size, 40);\n\n    await writeFile(path, Buffer.concat([header, entryData, footer]));\n    if (this.config.verbose) console.log(`[gguf-engine] KV cache persisted: ${this.kvCache.size} entries`);\n  }\n\n  /** Restore KV cache from an RVF-compatible binary file. */\n  async loadKvCache(inputPath: string): Promise<void> {\n    const data = await readFile(inputPath);\n    if (data.length < 44) throw new Error('KV cache file too small');\n\n    const magic = data.readUInt32LE(0);\n    if (magic !== RVKV_MAGIC) throw new Error(`Invalid KV cache magic: 0x${magic.toString(16)}`);\n    const version = data.readUInt32LE(4);\n    if (version !== RVKV_VERSION) throw new Error(`Unsupported KV cache version: ${version}`);\n\n    const entryCount = data.readUInt32LE(40);\n    let offset = 44;\n    const entries = new Map<string, Buffer>();\n\n    for (let i = 0; i < entryCount; i++) {\n      if (offset + 8 > data.length) throw new Error('KV cache file truncated');\n      const keyLen = data.readUInt32LE(offset);\n      const valLen = data.readUInt32LE(offset + 4);\n      offset += 8;\n      if (offset + keyLen + valLen > data.length) throw new Error('KV cache file truncated');\n      entries.set(data.toString('utf-8', offset, offset + keyLen), Buffer.from(data.subarray(offset + keyLen, offset + keyLen + valLen)));\n      offset += keyLen + valLen;\n    }\n\n    // Verify footer hash (mandatory)\n    if (offset + 32 > data.length) {\n      throw new Error('KV cache file missing SHA256 footer');","sourceCodeStart":376,"sourceCodeEnd":412,"githubUrl":"https://github.com/ruvnet/ruflo/blob/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/v3/@claude-flow/cli/src/appliance/gguf-engine.ts#L376-L412","documentation":"Thrown by loadKvCache when the version u32 (offset 4) does not equal RVKV_VERSION. The RVKV format is versioned; loading a cache written by a different version of the writer is rejected to avoid misinterpreting the layout. Runs after magic check, before entry parsing.","triggerScenarios":"Loading a KV cache produced by an older or newer build of the engine whose RVKV_VERSION constant differs — e.g. after upgrading the CLI/appliance package, the on-disk caches from the prior version no longer match.","commonSituations":"Package upgrade that bumped RVKV_VERSION without a migration; caches shared across machines running different engine versions; a downgrade after an upgrade leaves incompatible caches.","solutions":["Delete the old cache files after an upgrade and regenerate them with the current engine (KV caches are derived data, safe to rebuild).","Keep caches version-tagged in their directory names so you can identify and purge stale ones post-upgrade.","Treat version mismatch as a cold-start signal rather than a fatal error (wrap loadKvCache and continue without the cache).","Pin the engine version if you must preserve caches across runs."],"exampleFix":"// before\nawait engine.loadKvCache(path);\n\n// after\ntry {\n  await engine.loadKvCache(path);\n} catch (e) {\n  if (e instanceof Error && /Unsupported KV cache version/.test(e.message)) {\n    logger.warn({ path }, 'cache version mismatch; rebuilding');\n    await fsUnlink(path).catch(() => {});\n  } else throw e;\n}","handlingStrategy":"fallback","validationCode":"// After an upgrade, purge caches whose version no longer matches:\nconst fh = await open(path, 'r');\nconst buf = Buffer.alloc(8);\nawait fh.read(buf, 0, 8, 0);\nawait fh.close();\nif (buf.readUInt32LE(4) !== RVKV_VERSION) {\n  await fsUnlink(path).catch(() => {});\n  return; // regenerate\n}\nawait engine.loadKvCache(path);","typeGuard":"function isSupportedCacheVersion(v: number): boolean {\n  return v === RVKV_VERSION;\n}","tryCatchPattern":"try {\n  await engine.loadKvCache(path);\n} catch (e) {\n  if (e instanceof Error && /Unsupported KV cache version/.test(e.message)) {\n    await fsUnlink(path).catch(() => {});\n    return; // rebuild\n  }\n  throw e;\n}","preventionTips":["Purge old caches after an engine/CLI upgrade.","Namespace caches by version in their path.","Treat version mismatch as a cold-start signal.","KV caches are disposable — never preserve across incompatible versions."],"tags":["gguf","kv-cache","version","migration"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}