storytellurx/reports/schema-recovery-investigation.md

4.6 KiB

Schema failure recovery — investigation, 2026-09-08

No recovery implementation or live model request was made for this investigation.

Current failure path

src/server/create-response-middleware.server.ts validates the entire completed turn:

const turn = outputSchema.parse(value.object);
applyStatePatch(state, turn.statePatch);

A failure in any required field rejects the turn. The middleware logs Zod issue paths without logging generated prose. We have not identified which field failed in the user's specific response.

src/components/narrative-chat.tsx hides the assistant body when its structured part is errored. This removes already rendered content and can change scroll geometry. The composer calls native reload() on retry. In installed @tanstack/ai-client, reload() removes messages after the latest user message, discards pending follow-ups, and sends another generation request. It does not pass the rejected object and validation diagnostics back for correction.

The native structured-part error updater retains raw/partial data. Those values are provisional, not valid state. Failed structured parts are excluded from normal model history.

Package capabilities

Mechanism What it recovers What it does not do
TanStack resumable streams Rejoins an existing durable run after a connection drops Repair a terminal schema failure
TanStack reload() Regenerates after the last user message Preserve the failed assistant message or perform targeted correction
TanStack interrupt resume/retry Pending tool/human interrupts Retry final output validation
Provider HTTP retries Configured transient request errors Correct schema-invalid output
LangChain JS toolStrategy error handling Returns validation feedback to the model for correction Resume the same decoder invocation
Pydantic AI output retries Bounded model correction using validation feedback A drop-in React/TanStack component

The installed TanStack AI 0.53.0 engine has no final structured-output validation repair callback or output-retry budget. Its onError middleware is observational; the agent-loop continuation hook runs before final structured output. Streaming Standard Schema validation is the consumer's responsibility, as documented. Provider schema constraints therefore do not replace our final runtime validation.

Preserve the displayed response and message identity while a bounded correction attempt receives the rejected object and exact validation issues. Keep invalid state changes uncommitted. Validate the corrected complete result, including relationships between narrative and state, before applying it. Do not silently default or clamp every invalid field to make validation pass.

This is an additional model request, not token-level continuation. Where correction changes prose, visual identity can be preserved but identical text cannot be promised. Manual retry should be the fallback after the correction budget is exhausted. A schema repair loop is not currently a one-option TanStack feature; adopting another full agent runtime solely for this would be an architectural change.

An implementation should be proved with offline fixtures for malformed output followed by successful correction, exhausted correction, cancellation during correction, and frame-by-frame geometry while the response stays mounted.

Sources