[Bug] Archive deletes session data + Auto-compact fires post-sampling causing inflated token costs

Open 💬 0 comments Opened Jun 11, 2026 by sky-domon

Bug 1: Archiving deletes session data permanently (no recovery path)

When clicking "Archive" on a conversation in Codex Desktop, the session data is completely deleted. The only remaining trace is an orphaned entry in session_index.jsonl. There is no way to recover via UI or filesystem.

Steps to reproduce:

  1. Click Archive on any conversation in the sidebar
  2. The conversation disappears from the list
  3. Check archived_sessions/ — no matching file
  4. Check state_5.sqlite, table threads — no matching record
  5. session_index.jsonl still has the orphaned index entry, but the data is gone

Affected thread: 019eafea-46bf-79d3-9c0a-426a46daf255 (title: "nev-kb审计--独立")

  • Present in session_index.jsonl but absent from state_5.sqlite and no JSONL file on disk

---

Bug 2: Auto-compact runs after API call (post-sampling) instead of before, causing inflated token consumption in tool-calling loops

When Codex enters a tool-calling loop (e.g., run test -> read output -> analyze -> run again), the auto_compact mechanism only fires after the API response is received ("post sampling"), not before the API request is sent. This means an oversized context (including image tokens ~85K-170K each + large tool results) is sent to the model API and billed, before being compacted down to normal size.

Steps to reproduce:

  1. Send an image for Codex to analyze
  2. Codex enters a tool-calling loop (e.g., run tests, read results, analyze, repeat)
  3. Observe token consumption: every other API call has total_usage_tokens reaching ~440K (nearly 2x the auto_compact_scope_limit of 244,800)
  4. Compaction only fires after the API call — the oversized context has already been billed

Token usage data (9 sequential calls, same session):

| Turn | total_usage_tokens | estimated_tokens | Over limit? |
|------|-------------------|------------------|-------------|
| 1 | 17,969 | 13,392 | No |
| 2 | 21,829 | 17,321 | No |
| 3 | 440,907 | 17,944 | Yes |
| 4 | 21,787 | 17,241 | No |
| 5 | 440,848 | 17,857 | Yes |
| 6 | 22,041 | 17,518 | No |
| 7 | 441,566 | 18,640 | Yes |
| 8 | 21,704 | 17,214 | No |
| 9 | 441,310 | 18,395 | Yes |

auto_compact_scope_limit = 244,800. Turns 3,5,7,9 exceeded the limit by ~1.8x.

Environment:

  • Codex Desktop: 0.137.0-alpha.4
  • Connection: VS Code extension / Codex Desktop
  • Model: deepseek-v4-pro (custom API Key)
  • OS: Windows 11
  • Evidence: Attached codex_019eafea_logs.json (487 log entries with full token records for all API calls)

codex_019eafea_logs.json

View original on GitHub ↗