codex icon indicating copy to clipboard operation
codex copied to clipboard

Codex Windows app crashes on startup with "SqliteError: attempt to write a readonly database"

Open chenhongyuan1 opened this issue 8 months ago • 10 comments

What version of the Codex App are you using (From “About Codex” dialog)?

26.305.950.0

What subscription do you have?

codex business

What platform is your computer?

Microsoft Windows NT 10.0.22631.0 x64

What issue are you seeing?

The Codex Windows desktop app crashes on startup with the following main-process error:

A JavaScript error occurred in the main process Uncaught Exception: SqliteError: attempt to write a readonly database

I already tried Repair, Reset, uninstalling, reinstalling, and deleting local app data.

I also checked the package container under: C:\Users<username>\AppData\Local\Packages\OpenAI.Codex_2p2nqsd0c76g0

The container appears to be writable because files such as:

  • Settings\settings.dat
  • Settings\roaming.lock
  • SystemAppData\Helium\User.dat
  • SystemAppData\Helium\UserClasses.dat

are created or updated successfully.

Windows Defender Controlled Folder Access is disabled, and I did not find evidence that Defender or AppLocker is blocking Codex.

However, the app still crashes before becoming usable, with: SqliteError: attempt to write a readonly database

It looks like the app may be trying to open or create a SQLite database in an unexpected non-writable location, or there may be a startup bug in version 26.305.950.0.

Image

What steps can reproduce the bug?

  1. Install the Codex Windows app from the Microsoft Store.
  2. Launch the app.
  3. Wait for startup to complete.
  4. A dialog appears immediately with: "A JavaScript error occurred in the main process" "SqliteError: attempt to write a readonly database"

I can reproduce this consistently after reinstalling the app.

What is the expected behavior?

The app should start normally and initialize its local state/database in a writable per-user location without crashing.

Additional information

I already tried Repair, Reset, uninstalling/reinstalling the app, and deleting local app data before reinstalling.

I checked the package container at: C:\Users<username>\AppData\Local\Packages\OpenAI.Codex_2p2nqsd0c76g0

The container is writable, because files such as Settings\settings.dat, Settings\roaming.lock, SystemAppData\Helium\User.dat, and SystemAppData\Helium\UserClasses.dat are created or updated successfully.

Windows Defender Controlled Folder Access is disabled, and I did not find evidence that Defender or AppLocker is blocking the app.

No app-local .db, .sqlite, .sqlite3, or .ldb file appears to be created before the crash, which suggests the app may be opening SQLite from an unexpected non-writable location or hitting a startup bug in version 26.305.950.0.

chenhongyuan1 avatar Mar 08 '26 14:03 chenhongyuan1

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #13553
  • #12974

Powered by Codex Action

github-actions[bot] avatar Mar 08 '26 14:03 github-actions[bot]

同样的情况!js类型写入sqlite错误。✔️我尝试把defender和其他安全组件都关闭了,用管理员权限启动codex,发现一切正常了,你可以作为参考

a1409606731 avatar Mar 11 '26 03:03 a1409606731

Workaround for Users (How to fix it now)

To fix this, you need to delete the local state database so the application can regenerate it from scratch with the new migration checksums.

Note: This will reset your local app state, but it will allow the app to launch successfully.

For Windows Users:

  1. Close the Codex application completely.
  2. Open File Explorer and navigate to your user profile's .codex directory: C:\Users\<YourUsername>\.codex\
  3. Delete the following files (if they exist):
    • state_5.sqlite
    • state_5.sqlite-shm
    • state_5.sqlite-wal
  4. Launch the application again. (If you are using WSL, the path is /mnt/c/Users/<YourUsername>/.codex/)

tebriz91 avatar May 21 '26 13:05 tebriz91

@tebriz91 Thanks, it work

nguyenytran avatar May 22 '26 01:05 nguyenytran

Confirmed Recovery: SQLite Rollback Journal — Windows Desktop Startup Failure

