Skip to content

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

Merged
wyuc merged 3 commits intoTHU-MAIC:mainfrom
YizukiAme:fix/316-agent-config-persistence
Apr 2, 2026
Merged

fix: persist agent configs in server-generated classrooms#336
wyuc merged 3 commits 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 3 times, most recently from d046b19 to ec0eadc Compare March 30, 2026 19:36
Copy link
Copy Markdown
Contributor

@wyuc wyuc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avatar paths in AGENT_AVATARS don't exist in public/avatars/student.png, assistant.png, student-2.png, assistant-2.png are all missing. Check the actual filenames and update.

Also, AGENT_COLORS is duplicated from COLOR_PALETTE in /api/generate/agent-profiles/route.ts. Worth extracting to a shared constant so they stay in sync.

YizukiAme added a commit to YizukiAme/OpenMAIC that referenced this pull request Apr 2, 2026
- Extract AGENT_COLOR_PALETTE and AGENT_DEFAULT_AVATARS into
  lib/constants/agent-defaults.ts to eliminate duplication
- Fix invalid avatar paths (student.png -> assist.png, etc.)
  to match actual files in public/avatars/
- Remove duplicated inline constants from classroom-generation.ts
  and agent-profiles/route.ts

Addresses reviewer feedback on THU-MAIC#336
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
- Extract AGENT_COLOR_PALETTE and AGENT_DEFAULT_AVATARS into
  lib/constants/agent-defaults.ts to eliminate duplication
- Fix invalid avatar paths (student.png -> assist.png, etc.)
  to match actual files in public/avatars/
- Remove duplicated inline constants from classroom-generation.ts
  and agent-profiles/route.ts

Addresses reviewer feedback on THU-MAIC#336
@YizukiAme YizukiAme force-pushed the fix/316-agent-config-persistence branch from db8597c to 53c9700 Compare April 2, 2026 03:54
@YizukiAme YizukiAme requested a review from wyuc April 2, 2026 03:57
Copy link
Copy Markdown
Contributor

@wyuc wyuc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, LGTM

@wyuc wyuc merged commit 95b5c2b into THU-MAIC:main Apr 2, 2026
2 checks passed
ifishcool pushed a commit to ifishcool/Linksy that referenced this pull request Apr 3, 2026
* fix: persist agent configs in server-generated classrooms (THU-MAIC#316)

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

* fix: extract shared agent constants and fix avatar paths

- Extract AGENT_COLOR_PALETTE and AGENT_DEFAULT_AVATARS into
  lib/constants/agent-defaults.ts to eliminate duplication
- Fix invalid avatar paths (student.png -> assist.png, etc.)
  to match actual files in public/avatars/
- Remove duplicated inline constants from classroom-generation.ts
  and agent-profiles/route.ts

Addresses reviewer feedback on THU-MAIC#336

---------
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

2 participants