Skip to content

Opt-in parallel scene generation (hybrid two-phase) #572

@wyuc

Description

@wyuc

Problem

Scene generation in lib/hooks/use-scene-generator.ts runs strictly serial — content → actions → TTS, one outline at a time (see the // Serial generation loop at line ~329). For an N-scene classroom this is N × (content + actions + TTS) of wall-clock latency, which dominates the post-outline wait.

Proposal

A hybrid two-phase parallel mode:

  1. Phase 1 — concurrent content. Promise.all over pending outlines (capped) to fetch /api/generate/scene-content. Failures mark individual outlines and don't pause the batch.
  2. Phase 2 — serial actions + TTS. Keep the current in-order for-of loop for /api/generate/scene-actions + TTS so that previousSpeeches threading and the pause-on-failure UX stay intact.

This keeps narrative coherence (previousSpeeches carryover) and ordered UI rendering, while parallelizing the heaviest per-scene LLM call. Expected speedup ≈ 2–3× at concurrency 3.

Configuration

  • Gated by a server-side config flag, default OFF.
  • Concurrency is configurable (e.g., PARALLEL_SCENE_CONCURRENCY, default 3 when enabled).
  • Rationale for default-off: many users bring API keys with low per-key concurrency quotas; a bursty default would surprise them with 429s. Opt-in keeps the out-of-box behavior unchanged.

Out of scope

  • A "full parallel" path (content + actions + TTS all concurrent) — would break previousSpeeches coherence.
  • The classroom-job-runner.ts server path is also serial today but is not on the web critical path; can adopt the same pattern later.
  • The unused generateFullScenes in lib/generation/scene-generator.ts (no callers) — worth removing as cleanup alongside this work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions