AI Learning Tiers - Toggle Fix

Fixed Tier 1 toggle reverting to OFF issue

AI Learning Tiers - Toggle Fix

Problem

When enabling Tier 1: Development AI in the learning dashboard, it would immediately revert back to OFF.

Root Cause

  1. Frontend tried to save tier settings to /api/ai-agents/settings (endpoint doesn't exist)
  2. Every 30 seconds, frontend polled /api/ai-agents/stats/summary for tier stats
  3. Backend returned hardcoded tier1.active: false with comment "managed locally via MCP"
  4. Frontend overwrote local settings with backend response → Toggle reverted to OFF

The Fix

Changed 3 things in ai-learning-dashboard.component.ts:

1. Removed Failed Backend Call

// OLD: Tried to save to non-existent endpoint
await firstValueFrom(
  this.http.patch(`${this.API_BASE}/settings`, { [key]: newValue })
);

// NEW: Local-only toggle (no backend call)
this.addEvent({
  type: 'sync',
  message: `Tier ${tierIndex + 1} ${newValue ? 'enabled' : 'disabled'} (local)`,
  tier: tierIndex + 1,
  timestamp: new Date(),
  success: true,
});

2. Use Local Setting for Tier 1 Status

// OLD: Backend overwrites status
status: stats.tier1?.active ? 'active' : 'inactive',

// NEW: Use local setting
status: this.settings().tier1Enabled ? 'active' : 'inactive',

3. Persist Settings with autoFlashState

// OLD: Lost on page reload
readonly settings = signal({ tier1Enabled: true, ... });

// NEW: Persists across reloads
readonly settings = autoFlashState('ai-learning-dashboard/settings', {
  tier1Enabled: true,
  tier2Enabled: true,
  tier3Enabled: true,
  ...
});

Result

✅ Tier 1 toggle now works correctly
✅ Settings persist across page reloads
✅ No more "INACTIVE" revert

Architecture Notes

Tier 1: Development AI (Local)

Tier 2: Platform AI (Backend)

Tier 3: Tenant AI (Tenant Config)

Testing

  1. Open AI Learning Dashboard
  2. Toggle Tier 1: Development AI to ON
  3. Wait 30+ seconds (stats refresh interval)
  4. ✅ Should stay ON (not revert to OFF)
  5. Refresh page
  6. ✅ Should still be ON (persisted)

Fixed: December 10, 2025
Session: 13
Files Modified: