Skip to content

fix(#353,#354): conditionally set generatedAgentConfigs based on agentMode#373

Open
YizukiAme wants to merge 2 commits intoTHU-MAIC:mainfrom
YizukiAme:fix/353-354-agent-mode-conditional
Open

fix(#353,#354): conditionally set generatedAgentConfigs based on agentMode#373
YizukiAme wants to merge 2 commits intoTHU-MAIC:mainfrom
YizukiAme:fix/353-354-agent-mode-conditional

Conversation

@YizukiAme
Copy link
Copy Markdown
Contributor

Summary

Fixes #353 and #354.

#353: generatedAgentConfigs unconditionally set for all agent modes

Problem: classroom-generation.ts always embedded generatedAgentConfigs in the Stage object regardless of agentMode. When agentMode === 'default', this caused the 6 default agents (default-1 ~ default-6) to be written to the client-side IndexedDB and Agent Registry as isGenerated: true, overwriting their isDefault: true entries.

Fix: Only set generatedAgentConfigs when agentMode === 'generate'. For default mode, set agentIds instead — the client already has the default agent definitions built in.

Additional fix: When LLM agent generation fails and falls back to defaults, reset agentMode to 'default' so the Stage object correctly uses agentIds instead of generatedAgentConfigs.

#354: Redundant agent hydration in classroom page load

Problem: When loading a server-generated classroom, page.tsx Path 1 called both saveGeneratedAgents() and setSelectedAgentIds(). Path 2 (general restoration logic) would then clear the registry and re-add the same agents, calling setSelectedAgentIds() again — redundant work.

Fix: Path 1 now only calls saveGeneratedAgents() to persist agents to IndexedDB. Path 2 handles all agent restoration uniformly, including setting selectedAgentIds and agentMode.

Changes

File Change
lib/server/classroom-generation.ts Conditional generatedAgentConfigs vs agentIds based on agentMode; reset agentMode on LLM fallback
app/classroom/[id]/page.tsx Remove redundant setSelectedAgentIds from server hydration path
tests/server/classroom-agent-mode.test.ts [NEW] Unit tests for all 3 scenarios (default, generate, LLM fallback)

Verification

  • tsc --noEmit — zero errors
  • pnpm lint — no new warnings/errors
  • Unit tests — 3/3 passed (vitest)
  • E2E: Server-generated classroom with agentMode: 'default' produces agentIds: ["default-1",...,"default-6"] and no generatedAgentConfigs

@YizukiAme YizukiAme force-pushed the fix/353-354-agent-mode-conditional branch from 975be56 to 443e296 Compare April 5, 2026 08:51
…gs based on agentMode

THU-MAIC#353: Only embed generatedAgentConfigs in the Stage when agentMode is
'generate'. For default mode, set agentIds instead. This prevents
default agents from being incorrectly marked as isGenerated on the
client-side registry.

Also reset agentMode to 'default' in the catch block when LLM agent
generation fails and falls back to defaults.

THU-MAIC#354: Remove redundant setSelectedAgentIds call from Path 1 (server
hydration). Path 2 handles agent restoration uniformly for both
IndexedDB and server-loaded classrooms.

Includes unit tests covering all three scenarios (default, generate,
and LLM fallback).
@YizukiAme YizukiAme marked this pull request as draft April 5, 2026 08:56
@YizukiAme YizukiAme force-pushed the fix/353-354-agent-mode-conditional branch from 443e296 to 4105736 Compare April 5, 2026 08:56
@YizukiAme YizukiAme marked this pull request as ready for review April 5, 2026 08:56
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.

fix: generatedAgentConfigs unconditionally set — default agents polluted as "generated"

1 participant