Proposal: bump history_version when remove_first_item rewrites history
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 125k
- Forks
- 19.4k
- PR merge metrics
- PR metrics pending
Description
Summary
This is a proposal submitted as an issue because this repository restricts pull requests to collaborators.
ContextManager::remove_first_item() rewrites the history transcript (removes the oldest item and its call/output counterpart) but never bumps history_version, while the field is documented as "Bumped whenever history is rewritten, such as compaction or rollback". The fix keeps the "mutation bumps the version" invariant true for all mutation APIs.
Why it matters
history_version is a correctness signal: guardian/review_session.rs uses parent_history_version as a reuse key for review sessions. Today's only caller (compact.rs retry-trim) mutates a private clone_history() snapshot, so COW isolates the live history and the missing bump is currently harmless. But the pub(crate) API carries no such contract, and any future caller trimming the live history would silently invalidate review-session reuse.
Patch
One line, in codex-rs/core/src/context_manager/history.rs:
normalize::remove_corresponding_for(items, &removed.item);
self.world_state_baseline = None;
+ self.history_version = self.history_version.saturating_add(1);
Plus two unit tests (bump semantics + COW snapshot isolation) in history_tests.rs.
Verification
cargo test -p codex-core --lib remove_first_item # 6 passed (4 existing pairing + 2 new)
cargo test -p codex-core --lib context_manager::history::tests # 72 passed, 0 failed
Full change is pushed on fork branch: runzhong123-max:fix/history-version-bump-on-remove-first-item (commit 5272921, +88/−0, two files).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in codex-rs/core/src/context_manager/history.rs and read ContextManager::remove_first_item alongside the tests in history_tests.rs. Run the targeted codex-core tests to understand the existing pairing and snapshot-isolation behavior. Done means the history version changes for this mutation, snapshots remain isolated, and the listed tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 30/100