I encountered the same startup error in the Windows ChatGPT desktop application using the OpenAI.Codex package. Reinstalling the application did not resolve the problem.

Through a structured diagnostic process conducted with ChatGPT, I identified an outstanding SQLite rollback journal associated with .codex-global-state.sqlite in the persistent user-data directory.

Rather than deleting the database or resetting the application, I successfully recovered it using SQLite's native rollback recovery mechanism through Python's standard-library sqlite3 module.

The recovery was first tested on an isolated copy. After the integrity check passed and SQLite automatically resolved the rollback journal, the procedure was repeated on the original database. The desktop application subsequently launched successfully.

I am contributing the sanitized diagnostic and recovery protocol for the benefit of other affected users and the OpenAI engineering team.

This is a validated recovery procedure from one observed incident, not a definitive identification of the underlying software defect. Personal information and machine-specific diagnostic data have been intentionally omitted.

ChatGPT Desktop SQLite Startup Failure - Diagnostic and Recovery Protocol

Project: Public technical troubleshooting contribution
Chat: Desktop startup database recovery (sanitized)
Prepared with: ChatGPT, GPT-6.2
Date: November 2026 (month-level precision for privacy)
Version: 1.0

Summary

A Windows ChatGPT desktop application using the OpenAI.Codex package failed to start with attempt to write a readonly database. Reinstallation did not resolve the error. Native SQLite rollback recovery of .codex-global-state.sqlite restored application startup without deleting the database or resetting application state.

This is a single observed case, not an official OpenAI fix or a guarantee for other installations. The underlying reason the application could not perform recovery itself remains unknown. No reliable procedure for deliberately reproducing the initial failure was established.

Diagnostic findings

  • The installed package was identified as OpenAI.Codex using PowerShell.
  • Browser-cache databases did not have the Windows ReadOnly attribute. The primary application state was found outside the installation directory, under $env:USERPROFILE\.codex.
  • The user account had full control of the directory, the global-state database and its rollback journal. Creating a temporary file in the directory succeeded. This did not prove that the application had equivalent effective access.
  • .codex-global-state.sqlite-journal was nonempty and contained the SQLite rollback-journal magic bytes D9 D5 05 F9 20 A1 63 D7.
  • Other SQLite WAL and SHM files were present. Their presence alone did not indicate corruption.
  • The OpenAI Chrome native messaging process was extension-host.exe, not the initially suspected executable name. Its involvement in the failure was not independently established.

1. Identify application storage and inspect permissions

Run each command separately in Windows PowerShell under the affected Windows account. Close the desktop application first. Do not change WindowsApps permissions or weaken security controls.

Get-AppxPackage *OpenAI* | Format-List Name, Version, PackageFamilyName, InstallLocation
Get-ChildItem "$env:USERPROFILE\.codex" -Force -File | Format-Table Name, Attributes, Length, LastWriteTime -AutoSize
icacls "$env:USERPROFILE\.codex"
icacls "$env:USERPROFILE\.codex\.codex-global-state.sqlite*"

Optional directory write test (creates and removes only a uniquely named temporary file):

$t = Join-Path "$env:USERPROFILE\.codex" ("write-test-" + [guid]::NewGuid() + ".tmp"); New-Item -Path $t -ItemType File -ErrorAction Stop; Remove-Item -LiteralPath $t -ErrorAction Stop

2. Quiesce application processes

Save work, quit the desktop application, and temporarily disable its browser extension if necessary. Disable automatic desktop startup temporarily if it keeps relaunching. Inspect matching processes:

Get-CimInstance Win32_Process | Where-Object { $_.ExecutablePath -like '*OpenAI*' -or $_.Name -match 'codex|chatgpt|native.host' } | Format-List Name, ProcessId, ParentProcessId, ExecutablePath

If the OpenAI extension host remains active, the following targets only processes whose executable path identifies the OpenAI.Codex installation:

Get-Process -Name extension-host -ErrorAction SilentlyContinue | Where-Object { $_.Path -like '*OpenAI.Codex*' } | Stop-Process -Force -ErrorAction Stop

Recheck the process listing. If the application or a process accessing the database remains active, stop here until it is closed. Do not terminate unrelated native hosts. A process-name check alone cannot prove that every database handle is closed.

3. Preserve the database and its journal together

The following commands use new timestamped folders. Keep the same PowerShell session for the variables. Execute each line separately and stop if any error occurs. These folders may contain sensitive local application state; do not upload or share them.

$source = Join-Path $env:USERPROFILE '.codex'
$backup = Join-Path $env:USERPROFILE ('Codex-Backup-' + (Get-Date -Format yyyyMMdd-HHmmss))
New-Item -ItemType Directory -Path $backup -ErrorAction Stop
Copy-Item "$source\.codex-global-state*" -Destination $backup -ErrorAction Stop
Get-ChildItem $backup -Force

Verify that the database and its journal are present and that their sizes and hashes match the originals before proceeding. If other companion files exist, preserve those too. The following compares all copied files:

Get-ChildItem $backup -Force -File | ForEach-Object { [pscustomobject]@{ Name = $_.Name; Match = ((Get-FileHash -LiteralPath $_.FullName -ErrorAction Stop).Hash -eq (Get-FileHash -LiteralPath (Join-Path $source $_.Name) -ErrorAction Stop).Hash) } }

All matches must be True. If the originals change during backup, stop and establish that the application is fully closed before making a fresh backup.

Inspect the backup journal header:

Format-Hex -Path (Join-Path $backup '.codex-global-state.sqlite-journal') | Select-Object -First 2

The magic bytes above support identification of a SQLite rollback journal but are not alone sufficient to establish that it is hot or recoverable. Never manually delete an outstanding journal.

4. Test native SQLite recovery on a disposable copy

Python 3 with its standard-library sqlite3 module is required. The observed recovery used Python 3.12. Check availability:

Get-Command python, py, sqlite3 -ErrorAction SilentlyContinue | Format-Table Name, Source -AutoSize

Create a separate working directory and copy the database and companions from the preserved backup:

$recovery = Join-Path $env:USERPROFILE ('Codex-Recovery-' + (Get-Date -Format yyyyMMdd-HHmmss))
New-Item -ItemType Directory -Path $recovery -ErrorAction Stop
Copy-Item "$backup\.codex-global-state.sqlite*" -Destination $recovery -ErrorAction Stop
$env:CODEX_RECOVERY_DB = Join-Path $recovery '.codex-global-state.sqlite'

Open the existing database in read-write mode, allowing SQLite to perform any necessary rollback recovery, and run an integrity check:

python -c "import os, sqlite3, pathlib; p=pathlib.Path(os.environ['CODEX_RECOVERY_DB']); c=sqlite3.connect(p.as_uri()+'?mode=rw', uri=True); print('Integrity check:', c.execute('PRAGMA integrity_check').fetchall()); c.close()"

Expected result in this case:

Integrity check: [('ok',)]
Get-ChildItem $recovery -Force

In the observed case, SQLite automatically removed the rollback journal and the database passed the integrity check. If recovery fails, the journal remains unexpectedly, or integrity checking reports anything other than ok, stop rather than deleting files or attempting the procedure on the original.

5. Recover the original database

Only proceed after confirming successful recovery on the copy, verifying the preserved backup, and ensuring the application and processes accessing its database remain closed. Check the backup hashes against the originals again; if they differ, reassess and make a new consistent backup.

This command can modify the original database as SQLite performs rollback recovery. Uncommitted transaction changes may be rolled back. Structural integrity does not guarantee that all application-level state is intact.

python -c "import sqlite3, pathlib; p=pathlib.Path.home()/'.codex'/'.codex-global-state.sqlite'; c=sqlite3.connect(p.as_uri()+'?mode=rw', uri=True); print('Integrity check:', c.execute('PRAGMA integrity_check').fetchall()); c.close()"
Get-ChildItem "$env:USERPROFILE\.codex\.codex-global-state.sqlite*" -Force

