Skip to content

fix(generation): stop creative-space generations failing on Anki metadata validation - #63

Merged
mrsibe merged 1 commit into
mainfrom
fix/creative-space-generation-schema
Sep 24, 2026
Merged

mrsibe merged 1 commit into
mainfrom
fix/creative-space-generation-schema

Conversation

@mrsibe

@mrsibe mrsibe commented Sep 24, 2026

Copy link
Copy Markdown
Owner

What does this PR do?

Makes the Anki, mind map and quiz generators stop discarding an entire result when the model omits a field the prompts never required. Concretely, Anki card generation now succeeds instead of always ending in a failed item, and chunk IDs are treated as the best-effort field the prompts describe.

Why?

In the creative space, creating Anki cards always failed after the model finished streaming, and chart/quiz creation was exposed to the same class of failure. The root cause is that the Zod schemas used for streamObject are stricter than the prompts:

  • Anki (reproducible, always fails): createAnkiSchema required metadata.cardTypes: string[], but the Anki prompt's output format only mentions metadata.totalCards. The model follows the prompt, omits cardTypes, and final validation throws AI_NoObjectGeneratedError: No object generated: response did not match schema with path: ["metadata","cardTypes"], expected "array", received undefined.
  • chunkIds (all three): aggregateNotebookContent never passes chunk IDs to the model — only the chunk text — while the prompts ask for chunk IDs only "whenever possible" (尽可能). Yet chunkIds was required, so one omitted node/card/question field failed the whole generation.
  • Anki text caps: the schema imposed front max(300), back max(500), etc., which the Anki prompt never states, so a long answer could fail the same way.

Related issue

None.

What changed?

  • AnkiCardService: metadata is now optional and totalCards/cardTypes are derived from the generated cards; chunkIds defaults to []; the undeclared max() caps on card text are removed.
  • MindMapService / QuizService: chunkIds defaults to []. The existing validateAndClean* code already filters invalid IDs and rebuilds the chunk mapping, so this only affects the "model omitted them" case.

Verification

  • npm run typecheck — pass
  • npm test — 49/49 pass
  • npm run build — pass
  • Manual (Linux, electron-vite dev): ran the real generation path against the configured openai-completions / api.deepseek.com connection.
    • Before: Anki failed with No object generated: response did not match schema (missing metadata.cardTypes).
    • After: Anki returned 4 cards with cardTypes=basic; mind map and quiz already succeeded and still do.

No new tests were added: the generation services are not unit-testable without a model connection, and the schemas are module-private. The prompt/schema mismatch is covered by the manual verification above.

The Anki schema required metadata.cardTypes, but the Anki prompt never asks
the model to emit it, so every Anki generation died at final validation with
AI_NoObjectGeneratedError ("No object generated: response did not match
schema"). The mind map, quiz and Anki schemas also required chunkIds even
though aggregateNotebookContent never exposes chunk IDs to the model and the
prompts only ask for them "whenever possible" (尽可能); a single omitted field
discarded the entire generation. Anki card text additionally carried max()
caps the prompt never states, so a long answer failed the same way.

- Anki: metadata is optional and totalCards/cardTypes are derived from the
  generated cards; chunkIds defaults to [] and the undeclared text caps are
  removed.
- Mind map / quiz: chunkIds defaults to [].

Verified by running the real generation path against the configured
DeepSeek connection: Anki went from a schema validation failure to a
successful 4-card result; mind map and quiz already succeeded.
@github-actions github-actions Bot added the bug Something isn't working label Sep 24, 2026
@mrsibe
mrsibe merged commit f5b720d into main Sep 24, 2026
4 checks passed
@mrsibe
mrsibe deleted the fix/creative-space-generation-schema branch September 24, 2026 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant