From 1782f427f17822ccf9d0f14bdc3661abe8259d14 Mon Sep 17 00:00:00 2001 From: Thomas Hallock Date: Tue, 11 Nov 2025 20:31:53 -0600 Subject: [PATCH] fix: add seed and prngAlgorithm fields to all Zod schema versions (V1-V4) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Problem**: Seeds were being saved to the database but lost when loading because Zod schemas didn't include seed/prngAlgorithm fields. Zod strips unknown fields during parsing, so even though extractConfigFields() included the seed and the database had the seed, parseAdditionConfig() was removing it. **Root Cause**: The migration from summary showed seed was being extracted and saved, but server logs showed `hasSavedSeed: false, savedSeed: undefined`. Database query confirmed seed WAS in the JSON (seed: 1977890241), but migrateAdditionConfig() → additionConfigSchema.safeParse() was stripping it. **Fix**: Added seed and prngAlgorithm as optional fields to ALL schema versions: - V1: Added to additionConfigV1Schema - V2: Added to additionConfigV2Schema - V3: Added to additionConfigV3BaseSchema (inherited by Smart/Manual modes) - V4: Added to additionConfigV4BaseSchema (inherited by Smart/Manual/Mastery modes) **Impact**: Seeds will now persist correctly through the full save/load cycle. Users can reload the page and see the exact same problems. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../src/app/create/worksheets/config-schemas.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/apps/web/src/app/create/worksheets/config-schemas.ts b/apps/web/src/app/create/worksheets/config-schemas.ts index 8fc85bea..5e7ace05 100644 --- a/apps/web/src/app/create/worksheets/config-schemas.ts +++ b/apps/web/src/app/create/worksheets/config-schemas.ts @@ -50,6 +50,10 @@ export const additionConfigV1Schema = z.object({ .int() .min(WORKSHEET_LIMITS.FONT_SIZE.MIN) .max(WORKSHEET_LIMITS.FONT_SIZE.MAX), + + // Problem reproducibility (CRITICAL for sharing worksheets) + seed: z.number().int().min(0).optional(), + prngAlgorithm: z.string().optional(), }) export type AdditionConfigV1 = z.infer @@ -139,6 +143,10 @@ export const additionConfigV2Schema = z.object({ .min(WORKSHEET_LIMITS.FONT_SIZE.MIN) .max(WORKSHEET_LIMITS.FONT_SIZE.MAX), showTenFramesForAll: z.boolean(), + + // Problem reproducibility (CRITICAL for sharing worksheets) + seed: z.number().int().min(0).optional(), + prngAlgorithm: z.string().optional(), }) export type AdditionConfigV2 = z.infer @@ -168,6 +176,10 @@ const additionConfigV3BaseSchema = z.object({ pAnyStart: z.number().min(0).max(1), pAllStart: z.number().min(0).max(1), interpolate: z.boolean(), + + // Problem reproducibility (CRITICAL for sharing worksheets) + seed: z.number().int().min(0).optional(), + prngAlgorithm: z.string().optional(), }) // Smart Difficulty Mode @@ -314,6 +326,10 @@ const additionConfigV4BaseSchema = z.object({ pAnyStart: z.number().min(0).max(1), pAllStart: z.number().min(0).max(1), interpolate: z.boolean(), + + // Problem reproducibility (CRITICAL for sharing worksheets) + seed: z.number().int().min(0).optional(), + prngAlgorithm: z.string().optional(), }) // Smart Difficulty Mode for V4