In the observed case the integrity check returned ok, and the rollback journal was automatically removed. Launch the desktop application normally only after successful checks. If the error persists, retain the backup and seek further diagnostics instead of indiscriminately modifying other databases.

Observed outcome and engineering implications

The application launched successfully after native recovery of the original database. No database was manually deleted, and no application reset was needed for the successful recovery procedure. Full preservation of application-level state was not independently audited.

The result supports the hypothesis that an outstanding rollback transaction contributed to the startup failure. The native host was also stopped before final recovery, so its independent contribution cannot be excluded. No specific application defect, security-context failure or update mechanism was conclusively identified.

Suggested engineering investigation: determine why startup could not recover the global-state rollback journal under the application's effective security context, and consider safe recovery handling and more specific diagnostics (database path, SQLite extended error code, and recovery status, with privacy controls).

References

  • Related OpenAI issue: https://github.com/openai/codex/issues/13971
  • SQLite locking and hot journals: https://www.sqlite.org/lockingv3.html
  • SQLite result codes: https://www.sqlite.org/rescode.html
  • SQLite integrity check: https://www.sqlite.org/pragma.html#pragma_integrity_check

Privacy and methodology note

This report was prepared from an actual troubleshooting session with ChatGPT assistance. Personal identifiers, exact system/build versions, exact incident timestamps, machine-specific paths, screenshots, logs, third-party applications and database contents have been omitted. Generic application filenames and environment-variable paths are retained for reproducibility. The commands were generalized from the observed procedure; timestamped working folders, hash verification and additional stop conditions are recommended safeguards, not separately observed test results.

Daveremory avatar Nov 24 '26 15:11 Daveremory

Follow-up on the Windows desktop startup failure with OpenAI.Codex version 26.1120.5083.0: during the first incident, opening a copy of .codex-global-state.sqlite with its rollback journal in read-only mode reproduced SQLite extended error 776 (SQLITE_READONLY_ROLLBACK). Opening the copy with write access let SQLite complete recovery. PRAGMA integrity_check returned ok, and the desktop app started with the recovered database.

The recovery was temporary. The startup failure has since recurred. Error 776 was verified for the first incident only. Could the desktop team check whether startup can handle a pending rollback before reading global settings, and let us know if a release addresses this case?

Confirmed on Windows 11, November 24, 2026.

The ChatGPT desktop app failed to start with the following error: ChatGPT failed to start. attempt to write a readonly database

Possible trigger: simultaneous updates through Microsoft Store and the application's built-in updater. This has not been independently confirmed.

What did not work: Windows Settings → Apps → ChatGPT → Repair.

What worked: Closing the application. Backing up .codex-global-state.sqlite and its companion files. Opening the database in read-write mode using Python's SQLite module. Running PRAGMA integrity_check. The application launched successfully after this procedure, without reinstalling or resetting it. This provides another confirmation that native SQLite recovery can resolve the startup failure.

Please consider implementing automatic database recovery during application startup and investigating potential conflicts between update mechanisms.

ilyaobryvin avatar Nov 25 '26 20:11 ilyaobryvin

I encountered the same error on the ChatGPT desktop app for Windows 11 after my laptop abruptly powered off due to a depleted battery while I was recording a voice dictation.

After restarting, ChatGPT repeatedly failed to launch with attempt to write a readonly database. Rebooting did not help. Opening %USERPROFILE%\.codex\.codex-global-state.sqlite in read-write mode using Python's sqlite3 and running PRAGMA integrity_check resolved the issue.

Please consider implementing automatic SQLite recovery on startup after an unexpected shutdown so users do not need to repair the database manually.

SHS2030 avatar Nov 25 '26 20:11 SHS2030

