- Blocking Generation: When a user creates or updates code, the system generates NUM_VARIANTS (2) variants in parallel using different AI models
- All-or-Nothing: The WebSocket connection remains open until ALL variants complete generation
- No Interactivity During Generation: Users must wait for all variants to finish before they can:
- Select a variant
- Make updates
- Start a new generation
- Lines 286-348: Creates parallel tasks for all variants
- Line 350: Uses
asyncio.gather()to wait for ALL tasks to complete - Line 447: Only closes WebSocket after all variants are done
- Sends messages with
variantIndexto route to correct variant
frontend/src/generateCode.ts: WebSocket client that only triggersonCompletewhen connection closesfrontend/src/App.tsx: SetsAppState.CODINGduring generation, blocking UIfrontend/src/components/variants/Variants.tsx: Only shows variants when generation is complete
User Request → Generate All Variants → Wait for All → Close WS → Show Results → Allow Interaction
User Request → Start Generation → Show First Complete → User Can Interact → Cancel Others if Needed
WebSocket Protocol Enhancement
- Add new message type:
"variantComplete"to signal individual variant completion - Keep WebSocket open after first variant completes
- Add ability to cancel specific variants mid-generation
- Track variant states:
pending,generating,complete,failed,cancelled
Generation Logic
# Instead of:
completions = await asyncio.gather(*tasks, return_exceptions=True)
# Use:
async def process_variants():
for index, task in enumerate(tasks):
try:
completion = await task
await send_message("variantComplete", index)
# Allow frontend to interact immediately
except Exception as e:
await send_message("variantFailed", index)State Management
- Add variant-level state tracking in
project-store.ts:interface VariantState { code: string; status: 'pending' | 'generating' | 'complete' | 'failed' | 'cancelled'; generationTime?: number; }
UI Updates
- Show variant options as soon as first one completes
- Display loading states for incomplete variants
- Enable "Update" button when at least one variant is ready
- Add visual indicators for variant states
WebSocket Client
- Handle new
variantCompletemessage type - Don't wait for WebSocket close to enable interactions
- Track which variants are still generating
Progressive Loading
- Show first variant immediately when ready
- Display skeleton/loading state for pending variants
- Allow switching between completed variants while others generate
Update Flow
- When user starts update with incomplete variants:
- Cancel remaining variant generations
- Start new generation with 2 variants
- Clear previous incomplete variants
Visual Feedback
- Loading spinner on generating variants
- Success checkmark on completed variants
- Subtle animation when variant completes
- Time elapsed indicator
-
Phase 1: Backend Protocol (2-3 days)
- Modify WebSocket message protocol
- Implement per-variant completion tracking
- Add cancellation mechanism
-
Phase 2: Frontend State (2-3 days)
- Update Zustand store for variant states
- Modify WebSocket client handling
- Update commit structure
-
Phase 3: UI Components (2-3 days)
- Update Variants.tsx for progressive display
- Add loading states and animations
- Update Sidebar.tsx for immediate interactions
-
Phase 4: Testing & Polish (2 days)
- Handle edge cases (all variants fail, etc.)
- Performance optimization
- User testing
- Faster Time to First Interaction: Users can work with the first variant immediately
- Better User Experience: No more waiting for slow models when fast ones are ready
- Increased Efficiency: Users can evaluate and iterate faster
- Flexibility: Users can cancel unwanted generations mid-flight
-
Complexity: More state to manage
- Mitigation: Careful state design, comprehensive testing
-
Race Conditions: User updates while variants generating
- Mitigation: Clear cancellation logic, queue management
-
UI Confusion: Users might not understand partial results
- Mitigation: Clear visual indicators, tooltips
- Time to first interaction reduced by ~50%
- User satisfaction with generation speed
- Reduced abandonment during generation
- Increased number of iterations per session