mirror of
https://github.com/openai/codex.git
synced 2026-11-04 00:24:43 +00:00
## Why Cloning a `ContextManager` deep-copies every `ResponseItem`, even when callers only need a read-only history snapshot. ## What changed - Store history items in an `Arc<Vec<ResponseItem>>` so cloned snapshots share their items until one is mutated. - Reuse an owned vector when consuming an unshared snapshot and clone it only when other snapshots still reference it. - Estimate session token counts from a snapshot after releasing the session-state lock. ## Testing Added a regression test that verifies cloned histories share their backing items before mutation and diverge without affecting each other afterward. GitOrigin-RevId: 24605888209ae9ff78cadb04d9c36463f7e2dbe0