I ran into the same issue on November 26 after a Windows BSOD (MEMORY_MANAGEMENT, 0x1A). I've managed to get the desktop app working again without resetting it or losing my existing local work records. Sharing my findings here in case they help the team narrow down the issue.

Environment

  • Windows 11 25H2 (Build 26200.9445)
  • ChatGPT desktop app: 26.1120.6357.0
  • Package: OpenAI.Codex
  • Python 3.12.13 / SQLite 3.53.2

What I found

The Windows built-in app repair did not resolve the startup error. After some investigation, I found two files under %USERPROFILE%\.codex\:

  • .codex-global-state.sqlite (38,166,528 bytes)
  • .codex-global-state.sqlite-journal (8,720 bytes)

Both had been modified around the time of the crash. Neither had the ReadOnly attribute, and my Windows user account had full control over both files and their parent directory.

This made me suspect an interrupted SQLite transaction rather than a conventional file permission issue.

How I reproduced and resolved it

After closing the relevant Codex processes and stopping CodexSandboxService.OpenAI.Codex, I backed up the database and its journal, verified their SHA-256 hashes, and performed the following tests on an isolated copy.

Test Result
Read-only connection (mode=ro) + PRAGMA integrity_check SQLITE_READONLY_ROLLBACK (776)
Read-write connection (mode=rw) + PRAGMA integrity_check ok
Read-only connection after recovery ok

The first test reproduced the exact same error message shown by the desktop app:

OperationalError: attempt to write a readonly database
SQLITE_ERROR_CODE: 776
SQLITE_ERROR_NAME: SQLITE_READONLY_ROLLBACK

Simply opening the database in read-write mode and running the integrity check allowed SQLite to perform its native rollback recovery. The journal was automatically removed by SQLite.

Once I had verified the recovery on the isolated copy, I repeated the procedure on the original database. Both integrity checks passed, and the recovered original database and the recovered test copy had identical SHA-256 hashes.

After restarting the sandbox service, the desktop app launched normally and passed my functional checks.

No app reset, reinstallation, manual journal deletion, or permission changes were needed.

A possible direction for investigation

I wonder if the startup sequence attempts to read global application state before SQLite has had a chance to recover an outstanding rollback journal after an unexpected shutdown.

If so, a safe recovery step before read-only access might prevent this issue. Including the affected database path and SQLite extended error code in the startup error dialog would also make troubleshooting considerably easier.

To be clear, I reproduced error 776 externally using Python's SQLite module, not directly from the application's internal logs. I haven't inspected the desktop implementation, so this is a verified recovery case rather than a confirmed root cause in the application code.

I worked through the investigation with ChatGPT's assistance and verified each recovery step locally. Hopefully this provides another useful data point for the team.


简体中文补充

我在 11 月 26 日遇到了相同的问题。当时 Windows 发生 MEMORY_MANAGEMENT (0x1A) 蓝屏,恢复进入桌面后,ChatGPT 客户端一直报数据库只读错误,无法启动。

Windows 自带的应用修复没有解决问题。进一步排查发现,%USERPROFILE%\.codex\ 下的 .codex-global-state.sqlite 存在遗留的回滚日志,两个文件的最后修改时间均与蓝屏时间接近,但文件本身没有只读属性,当前用户也拥有完整的访问权限。

为避免损坏原有数据,我先停止相关进程和后台服务,对数据库及其回滚日志进行备份和 SHA-256 校验,然后在独立副本上进行测试:

  • 只读连接:成功复现 SQLITE_READONLY_ROLLBACK (776)。
  • 读写连接:SQLite 自动完成事务回滚,完整性检查通过,回滚日志被自动移除。
  • 再次建立只读连接:完整性检查通过。

确认副本恢复成功后,我对原始数据库执行了相同的操作。恢复后的原始数据库与测试副本具有完全一致的 SHA-256 哈希值。重新启动后台服务后,ChatGPT 客户端恢复正常,功能验收通过。

整个过程无需重置或重新安装应用,也没有手动删除回滚日志或修改文件权限。

建议团队检查客户端启动时对 SQLite 未完成事务的恢复机制,并考虑在启动错误弹窗中提供具体的数据库路径及 SQLite 扩展错误码。

目前能够确认的是故障复现及恢复方案的有效性,尚不能确定客户端内部的具体缺陷。此次排查在 ChatGPT 的辅助下完成,各项恢复操作均经过本地实际验证。

希望这些信息能够为问题定位提供一些帮助。

Charlie-Wang-03 avatar Nov 26 '26 16:11 Charlie-Wang-03

Confirmed on Linux: pending global-state rollback journal blocks desktop startup

I encountered the same failure and recovery pattern on Linux on 29 November 2026. OpenAI Support directed me to this issue tracker. This adds Linux evidence to the Windows reports above.

Environment

  • ChatGPT Debian package: 26.1117.41037
  • Executable: /usr/lib/chatgpt/ChatGPT
  • Linux Mint 21.3 (Ubuntu 22.04 base), x86_64
  • Kernel: 6.8.0-149-generic; Cinnamon/X11

Observed behavior

The desktop app left its main process running with a blank-titled window and no renderer process. Launching it again printed Opening in existing browser session. No usable interface appeared.

Startup log:

2026-11-29T08:13:31.320Z error Desktop bootstrap failed to start the main app
errorCode=ERR_SQLITE_ERROR
errorMessage="attempt to write a readonly database"
errorName=Error
phase=bootstrap-import-main

Error: attempt to write a readonly database
    at e.evaluateImpl (/usr/lib/chatgpt/resources/app.asar/.vite/build/early-bootstrap-7-c91366067f482dd9.js:1043:98349)
    at e.evaluateWithDepth (/usr/lib/chatgpt/resources/app.asar/.vite/build/early-bootstrap-7-c91366067f482dd9.js:1043:96071)
    at e.evaluate (/usr/lib/chatgpt/resources/app.asar/.vite/build/early-bootstrap-7-c91366067f482dd9.js:1043:95955)
    at K.readLoop (/usr/lib/chatgpt/resources/app.asar/.vite/build/early-bootstrap-7-c91366067f482dd9.js:1043:114611)

Database findings

  • ~/.codex/.codex-global-state.sqlite: 4,509,696 bytes.
  • ~/.codex/.codex-global-state.sqlite-journal: 12,824 bytes.
  • Both files were owned by the logged-in user with mode 0644; the parent directory was user-owned and writable.
  • Neither file had the immutable attribute. Approximately 85 GB of disk space was available.

Reproduction from the captured database state

I copied the database and its journal together into an isolated temporary directory and tested with Python's standard-library sqlite3:

Test Result
Read-only connection (mode=ro) + PRAGMA quick_check attempt to write a readonly database
Normal read/write connection + PRAGMA quick_check ok after SQLite recovery
Read-only connection after recovery + PRAGMA quick_check ok

The extended SQLite error code was not captured in my test, so I cannot independently confirm error 776 for this Linux incident. The original event that left the pending journal is unknown; I have not reproduced the initial application failure from a clean profile.

Verified recovery

After validating the procedure on the copy, I stopped the failed desktop process, backed up the original database and journal, and opened the original database with a normal read/write SQLite connection. PRAGMA quick_check returned ok. Relaunching the app loaded the main window and completed app-server initialization successfully. I confirmed that the GUI works.

No database reset, manual journal deletion, reinstall, or permission change was needed.

Expected behavior

The desktop startup path should allow SQLite to recover a pending rollback journal before reading global state. If recovery is unavailable, the app should show an actionable error rather than leave an unusable background instance.

The tests support the pending-journal recovery explanation, but do not establish the application's exact internal open mode or the cause of the interrupted transaction. This is one verified Linux incident and workaround, not evidence that recurrence is prevented.

No database contents or private diagnostic bundles are attached.

KonstantinMitish avatar Nov 29 '26 08:11 KonstantinMitish