Skip to Content

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-172 catches ALL exceptions and returns {}
  • If there's ANY error loading manifest, it returns empty dict
  • Empty dict → installable missing → 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:

  1. Edit C:\Program Files\SAM AI\server\odoo.conf
  2. Add:
    ini log_handler = odoo.modules.module:DEBUG,odoo.modules.graph:DEBUG,:INFO
  3. Restart Odoo
  4. Try installing ai_sam
  5. Check log for:
    DEBUG odoo.modules.module: Loading manifest for ai_sam

STEP 4: Try Installation

  1. Go to Odoo UI → Apps
  2. Remove any filters
  3. Search for "ai_sam"
  4. Click "Install"
  5. DO NOT click "Activate" multiple times
  6. 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:

  1. First install attempt triggered
  2. Database marked state='to install'
  3. Odoo tried to load manifest
  4. Something failed (exception, cache issue, lock)
  5. get_manifest() returned {} or {installable: False}
  6. Module skipped from dependency graph
  7. Installation completed WITHOUT ai_sam
  8. Module left orphaned in 'to install' state
  9. 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 state
  • ai_sam_manifest_test_report.txt - Detailed manifest test results
  • check_ai_sam_state.py - Python script to check current state
  • diagnostic_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)

Was this helpful?