[Bug] Archive deletes session data + Auto-compact fires post-sampling causing inflated token costs
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:
- Click Archive on any conversation in the sidebar
- The conversation disappears from the list
- Check
archived_sessions/— no matching file - Check
state_5.sqlite, tablethreads— no matching record session_index.jsonlstill has the orphaned index entry, but the data is gone
Affected thread: 019eafea-46bf-79d3-9c0a-426a46daf255 (title: "nev-kb审计--独立")
- Present in
session_index.jsonlbut absent fromstate_5.sqliteand 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:
- Send an image for Codex to analyze
- Codex enters a tool-calling loop (e.g., run tests, read results, analyze, repeat)
- Observe token consumption: every other API call has
total_usage_tokensreaching ~440K (nearly 2x theauto_compact_scope_limitof 244,800) - 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)