{"record":{"id":"f205c6ba5779b353","repo":"rohitg00/agentmemory","slug":"parse-failed","errorCode":"parse_failed","errorMessage":"parse_failed","messagePattern":"parse_failed","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/functions/sliding-window.ts","lineNumber":180,"sourceCode":"          enriched: null,\n          reason: \"No adjacent context available\",\n        };\n      }\n\n      try {\n        const prompt = buildWindowPrompt(primary, before, after);\n        const response = await provider.compress(\n          SLIDING_WINDOW_SYSTEM,\n          prompt,\n        );\n        const parsed = parseEnrichedXml(response);\n\n        if (!parsed) {\n          logger.warn(\"Failed to parse enrichment XML\", {\n            obsId: data.observationId,\n          });\n          return { success: false, error: \"parse_failed\" };\n        }\n\n        const enriched: EnrichedChunk = {\n          id: generateId(\"ec\"),\n          originalObsId: observationId,\n          sessionId,\n          content: parsed.content,\n          resolvedEntities: parsed.resolvedEntities,\n          preferences: parsed.preferences,\n          contextBridges: parsed.contextBridges,\n          windowStart: Math.max(0, primaryIdx - hprev),\n          windowEnd: Math.min(allObs.length - 1, primaryIdx + hnext),\n          createdAt: new Date().toISOString(),\n        };\n\n        await kv.set(\n          KV.enrichedChunks(sessionId),\n          observationId,\n          enriched,","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/rohitg00/agentmemory/blob/e04ba88819c365c9acf9d6661ea802143e728bd6/src/functions/sliding-window.ts#L162-L198","documentation":"The sliding-window enrichment function parses an LLM-provided enrichment XML chunk with a parser that returned null. When parsing fails (malformed or empty XML from the model), the function logs a warning and returns success:false with error 'parse_failed' instead of producing an EnrichedChunk.","triggerScenarios":"Calling the mem::sliding-window function (via sdk.trigger or MCP) where the provider response for a chunk cannot be parsed into the expected enrichment XML — the parser returns a falsy value.","commonSituations":"Provider returns prose or markdown-fenced output instead of XML; truncated response due to max tokens; model refused the task; provider changed output format; empty response on rate limit.","solutions":["Retry the function call — LLM output is nondeterministic and a retry often parses cleanly.","Lower chunk size so the provider response fits within token limits and is not truncated.","Verify the provider/model configuration returns valid XML (adjust the prompt or model).","Check the daemon logs for the 'Failed to parse enrichment XML' warning with the observationId to inspect the raw response."],"exampleFix":"// before\nawait sdk.trigger({ function_id: \"mem::sliding-window\", payload: { observationId } });\n// after\nconst res = await sdk.trigger({ function_id: \"mem::sliding-window\", payload: { observationId } });\nif (res.error === \"parse_failed\") retryOrFail(res); // handle parse failures explicitly","handlingStrategy":"try-catch","validationCode":"// pre-check: provider reachable and configured\nif (!provider?.apiKey) throw new Error(\"provider not configured before sliding-window call\");","typeGuard":"function isParseFailure(res: unknown): res is { success: false; error: \"parse_failed\" } {\n  return typeof res === \"object\" && res !== null && (res as any).error === \"parse_failed\";\n}","tryCatchPattern":"const res = await sdk.trigger({ function_id: \"mem::sliding-window\", payload: { observationId } });\nif (isParseFailure(res)) {\n  // retry once, then fall back to unenriched chunk\n}","preventionTips":["Retry enrichment calls once on parse failure — LLM output is nondeterministic.","Keep chunk sizes well under provider token limits to avoid truncation.","Pin the model and prompt that reliably produce valid XML.","Log raw provider responses to diagnose parse failures quickly."],"tags":["llm","xml-parsing","enrichment","provider-response"],"backgroundTag":"llm-output-parse-failed","analyzedSha":"e04ba88819c365c9acf9d6661ea802143e728bd6","analyzedAt":"2026-08-30T01:07:40.754Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}