The extractJSONFromMarkdown fence-stripping caught my eye. It only strips when the string starts with the literal "json", but you say right above it that the model wraps its answer in a fence about half the time regardless of what you ask for. If it ever emits a bare fence without the json tag, that startsWith check misses it, JSON.parse chokes on the leading backticks, and I don't see a try/catch anywhere around that call, so it looks like that would throw straight through, right on the authenticated persist path where you actually need the data to land. A regex like /^```(?:json)?\n?/ instead of the literal startsWith would catch both cases without adding much code.