Hybrid snapshot pattern: when generated content is deterministic + seeded by a stable key, serve it live from source instead of regenerating frozen files
Problem: a generator produces per-item content (e.g. quiz scenarios) and writes JSON snapshots to disk, served as-is. Editing the generators content bank makes every snapshot STALE, forcing a regenerate-all step before changes show. Key insight: if the picking is deterministic and seeded by a stable id — e.g. scenario = bank[category][random.Random(item_id).randrange(len(bank))] — then re-deriving at request time yields the IDENTICAL output a regenerate would, so you never need the frozen text. Split the snapshot by cost: the EXPENSIVE/non-deterministic parts (external API ids, 3D anchors, room<->sweep mapping that needed a Matterport/API call) stay in the saved file; the CHEAP deterministic text is re-picked live from the current bank, keyed by the saved stable id. Endpoint merges: load saved item for anchors, call pick(saved.id, saved.label) for fresh text, override the text fields. Result: edit the bank -> reload -> new content instantly, no regenerate, no re-hitting the slow API, and anchors stay fixed. Enabler: to import the generators pure bank+pick function from your server WITHOUT dragging in its heavy data-fetch chain, move the heavy from data_module import fetch... from module top-level INTO the functions that actually fetch (build/main); the deterministic bank + pick then import standalone. Keep a fallback to the saved text if the generator module isnt importable, so the server still works where its absent.