-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Bug: Server-side classroom generation does not persist generated agents, causing discussion actions to be skipped #316
Description
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:
- The resulting
Stageobject does not includeagentIds(unlike the frontend flow atgeneration-preview/page.tsx:L468which setsstage.agentIds = savedIds) - 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.agentIdsis also undefined, the client falls back to['default-1', 'default-2', 'default-3'] - The playback engine's
isAgentSelected()check fails forgen-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-previewpage which handles agent persistence correctly viasaveGeneratedAgents()+stage.agentIdsassignment. 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 hydrationAnd on the client side, when loading a stage with generatedAgentConfigs, register them into the agent registry.
Steps to Reproduce
- Call
POST /api/generate-classroomwith{ requirement: "...", agentMode: "generate" } - Open the generated classroom URL
- 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)