fix(codex): auto-cleanup broken model_catalog_json on install/update

All scripts now detect and fix leftover damage from previous installs:
- Remove model_catalog_json from config.toml (crashes Codex on startup)
- Delete stale model_catalog.json file
- Detect broken TOML with dotted key bug
Both PS1 scripts and Python patcher handle cleanup before patching.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
delta-cloud-208e
2026-03-08 08:50:33 +00:00
parent fa07058917
commit 60703fc7db
3 changed files with 65 additions and 1 deletions

View File

@@ -458,9 +458,20 @@ def apply_all_patches(config, home_dir=None):
print(f" Proxy: {config['base_url']}")
print()
# Clean up stale model_catalog.json from previous broken installs
stale_catalog = os.path.join(codex_dir, "model_catalog.json")
if os.path.isfile(stale_catalog):
os.remove(stale_catalog)
print(f" {YELLOW}Removed stale model_catalog.json{RESET}")
# Read existing config
existing = read_toml(config_path)
# Remove model_catalog_json if present (wrong format crashes Codex)
if "model_catalog_json" in existing:
del existing["model_catalog_json"]
print(f" {YELLOW}Removed model_catalog_json from config (unsupported format){RESET}")
# Backup before any changes
backup_file(config_path)

View File

@@ -153,14 +153,34 @@ if ($currentVersion -eq $latestVersion) {
$codexConfigDir = "$env:USERPROFILE\.codex"
$codexConfigFile = "$codexConfigDir\config.toml"
if (Test-Path $codexConfigFile) {
# Check if existing config is broken (Codex writes bad TOML with dotted model keys)
$existingContent = Get-Content $codexConfigFile -Raw -ErrorAction SilentlyContinue
$needsCleanup = $false
# Check 1: broken TOML with dotted model keys (gpt-5.4 parsed as gpt-5 -> 4)
if ($existingContent -match "gpt-5\s*=" -and $existingContent -match "\{.*:") {
Write-Host " Detected broken TOML (dotted key bug)" -ForegroundColor Yellow
$needsCleanup = $true
}
# Check 2: model_catalog_json with wrong format (crashes Codex on startup)
if ($existingContent -match "model_catalog_json") {
Write-Host " Detected model_catalog_json (unsupported, removing)" -ForegroundColor Yellow
$needsCleanup = $true
}
if ($needsCleanup) {
Write-Host " Removing broken config.toml..." -ForegroundColor Yellow
Remove-Item $codexConfigFile -Force -ErrorAction SilentlyContinue
}
}
# Clean up stale model_catalog.json if it exists
$staleCatalog = "$codexConfigDir\model_catalog.json"
if (Test-Path $staleCatalog) {
Remove-Item $staleCatalog -Force -ErrorAction SilentlyContinue
Write-Host " Removed stale model_catalog.json" -ForegroundColor Yellow
}
# ---- Apply patches ----
if ($pyCmd) {

View File

@@ -93,6 +93,39 @@ if ($oldVer -eq $latestVer) {
Write-Host " Updated: $oldVer -> $newVer" -ForegroundColor Green
}
# ---- Clean up broken config from previous runs ----
$codexConfigDir = "$env:USERPROFILE\.codex"
$codexConfigFile = "$codexConfigDir\config.toml"
if (Test-Path $codexConfigFile) {
$existingContent = Get-Content $codexConfigFile -Raw -ErrorAction SilentlyContinue
$needsCleanup = $false
# Check 1: broken TOML with dotted model keys
if ($existingContent -match "gpt-5\s*=" -and $existingContent -match "\{.*:") {
Write-Host " Detected broken TOML (dotted key bug)" -ForegroundColor Yellow
$needsCleanup = $true
}
# Check 2: model_catalog_json with wrong format (crashes Codex)
if ($existingContent -match "model_catalog_json") {
Write-Host " Detected model_catalog_json (unsupported, removing)" -ForegroundColor Yellow
$needsCleanup = $true
}
if ($needsCleanup) {
Write-Host " Removing broken config.toml..." -ForegroundColor Yellow
Remove-Item $codexConfigFile -Force -ErrorAction SilentlyContinue
}
}
# Clean up stale model_catalog.json
$staleCatalog = "$codexConfigDir\model_catalog.json"
if (Test-Path $staleCatalog) {
Remove-Item $staleCatalog -Force -ErrorAction SilentlyContinue
Write-Host " Removed stale model_catalog.json" -ForegroundColor Yellow
}
# ---- Download and apply patches ----
$pyCmd = $null