Remote compaction v2 retains raw media and can trigger repeated auto-compaction
Summary
In a long-running Codex Desktop session with image inputs, repeated remote compaction retained raw media payloads in replacement history. The session then kept auto-compacting and the rollout grew continuously.
Observed behavior
- A successful compaction did not remove earlier inline image payloads from the retained history.
- Subsequent compaction requests carried those payloads forward again.
- The retained payload volume created a high context floor and repeated automatic compaction.
Root-cause hypothesis
The v2 retained-history path in codex-rs/core/src/compact_remote_v2.rs assigns zero text-token cost to InputImage and InputAudio, while preserving the raw items during truncation. Therefore a byte-heavy media item can survive the text-only budget indefinitely across compactions.
Expected behavior
After successful compaction, retained history must not contain raw image or audio payloads from previous turns, and all retained context should remain bounded by the retention budget.
Proposed fix
Before retained-history budget truncation, replace InputImage and InputAudio with bounded text markers. This preserves conversation structure without resending or persisting raw media. Add regression coverage that asserts compacted retained history contains no data:image or audio payload and that markers are charged by the existing budget.
Related discussion
This is a current reproduction and source-level analysis related to #33493.
4 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
Sanitized reproduction data
The following is a structural-only scan of one affected local rollout. No transcript text, prompts, file paths, screenshots, tool output, account identifiers, or raw media is included.
Environment and capture window
| Field | Value |
| --- | --- |
| Client version recorded at session start |
0.144.6|| History mode |
legacy|| Session start | 2026-07-25 08:28:28 UTC |
| Last recorded event at scan time | 2026-08-16 04:13:14 UTC |
| Writer state | rollout file was still open by the running Codex process |
Measured rollout shape
| Metric | Value |
| --- | ---: |
| Rollout size | 10,057,075,750 bytes, 9.4 GiB as reported by
du|| JSONL records | 64,983 |
|
context_compactedrecords | 494 || Literal
input_imageoccurrences | 30,202 |Compaction concentration
The event timestamps show a pronounced late-session acceleration. Counts below are UTC and are structural event counts only.
| Date |
context_compactedrecords || --- | ---: |
| 2026-08-13 | 19 |
| 2026-08-14 | 32 |
| 2026-08-15 | 269 |
| 2026-08-16 through 04:13 UTC | 35 |
The 269 compactions on 2026-08-15 correspond to an average interval of about 5.4 minutes across that UTC day. The problem persisted after compactions rather than resolving the history pressure.
Source-level correlation
In
codex-rs/core/src/compact_remote_v2.rs:message_text_token_countassigns zero text-token cost toInputImageandInputAudio.truncate_message_text_to_token_budgetpreserves those media items unchanged.This makes a media-heavy retained history effectively unbounded with respect to the text-only retention budget, matching the measured growth and recurring compaction pattern.
Acceptance criteria for a fix
data:imageor audio payload in retained replacement history.Additional Windows reproduction on a current Desktop build
Corroborating this on Windows 11 x64 with Codex Desktop
26.810.7004.0, embedded CLI0.148.0-alpha.9,gpt-5.6-sol,and
remote_compaction_v2enabled during the incident.A structural-only scan of one image-heavy thread showed:
input_image/data:imageoccurrences acrossreplacement histories; these were not unique images;
200 OK, but token usage remained abovethe automatic-compaction threshold, causing another compaction roughly every
2–3 minutes.
This distinction may be useful: the failure was not only a transport error.
Compaction succeeded at the HTTP layer but did not re-establish enough context
headroom to converge, leaving the Desktop session unusable.
No transcript text, prompts, paths, task or thread identifiers, screenshots,
raw logs, media, account information, or repository content is included.
Your retained-media/compaction case is a strong stress test for
codex-rescuebecause the failure is persisted in session history rather than being only a transient UI symptom. I’m field-testing the tool on real broken/oversized Codex sessions. It is experimental, local-first, and keeps the source rollout read-only; it does not claim to fix remote compaction itself.Could you run the narrow diagnostic path on an affected local session?
For a multi-GB/image-heavy rollout, please stop there first rather than immediately salvaging it. I’m interested in whether discovery/diagnosis stays bounded and reports the state without mutating the original file.
Sanitized output + versions/exit codes would be useful; please don’t post raw JSONL/SQLite, image payloads, prompts, credentials, or private paths. Repo: https://github.com/shleder/codex-rescue