Skip to content

Use copy-on-write storage for history snapshots - #34390

Merged
copyberry[bot] merged 1 commit into
mainfrom
copyberry/codex-internal-to-codex-oss/24605888209ae9ff78cadb04d9c36463f7e2dbe0
Jul 20, 2026
Merged

Use copy-on-write storage for history snapshots#34390
copyberry[bot] merged 1 commit into
mainfrom
copyberry/codex-internal-to-codex-oss/24605888209ae9ff78cadb04d9c36463f7e2dbe0

Conversation

@copyberry

@copyberry copyberry Bot commented Jul 20, 2026

Copy link
Copy Markdown

Use copy-on-write storage for history snapshots

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.

## 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
@copyberry
copyberry Bot force-pushed the copyberry/codex-internal-to-codex-oss/24605888209ae9ff78cadb04d9c36463f7e2dbe0 branch from ce47232 to 45ac251 Compare July 20, 2026 18:04
@copyberry
copyberry Bot merged commit 45ac251 into main Jul 20, 2026
18 of 32 checks passed
@copyberry
copyberry Bot deleted the copyberry/codex-internal-to-codex-oss/24605888209ae9ff78cadb04d9c36463f7e2dbe0 branch July 20, 2026 18:05
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants