- Add isGeneratingRef to track if generation is in progress
- Guard against double calls by checking ref before starting
- Reset ref in finally block to allow subsequent generations
- This fixes the issue where script generation was called twice in succession