| Error | A JavaScript error occurred in the main process / Uncaught Exception: Error: Peer closed MessagePort connection. |
|---|---|
| Tool | Codex in the ChatGPT (Codex) desktop app. Most reports are from Windows (Microsoft Store package OpenAI.Codex 26.1117 and 26.1120); macOS too |
| Common trigger | Sending, pasting or dropping many or large images. Reports: 10 to 151 images, 257 to 466 MiB of queued data |
| Log line | RangeError: Message exceeds the 536870912-byte serialization limit. |
| Fix | Remove the unsent message: in the app if it opens, or empty queued-follow-ups in .codex-global-state.sqlite after a backup |
| Status | Reported by users, not official. No OpenAI reply on GitHub as of 4 Dec 2026 |
| Checked | 4 Dec 2026, against the sources listed below |
Fix it
These steps come from users who recovered on Windows and macOS (issues #64073, #63217, #63610, #63104). OpenAI has not confirmed them.
- Quit the app completely. Close it from the system tray too, not just the window.
- Try the gentle fix first. If you can still open the chat where you attached the images, remove the unsent attachments and the draft there. One user did only this, without touching any files, and the queued data dropped from 317.5 MiB to 34.2 MiB. Text messages then worked again.
- If the app crashes before you get there, check the size of the queue. Install the SQLite command-line tool (
winget install --id SQLite.SQLite --exact --source winget), keep the app closed, and run this read-only check in PowerShell:
It prints only a size in MiB, not your chats. If you setsqlite3 -readonly "$env:USERPROFILE\.codex\.codex-global-state.sqlite" "SELECT round(length(CAST(value AS BLOB))/1048576.0, 1) AS queue_MiB FROM settings WHERE scope='global' AND key='queued-follow-ups';"CODEX_HOME, use that folder instead of%USERPROFILE%\.codex. Users who had this error saw values from about 257 to 466 MiB. - Back up the file (app still closed), with a plain copy in PowerShell:
Copy-Item "$env:USERPROFILE\.codex\.codex-global-state.sqlite" "$env:USERPROFILE\.codex\global-state-backup.sqlite" - Empty the queue, following the users' own steps. Users who couldn't open the chat emptied the
queued-follow-upsentry in that file and the app came back. Their exact commands are in openai/codex #64073 and #63610; follow them only with the backup above in place. We haven't tested these commands, so we don't repeat them here. Emptying the queue throws away every unsent queued message, in all chats, including any text in them. Users report that chat history and project files stay. - Open the app and send a short text message to test it. Don't resend the same batch of images. Send fewer, smaller ones.
Why it happens
Users who read the app's logs found the same pattern. When you send images, the desktop app saves the message in a local queue first. A very large message (many full-size screenshots or photos) can grow past Electron's 512 MiB message limit (536,870,912 bytes). The app then logs:
Failed to execute queued message: RangeError: Message exceeds the 536870912-byte serialization limit.
Peer closed MessagePort connection
Because the message stays in the queue, the app tries it again on every launch and every send. That is why repair, reset, reinstall and restarting Windows don't help: the queue lives in your .codex folder, not in the app's install folder.
How to check it's this problem
- It started right after you attached, pasted or dropped images (or videos in Work).
- It now happens even on short text messages, and often in new chats too.
- The read-only check above prints a large number (hundreds of MiB).
If the queue is small, you may have a different bug with the same dialog. Some users got it on the second message of any chat with no images at all (#62901). For them, a second Windows user profile worked, and rolling back the app helped only for a while.
What didn't help in reports
- Windows Settings > Apps > Repair or Reset, reinstalling, or resetting the Microsoft Store.
- Restarting Windows.
- Updating to 26.1120.6357.0 (users still hit it there).
Running Claude Code, Codex or Cursor on real repos, or shipping an AI agent? A Quick Review ($149 / ₹13,900, 1 working day) checks one repo, config or setup for leaked keys, risky agent permissions and MCP servers. Request a Quick Review
FAQ
What causes 'Peer closed MessagePort connection' in Codex?
In user reports it follows an unsent message with many or large images. It stays in the desktop app's local queue and goes over Electron's 512 MiB message limit, so every send fails. OpenAI hasn't confirmed the cause.
Will clearing queued-follow-ups delete my chats?
No, according to the users who did it. It removes unsent queued messages only, including any text in them. Chat history and project files stay. Back up the file first anyway.
Why doesn't reinstalling fix it?
The stuck message is stored in .codex-global-state.sqlite in your .codex folder, which a reinstall or app reset doesn't remove.
Where is .codex-global-state.sqlite on Windows?
In %USERPROFILE%\.codex\ by default, or in the folder set by CODEX_HOME.
Is there an official fix?
Not as of 4 Dec 2026. No OpenAI reply on the GitHub issues. Users have asked for a size limit on attachments and a way to cancel a stuck queued message in the app.
Related errors
- Codex not working on Windows
- Codex: elastic section minimums must sum to 128000
- Codex CLI: Error loading config.toml
Sources
Read 4 Dec 2026. These tools change often: if a step no longer matches, the linked page wins.
- openai/codex #64073 (Windows, 18 images, recovery steps and confirmations): github.com/openai/codex/issues/64073
- openai/codex #63217 (read-only queue check; recovery by clearing attachments in the app): github.com/openai/codex/issues/63217#issuecomment-7128925968
- openai/codex #63610 (Windows queue recovery, 279 MiB pending message): github.com/openai/codex/issues/63610
- openai/codex #63104 (512 MiB serialization limit log lines, quick_check result): github.com/openai/codex/issues/63104
- openai/codex #64566 (RangeError log lines): github.com/openai/codex/issues/64566
- openai/codex #64707 (Windows, after sending messages): github.com/openai/codex/issues/64707
- openai/codex #62901 (second-message variant, no images): github.com/openai/codex/issues/62901
- reviewready CLI: one command that checks an AI app repo before it ships
- Exposed API key checker: find API keys committed to a repo or shipped to the browser
- MCP config checker: scan your mcp.json for hard-coded tokens, unpinned servers and risky access