Skip to content

fix: persist agent configs in server-generated classrooms#336

Open
YizukiAme wants to merge 1 commit intoTHU-MAIC:mainfrom
YizukiAme:fix/316-agent-config-persistence
Open

fix: persist agent configs in server-generated classrooms#336
YizukiAme wants to merge 1 commit intoTHU-MAIC:mainfrom
YizukiAme:fix/316-agent-config-persistence

Conversation

@YizukiAme
Copy link
Copy Markdown
Contributor

@YizukiAme YizukiAme commented Mar 30, 2026

Summary

Fix server-generated classrooms silently skipping all discussion actions due to missing agent configuration persistence.

Root Cause

The server-side classroom generation pipeline (/api/generate-classroom) generates agent profiles and passes them to scene/action generation, but never embeds them in the persisted Stage object. When a client loads the classroom:

  1. loadGeneratedAgentsForStage() queries IndexedDB → empty (server can't write to client IndexedDB)
  2. selectedAgentIds remains empty
  3. The playback engine's isAgentSelected() guard returns false for every discussion action
  4. All discussions are silently skipped via consumedDiscussions.add() + processNext()

Changes

1. lib/types/stage.ts

  • Added optional generatedAgentConfigs field to Stage interface
  • Type shape matches saveGeneratedAgents() input exactly for zero-transform pass-through

2. lib/server/classroom-generation.ts

  • Added AGENT_COLORS and AGENT_AVATARS constants (consistent with /api/generate/agent-profiles)
  • Injected generatedAgentConfigs into Stage object during construction with fallback avatar/color/priority

3. app/classroom/[id]/page.tsx

  • After loading classroom from server storage, hydrates stage.generatedAgentConfigs into IndexedDB + agent registry via existing saveGeneratedAgents()
  • Sets selectedAgentIds so the playback engine's isAgentSelected() guard passes correctly

Data Flow (After Fix)

Server: generateAgentProfiles() → agents[]
  ↓
Stage.generatedAgentConfigs = agents (with avatar/color/priority)
  ↓
persistClassroom() → data/classrooms/{id}.json
  ↓
Client: fetch /api/classroom → stage.generatedAgentConfigs
  ↓
saveGeneratedAgents() → IndexedDB + Registry
  ↓
setSelectedAgentIds() → Settings Store
  ↓
isAgentSelected(agentId) → ✅ true → Discussion plays!

Backward Compatibility

  • generatedAgentConfigs is optional — existing classroom JSON files load normally
  • Frontend generation-preview flow is unaffected (uses IndexedDB directly, never touches this field)
  • Old server-generated classrooms (without this field) behave as before (no regression)

Verification

  • pnpm exec tsc --noEmit → exit code 0, zero errors

Closes #316


Assisted by Claude Opus 4.6.

@YizukiAme YizukiAme force-pushed the fix/316-agent-config-persistence branch 2 times, most recently from c3f0e4e to d046b19 Compare March 30, 2026 19:32
Server-generated classrooms via /api/generate-classroom silently skip all discussion actions because agent configurations are never embedded in the persisted Stage object.

Changes:

- Add optional generatedAgentConfigs field to Stage interface

- Inject agent configs (with avatar/color/priority) into Stage during server-side generation

- Hydrate agents into IndexedDB/registry when loading from server storage on client

Closes THU-MAIC#316
@YizukiAme YizukiAme force-pushed the fix/316-agent-config-persistence branch from d046b19 to ec0eadc Compare March 30, 2026 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant