{"record":{"id":"d5e8ce78c233ef44","repo":"paperclipai/paperclip","slug":"refusing-to-overwrite-path-expected-hash-exp","errorCode":null,"errorMessage":"Refusing to overwrite ${path}: expected hash ${expectedHash} but current hash is ${currentHash}","messagePattern":"Refusing to overwrite (.+?): expected hash (.+?) but current hash is (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/plugins/plugin-llm-wiki/src/wiki/core.ts","lineNumber":1761,"sourceCode":"function mergeLocalSourceRows(sources: WikiSourceRow[], entries: PluginLocalFolderEntry[]): WikiSourceRow[] {\n  const byPath = new Map(sources.map((source) => [source.rawPath, source]));\n  for (const entry of entries) {\n    if (!entry.path.endsWith(\".md\") || byPath.has(entry.path)) continue;\n    byPath.set(entry.path, {\n      rawPath: entry.path,\n      title: null,\n      sourceType: \"local_file\",\n      url: null,\n      status: \"present\",\n      createdAt: entry.modifiedAt ?? new Date(0).toISOString(),\n    });\n  }\n  return [...byPath.values()].sort((a, b) => a.rawPath.localeCompare(b.rawPath));\n}\n\nfunction assertExpectedHash(expectedHash: string | null | undefined, currentHash: string | null, path: string): void {\n  if (expectedHash && currentHash && expectedHash !== currentHash) {\n    throw new Error(`Refusing to overwrite ${path}: expected hash ${expectedHash} but current hash is ${currentHash}`);\n  }\n}\n\nasync function upsertWikiInstance(ctx: PluginContext, input: { companyId: string; wikiId: string; rootPath?: string | null }) {\n  await ctx.db.execute(\n    `INSERT INTO ${tableName(ctx.db.namespace, \"wiki_instances\")} AS wiki_instances\n       (id, company_id, wiki_id, root_folder_key, configured_root_path, schema_version, settings, managed_agent_key, managed_project_key)\n     VALUES ($1, $2, $3, $4, $5, 1, '{}'::jsonb, $6, $7)\n     ON CONFLICT (company_id, wiki_id)\n     DO UPDATE SET configured_root_path = COALESCE(EXCLUDED.configured_root_path, wiki_instances.configured_root_path),\n                   managed_agent_key = EXCLUDED.managed_agent_key,\n                   managed_project_key = EXCLUDED.managed_project_key,\n                   updated_at = now()`,\n    [\n      randomUUID(),\n      input.companyId,\n      input.wikiId,\n      WIKI_ROOT_FOLDER_KEY,","sourceCodeStart":1743,"sourceCodeEnd":1779,"githubUrl":"https://github.com/paperclipai/paperclip/blob/5716fe907e596ce73501408fc6efdb19fb61edf2/packages/plugins/plugin-llm-wiki/src/wiki/core.ts#L1743-L1779","documentation":"Error \"Refusing to overwrite ${path}: expected hash ${expectedHash} but current hash is ${currentHash}\" thrown in paperclipai/paperclip.","triggerScenarios":"Thrown at packages/plugins/plugin-llm-wiki/src/wiki/core.ts:1762 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Re-read the file to get the current hash, then retry the write with the fresh expectedHash (optimistic concurrency)."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5716fe907e596ce73501408fc6efdb19fb61edf2","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}