rohitg00/agentmemory · error

parse_failed

parse_failed

Error message

parse_failed

What it means

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.

Source

Thrown at src/functions/sliding-window.ts:180

          enriched: null,
          reason: "No adjacent context available",
        };
      }

      try {
        const prompt = buildWindowPrompt(primary, before, after);
        const response = await provider.compress(
          SLIDING_WINDOW_SYSTEM,
          prompt,
        );
        const parsed = parseEnrichedXml(response);

        if (!parsed) {
          logger.warn("Failed to parse enrichment XML", {
            obsId: data.observationId,
          });
          return { success: false, error: "parse_failed" };
        }

        const enriched: EnrichedChunk = {
          id: generateId("ec"),
          originalObsId: observationId,
          sessionId,
          content: parsed.content,
          resolvedEntities: parsed.resolvedEntities,
          preferences: parsed.preferences,
          contextBridges: parsed.contextBridges,
          windowStart: Math.max(0, primaryIdx - hprev),
          windowEnd: Math.min(allObs.length - 1, primaryIdx + hnext),
          createdAt: new Date().toISOString(),
        };

        await kv.set(
          KV.enrichedChunks(sessionId),
          observationId,
          enriched,

View on GitHub (pinned to e04ba88819)

Solutions

  1. Retry the function call — LLM output is nondeterministic and a retry often parses cleanly.
  2. Lower chunk size so the provider response fits within token limits and is not truncated.
  3. Verify the provider/model configuration returns valid XML (adjust the prompt or model).
  4. Check the daemon logs for the 'Failed to parse enrichment XML' warning with the observationId to inspect the raw response.

Example fix

// before
await sdk.trigger({ function_id: "mem::sliding-window", payload: { observationId } });
// after
const res = await sdk.trigger({ function_id: "mem::sliding-window", payload: { observationId } });
if (res.error === "parse_failed") retryOrFail(res); // handle parse failures explicitly
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check: provider reachable and configured
if (!provider?.apiKey) throw new Error("provider not configured before sliding-window call");

Type guard

function isParseFailure(res: unknown): res is { success: false; error: "parse_failed" } {
  return typeof res === "object" && res !== null && (res as any).error === "parse_failed";
}

Try / catch

const res = await sdk.trigger({ function_id: "mem::sliding-window", payload: { observationId } });
if (isParseFailure(res)) {
  // retry once, then fall back to unenriched chunk
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of rohitg00/agentmemory@e04ba88819 (2026-08-30). Data as JSON: /api/errors/f205c6ba5779b353. Report an issue: GitHub.