Issue 1: Forecasting demand insights not triggered in demo workflow
- Created internal ML endpoint: /forecasting/internal/ml/generate-demand-insights
- Added trigger_demand_insights_internal() to ForecastServiceClient
- Integrated forecasting insights into demo session post-clone workflow
- Now triggers 4 AI insight types: price, safety stock, yield, + demand
Issue 2: RabbitMQ client cleanup error in procurement service
- Fixed: rabbitmq_client.close() → rabbitmq_client.disconnect()
- Added proper cleanup in exception handler
- Error: "'RabbitMQClient' object has no attribute 'close'"
Files modified:
- services/forecasting/app/api/ml_insights.py (new internal_router)
- services/forecasting/app/main.py (register internal router)
- shared/clients/forecast_client.py (new trigger method)
- services/demo_session/app/services/clone_orchestrator.py (+ demand insights)
- services/procurement/app/api/internal_demo.py (fix disconnect)
Expected impact:
- Demo sessions will now generate demand forecasting insights
- No more RabbitMQ cleanup errors in logs
- AI insights count should increase from 1 to 2-3 per session
🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fixed two critical issues preventing forecast data from being cloned:
1. **Missing batch_name field**: The fixture uses `batch_id` but the
PredictionBatch model requires `batch_name` (NOT NULL constraint).
Added field mapping to handle batch_id -> batch_name conversion.
2. **UUID type mismatch**: The fixture's `product_id` is a string but
the Forecast model expects `inventory_product_id` as UUID type.
Added conversion from string to UUID.
3. **Field mappings added**:
- batch_id -> batch_name
- total_forecasts -> total_products
- created_at -> requested_at (fallback)
- Calculated completed_products from status
These fixes enable the forecasting service to successfully clone all
28 forecasts from the fixture file, unlocking demand forecasting
AI insights in demo sessions.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Fixed AttributeError in procurement service ml_insights.py
- PurchaseOrderItem model uses inventory_product_id, not ingredient_id
- This resolves the forecasting errors for ingredients
Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
- Fixed ProductType enum values from lowercase to uppercase (INGREDIENT, FINISHED_PRODUCT)
- Fixed UnitOfMeasure enum values from lowercase/abbreviated to uppercase (KILOGRAMS, LITERS, etc.)
- Fixed IngredientCategory enum values from lowercase to uppercase (FLOUR, YEAST, etc.)
- Fixed ProductCategory enum values from lowercase to uppercase (BREAD, CROISSANTS, etc.)
- Updated seed data files to use correct uppercase enum values
- Fixed hardcoded enum references throughout the codebase
- This resolves the InvalidTextRepresentationError when inserting inventory data
Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Repairs enterprise demo tenants created before naming standardization that have:
- Missing TenantMember records (causing has_access: false)
- Wrong owner_id (María instead of Carlos)
- Old business_model values (enterprise_parent/enterprise_chain)
This fixes tenant 3fe07312-b325-4b40-97dd-c8d1c0a67ec7 which was returning
has_access: false because it had no tenant_members records.
The script:
1. Updates tenant to use correct enterprise owner (Carlos)
2. Standardizes business_model to 'enterprise'
3. Creates all required TenantMember records (owner + 6 staff)
Applied successfully - tenant now has 7 members including owner.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Standardize demo account type naming from inconsistent variants to clean names:
- individual_bakery, professional_bakery → professional
- central_baker, enterprise_chain → enterprise
This eliminates naming confusion that was causing bugs in the demo session
initialization, particularly for enterprise demo tenants where different
parts of the system used different names for the same concept.
Changes:
- Updated source of truth in demo_session config
- Updated all backend services (middleware, cloning, orchestration)
- Updated frontend types, pages, and stores
- Updated demo session models and schemas
- Removed all backward compatibility code as requested
Related to: Enterprise demo session access fix
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
The date adjustment logic was correct. The BASE_REFERENCE_DATE is used
by adjust_date_for_demo() to calculate offsets relative to demo session
creation time, not to filter for "today's" data.
Production batches showing "Sin Plan" must have a different root cause.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
1. **Fix "Sin Plan" (No Production Planned)**:
- Updated BASE_REFERENCE_DATE from Nov 25 to Nov 27 to match current date
- Production batches were being filtered out because they were dated for Nov 25
- The get_todays_batches() method filters for batches scheduled TODAY
2. **Fix "Ver razonamiento" Button Not Opening Modal**:
- Changed handleOpenReasoning() to always emit 'reasoning:show' event
- Previous logic tried to navigate to PO/batch detail pages instead
- Now keeps user on dashboard and shows reasoning modal inline
- Passes all metadata (action_id, po_id, batch_id, reasoning) in event
This ensures production progress shows correctly and users can view
AI reasoning without leaving the dashboard.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Removed debugging logs added during infinite loop investigation.
The fix has been verified and these logs are no longer needed.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Update BASE_REFERENCE_DATE from January 15, 2025 to November 25, 2025
to ensure demo data appears recent and relevant.
This fixes the "11 meses" (11 months) display issue in GlanceableHealthHero
where lastOrchestrationRun was showing an 11-month-old timestamp.
The BASE_REFERENCE_DATE is used by all demo seeding scripts to calculate
relative dates. With the updated reference date, the most recent
orchestration runs will show as "hace 2 días" or similar instead of
"hace 11 meses".
Impact:
- All demo seed data timestamps will be relative to Nov 25, 2025
- Dashboard will show "Last run: 2 days ago" instead of "11 months ago"
- Expiration dates, delivery dates, and other temporal data remain
properly offset from the new reference
Fixes: Issue #6 - "11 meses" data bug
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
UnifiedActionQueueCard changes:
- Update container: shadow-xl, border-2, hover:shadow-2xl
- Add large hero icon (w-16 h-16 md:w-20 md:h-20) with AlertCircle
- Colored background based on queue urgency (red/blue)
- Upgrade title to text-2xl md:text-3xl font-bold
- Move total actions and SSE status to inline metric badges
ExecutionProgressTracker changes:
- Update container: shadow-xl, border-2, hover:shadow-2xl
- Add large hero icon (w-16 h-16 md:w-20 md:h-20) with TrendingUp
- Primary color background for hero icon
- Upgrade title to text-2xl md:text-3xl font-bold
Both cards now match the visual weight and hero pattern of
GlanceableHealthHero and IntelligentSystemSummaryCard for
consistent dashboard hierarchy and improved scannability.
Fixes: Issue #1 - Style alignment
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Backend changes (dashboard_service.py):
- Collect in-progress batch details with id, batchNumber, productName, etc.
- Add inProgressBatches array to production progress response
Frontend changes (ExecutionProgressTracker.tsx):
- Update ProductionProgress interface to include inProgressBatches array
- Display batch names and numbers under "En Progreso" count
- Show which specific batches are currently running
Users can now see which production batches are in progress
instead of just a count (e.g., "• Pan (BATCH-001)").
Fixes: Issue #5 - Missing production batch details
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Create ReasoningModal component with AI reasoning display
- Add business impact section (financial impact, affected orders)
- Add urgency context display (time remaining)
- Wire up 'reasoning:show' event listener in UnifiedActionQueueCard
- Export ReasoningModal from domain/dashboard index
The smartActionHandlers already emit the 'reasoning:show' event,
this adds the missing listener and modal to display the AI reasoning
when users click "See Full Reasoning" on alerts.
Fixes: Issue #2 - "See Full Reasoning" button not working
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Remove `startTour` from useEffect dependency array (line 434)
- Remove notification arrays from useEffect deps (lines 182, 196, 210)
- Add temporary console.log debugging for notification effects
- Fix prevents "Maximum update depth exceeded" error
The latestBatchNotificationId is already memoized and designed to
prevent re-runs. Including the full arrays causes React to re-run
the effect when array references change even with same content.
Fixes: Issue #3 - Infinite Loop
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Root cause: params = reasoning_data.get('parameters', {}) created a reference
to the dictionary instead of a copy. When modifying params to add
product_names_joined, the change didn't persist because the database object
was immutable/read-only.
Changes:
- dashboard_service.py:408 - Create dict copy for PO params
- dashboard_service.py:632 - Create dict copy for batch params
- Added clean_old_dashboard_data.py utility script to remove old POs/batches
with malformed reasoning_data
The fix ensures template variables like {{supplier_name}}, {{product_names_joined}},
{{days_until_stockout}}, etc. are properly interpolated in the dashboard.
This commit fixes the template interpolation issues where variables like
{{supplier_name}}, {{product_names_joined}}, {{current_stock}}, etc. were
showing as literal strings instead of being replaced with actual values.
Changes made:
1. **Dashboard Service (Orchestrator):**
- Added missing `current_stock` parameter to default reasoning_data for
production batches
- This ensures all required template variables are present when batches
don't have proper reasoning_data from the database
2. **Production Service:**
- Updated batch creation to properly populate `product_name` field
- Improved product name resolution to check forecast data and stock_info
before falling back to placeholder
- Added missing `product_id` field to batch_data
- Added required `planned_duration_minutes` field to batch_data
- Ensures reasoning_data has all required parameters (product_name,
predicted_demand, current_stock, confidence_score)
The root cause was that the default reasoning_data used by the dashboard
service when database records lacked proper reasoning_data was missing
required parameters. This resulted in i18n template variables being
displayed as literal {{variable}} strings instead of interpolated values.
Fixes dashboard display issues for:
- Purchase order cards showing {{supplier_name}}, {{product_names_joined}},
{{days_until_stockout}}
- Production plan items showing {{product_name}}, {{predicted_demand}},
{{current_stock}}, {{confidence_score}}
This commit resolves three critical translation/localization issues in the bakery dashboard:
1. **Health Status Translation Keys**: Fixed HealthStatusCard's translateKey function to properly handle `dashboard.health.*` keys by correctly stripping the `dashboard.` prefix while preserving the `health.` namespace path. This ensures checklist items like "production_on_schedule" and "all_ingredients_in_stock" display correctly in Spanish.
2. **Reasoning Translation Keys**: Updated backend dashboard_service.py to use the correct i18n key prefixes:
- Purchase orders now use `reasoning.purchaseOrder.*` instead of `reasoning.types.*`
- Production batches now use `reasoning.productionBatch.*`
- Added context parameter to `_get_reasoning_type_i18n_key()` method for proper namespace routing
3. **Template Variable Interpolation**: Fixed template variable replacement in action cards:
- Added array preprocessing logic in both backend and frontend to convert `product_names` arrays to `product_names_joined` strings
- Updated ActionQueueCard's translateKey to preprocess array parameters before i18n interpolation
- Fixed ProductionTimelineCard to properly handle reasoning namespace prefix removal
These fixes ensure that:
- Health status indicators show translated text instead of raw keys (e.g., "Producción a tiempo" vs "dashboard.health.production_on_schedule")
- Purchase order reasoning displays with proper product names and stockout days instead of literal template variables (e.g., "Stock bajo para Harina. El stock se agotará en 7 días" vs "Stock bajo para {{product_name}}")
- All dashboard components consistently handle i18n key namespaces and parameter interpolation
Affected files:
- frontend/src/components/dashboard/HealthStatusCard.tsx
- frontend/src/components/dashboard/ActionQueueCard.tsx
- frontend/src/components/dashboard/ProductionTimelineCard.tsx
- services/orchestrator/app/services/dashboard_service.py