{"record":{"id":"7ddbdcd5faf329de","repo":"thedotmack/claude-mem","slug":"backfill-failed-error-instanceof-error-error","errorCode":null,"errorMessage":"Backfill failed: ${error instanceof Error ? error.message : String(error)}","messagePattern":"Backfill failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/services/sync/ChromaSync.ts","lineNumber":728,"sourceCode":"    });\n    logger.info('CHROMA_SYNC', 'Bootstrapped watermarks from Chroma', {\n      project,\n      watermarks: ChromaSyncState.get(project)\n    });\n  }\n\n  async ensureBackfilled(project: string, store: SessionStore): Promise<void> {\n    logger.info('CHROMA_SYNC', 'Starting smart backfill', { project });\n\n    await this.ensureCollectionExists();\n\n    const watermarks = ChromaSyncState.get(project);\n\n    try {\n      await this.runBackfillPipeline(store, project, watermarks);\n    } catch (error) {\n      logger.error('CHROMA_SYNC', 'Backfill failed', { project }, error instanceof Error ? error : new Error(String(error)));\n      throw new Error(`Backfill failed: ${error instanceof Error ? error.message : String(error)}`);\n    }\n  }\n\n  private async runBackfillPipeline(\n    db: SessionStore,\n    backfillProject: string,\n    watermarks: ProjectWatermarks\n  ): Promise<void> {\n    const observationDocs = await this.backfillObservations(db, backfillProject, watermarks.observations);\n    const summaryDocs = await this.backfillSummaries(db, backfillProject, watermarks.summaries);\n    const promptDocs = await this.backfillPrompts(db, backfillProject, watermarks.prompts);\n\n    logger.info('CHROMA_SYNC', 'Smart backfill complete', {\n      project: backfillProject,\n      synced: { observationDocs, summaryDocs, promptDocs },\n      watermarks: ChromaSyncState.get(backfillProject)\n    });\n  }","sourceCodeStart":710,"sourceCodeEnd":746,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d768ba364302d12b76e69e4f021f0bb1d2d50ed6/src/services/sync/ChromaSync.ts#L710-L746","documentation":"Thrown by ChromaSync.ensureBackfilled when runBackfillPipeline throws after ensureCollectionExists succeeded. It wraps the underlying error (preserving its message) as a plain Error. The original error is logged at CHROMA_SYNC/backfill-failed with the full Error object. The pipeline runs backfill for observations, summaries, and prompts using per-kind watermarks from ChromaSyncState.","triggerScenarios":"Any of backfillObservations/backfillSummaries/backfillPrompts throws — e.g. a chroma upsert returned isError, a transport error propagated from ChromaMcpManager, or the SessionStore query for rows-past-watermark failed.","commonSituations":"First-time backfill on a large DB overwhelms chroma or times out; the ChromaMcpManager connection dropped mid-backfill; a malformed row triggered a tool-level error 105; watermarks out of sync with actual DB state.","solutions":["Read the wrapped error message (the ${error.message}) — it carries the specific stage and underlying cause.","Check the CHROMA_SYNC error log for the full Error object with stack and project context.","If the cause is a Chroma connection drop, ensure chroma-mcp is healthy (probeSemanticSearch / isHealthy) then retry ensureBackfilled.","For huge first-time backfills, run backfill in smaller batches or pre-warm chroma before triggering it.","Verify ChromaSyncState watermarks are consistent with the DB; a corrupt watermark can cause re-processing or gaps."],"exampleFix":"// before: backfill aborts the whole sync on any sub-stage failure\nawait chromaSync.ensureBackfilled(project, store);\n// after: isolate per-kind backfill so one kind's failure does not abort the others\nfor (const kind of ['observations','summaries','prompts']) {\n  try { await chromaSync.ensureBackfilled(project, store); }\n  catch (e) { log.warn(`backfill kind ${kind} failed, will retry`, e); }\n}","handlingStrategy":"try-catch","validationCode":"// Pre-flight: ensure chroma is reachable before backfill\nif (!(await chromaMcp.isHealthy())) { throw new Error('chroma not healthy; skip backfill'); }","typeGuard":"function isBackfillFailure(e: unknown): boolean {\n  return e instanceof Error && /^Backfill failed:/i.test(e.message);\n}","tryCatchPattern":"try { await chromaSync.ensureBackfilled(project, store); }\ncatch (e) {\n  if (isBackfillFailure(e)) { log.warn('backfill failed, will retry next cycle', e); return; }\n  throw e;\n}","preventionTips":["Run ensureBackfilled only after chroma-mcp passes a health/probe check.","For large first-time backfills, chunk by watermark ranges to limit blast radius.","Keep ChromaSyncState watermarks consistent with the DB to avoid re-processing.","Log the wrapped inner error so the specific failing stage is identifiable."],"tags":["chroma","backfill","sync","vector-search"],"backgroundTag":null,"analyzedSha":"d768ba364302d12b76e69e4f021f0bb1d2d50ed6","analyzedAt":"2026-08-12T23:52:55.241Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}