AI SAM Module Installation - Root Cause & Solution
AI SAM Module Installation - Root Cause & Solution
Executive Summary
Problem: Module ai_sam stuck in 'to install' state, never completes installation
Root Cause: Module is orphaned in database with state='to install', but was skipped during dependency graph building because Odoo marked it as "not installable" during runtime
Status:
- ✅ Manifest file is VALID (installable=True)
- ✅ All dependencies are installed
- ✅ Module passes all offline tests
- ❌ Module stuck in 'to install' state in database
- ❌ Odoo runtime marks it "not installable" for unknown reason
What We Found
1. Database State (✅ CONFIRMED)
Module: ai_sam
State: to install <-- STUCK HERE
Version: 18.0.6.5.0
Dependencies: base, web, ai_sam_base (ALL INSTALLED ✅)
2. Manifest File Analysis (✅ VALID)
- File exists:
C:\Program Files\SAM AI\addons\samai_core\ai_sam\__manifest__.py - Size: 11,872 bytes
installable: True✅- All dependencies present ✅
- Syntax valid ✅
3. The Paradox
Standalone Test:
get_manifest('ai_sam') → installable = True ✅
Odoo Runtime (from log):
WARNING: module ai_sam: not installable, skipped ❌
This means something DIFFERENT happens when Odoo loads the manifest during actual installation vs. our standalone test.
The Installation Process (What Goes Wrong)
Step 1: User clicks "Install" button
↓
Step 2: Database record updated: state='to install' ✅
↓
Step 3: Odoo begins registry reload
↓
Step 4: load_marked_modules() queries modules with state='to install'
↓
Step 5: graph.add_modules(['ai_sam']) called
↓
Step 6: For each module in list:
info = get_manifest('ai_sam')
if info and info['installable']: <-- FAILS HERE ❌
add to packages
else:
log "not installable, skipped"
↓
Step 7: ai_sam NOT added to dependency graph
↓
Step 8: Registry loads WITHOUT ai_sam
↓
Step 9: ERROR: "Some modules have inconsistent states: ['ai_sam']"
↓
Result: Module stuck in 'to install' state (orphaned)
Possible Reasons for Runtime Failure
Theory 1: Cached Manifest with Old Data
- Odoo caches manifests with
@functools.lru_cache(maxsize=None) - If a previous attempt failed, cache might have stale data
- Likelihood: HIGH ⭐
Theory 2: Exception During get_manifest()
ir_module.py:170-172catches ALL exceptions and returns{}- If there's ANY error loading manifest, it returns empty dict
- Empty dict →
installablemissing → defaults to False - Likelihood: MEDIUM
Theory 3: Race Condition / Database Lock
- Module state changes to 'to install'
- Immediately tries to load
- Database hasn't fully committed the change?
- Likelihood: LOW
Theory 4: Permission Issue
- Manifest file not readable during Odoo runtime
- Works standalone but fails when Odoo service tries to read it
- Likelihood: LOW (we verified file is readable)
SOLUTION: Step-by-Step Fix
STEP 1: Reset Module State in Database ⭐ START HERE
-- Reset ai_sam to 'uninstalled' state
UPDATE ir_module_module
SET state = 'uninstalled'
WHERE name = 'ai_sam';
How to apply:
Option A: Using psql
set PGPASSWORD=samai_secure_pass
"C:\Program Files\PostgreSQL\15\bin\psql.exe" ^
-U sam_ai_user -d sam_ai ^
-c "UPDATE ir_module_module SET state = 'uninstalled' WHERE name = 'ai_sam';"
Option B: Using the fix script
"C:\Program Files\PostgreSQL\15\bin\psql.exe" ^
-U sam_ai_user -d sam_ai ^
-f C:\Users\total\fix_ai_sam_state.sql
STEP 2: Clear Odoo Cache
Method A: Restart Odoo Service (Recommended)
net stop "SAM AI"
net start "SAM AI"
Method B: Clear Python Cache Manually
- Delete C:\Program Files\SAM AI\data\sessions\*
- Delete any .pyc files in ai_sam module
STEP 3: Verify Manifest Cache is Clear
Add logging to see what get_manifest() returns:
- Edit
C:\Program Files\SAM AI\server\odoo.conf - Add:
ini log_handler = odoo.modules.module:DEBUG,odoo.modules.graph:DEBUG,:INFO - Restart Odoo
- Try installing ai_sam
- Check log for:
DEBUG odoo.modules.module: Loading manifest for ai_sam
STEP 4: Try Installation
- Go to Odoo UI → Apps
- Remove any filters
- Search for "ai_sam"
- Click "Install"
- DO NOT click "Activate" multiple times
- Wait for process to complete
STEP 5: If Still Fails - Nuclear Option
Delete module from database and rediscover:
-- BACKUP FIRST!
-- pg_dump sam_ai > backup.sql
-- Remove module completely
DELETE FROM ir_module_module_dependency
WHERE module_id IN (SELECT id FROM ir_module_module WHERE name = 'ai_sam');
DELETE FROM ir_module_module
WHERE name = 'ai_sam';
Then:
1. Restart Odoo
2. Go to Apps → Update Apps List (top menu)
3. Search for "ai_sam"
4. It should appear as "not installed"
5. Click Install
Advanced Debugging (If Nuclear Option Fails)
Enable Maximum Debug Logging
Add to odoo.conf:
log_level = debug
log_handler = odoo.modules.module:DEBUG,odoo.modules.graph:DEBUG,odoo.modules.loading:DEBUG,odoo.addons.base.models.ir_module:DEBUG,:INFO
Watch for These Specific Log Entries
After restart and install attempt, grep the log:
findstr /C:"ai_sam" "C:\Program Files\SAM AI\logs\odoo.log" > ai_sam_debug.txt
Look for:
1. module ai_sam: no manifest file found → File not found
2. Error when trying to fetch information for module ai_sam → Exception during load
3. module ai_sam: not installable, skipped → installable=False somehow
4. module ai_sam: Unmet dependencies → Dependency issue
Post-Fix Verification
After successful installation, verify:
SELECT name, state, latest_version
FROM ir_module_module
WHERE name = 'ai_sam';
Should show:
name | state | latest_version
--------|-----------|----------------
ai_sam | installed | 18.0.6.5.0
Why This Happened
The most likely scenario:
- First install attempt triggered
- Database marked
state='to install' - Odoo tried to load manifest
- Something failed (exception, cache issue, lock)
- get_manifest() returned
{}or{installable: False} - Module skipped from dependency graph
- Installation completed WITHOUT ai_sam
- Module left orphaned in 'to install' state
- Subsequent attempts see it already "to install" and skip it
The fix: Reset state so Odoo treats it as a fresh install.
Files Generated
fix_ai_sam_state.sql- SQL script to reset module stateai_sam_manifest_test_report.txt- Detailed manifest test resultscheck_ai_sam_state.py- Python script to check current statediagnostic_action_*.py- Individual diagnostic scripts- This file:
SOLUTION_ai_sam_installation.md
Quick Command Reference
Check current state:
python check_ai_sam_state.py
Reset state:
"C:\Program Files\PostgreSQL\15\bin\psql.exe" -U sam_ai_user -d sam_ai -f fix_ai_sam_state.sql
Restart Odoo:
net stop "SAM AI"
net start "SAM AI"
View logs:
notepad "C:\Program Files\SAM AI\logs\odoo.log"
Filter logs for ai_sam:
findstr /C:"ai_sam" "C:\Program Files\SAM AI\logs\odoo.log"
Success Criteria
✅ Module state = 'installed' in database
✅ No "not installable, skipped" warnings in log
✅ No "inconsistent states" errors in log
✅ ai_sam menu appears in Odoo UI
✅ Module features are accessible
Generated: 2025-11-30
Diagnostic Version: 1.0
Next Action: Run STEP 1 (reset state) and STEP 2 (restart Odoo)