Skip to content

Bug: Server-side classroom generation does not persist generated agents, causing discussion actions to be skipped #316

@YizukiAme

Description

@YizukiAme

Description

When using the server-side classroom generation API (/api/generate-classroom with agentMode: 'generate'), the generated agent profiles are not persisted to the Stage object or any client-accessible storage. This causes discussion actions to be silently skipped during playback.

Root Cause

The server-side pipeline in lib/server/classroom-generation.ts correctly generates agent profiles via generateAgentProfiles() and uses them to assign agentId to discussion actions during scene generation. However:

  1. The resulting Stage object does not include agentIds (unlike the frontend flow at generation-preview/page.tsx:L468 which sets stage.agentIds = savedIds)
  2. The server cannot write to the client's IndexedDB (where saveGeneratedAgents() stores agent configs in the frontend flow)

When a user opens the generated classroom:

  • loadGeneratedAgentsForStage(classroomId) returns an empty array (nothing was saved to IndexedDB)
  • Since stage.agentIds is also undefined, the client falls back to ['default-1', 'default-2', 'default-3']
  • The playback engine's isAgentSelected() check fails for gen-server-* IDs → discussion actions are silently skipped

Affected Code Path

POST /api/generate-classroom (agentMode: 'generate')
  → classroom-job-runner.ts → generateClassroom()
    → generateAgentProfiles() creates gen-server-* agents
    → processActions() assigns gen-server-0 as discussion agentId
    → Stage object saved WITHOUT agentIds field        ← BUG
    → Client loads classroom → falls back to default-* agents
    → engine.ts L543-550: isAgentSelected('gen-server-0') → false → SKIP

Impact

  • Current impact: Low — the default frontend uses the generation-preview page which handles agent persistence correctly via saveGeneratedAgents() + stage.agentIds assignment. No user-facing flow currently calls /api/generate-classroom.
  • Future risk: High — if any automation, external integration, or frontend refactor begins using this API endpoint with agentMode: 'generate', all discussion interactions in those classrooms will silently fail.

Suggested Fix

Bundle the generated agent configurations into the persisted Stage object so the client can hydrate them on load. For example:

// In classroom-generation.ts, after agent generation:
stage.agentIds = agents.map(a => a.id);
stage.generatedAgentConfigs = agents; // full configs for client hydration

And on the client side, when loading a stage with generatedAgentConfigs, register them into the agent registry.

Steps to Reproduce

  1. Call POST /api/generate-classroom with { requirement: "...", agentMode: "generate" }
  2. Open the generated classroom URL
  3. Observe that discussion prompts (ProactiveCards) never appear during playback

Environment

  • Commit: current main
  • Relevant files:
    • lib/server/classroom-generation.ts (L427-438: Stage creation without agentIds)
    • app/classroom/[id]/page.tsx (L81-106: agent loading fallback logic)
    • lib/playback/engine.ts (L543-550: discussion agent guard)
    • app/generation-preview/page.tsx (L464-468: correct frontend implementation for reference)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions