Skip to content

ensure thread.history_mode is immutable#30261

Merged
owenlin0 merged 5 commits into
mainfrom
owen/immutable_history_mode
Jun 26, 2026
Merged

ensure thread.history_mode is immutable#30261
owenlin0 merged 5 commits into
mainfrom
owen/immutable_history_mode

Conversation

@owenlin0

@owenlin0 owenlin0 commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR makes thread.history_mode immutable after the thread's canonical first SessionMeta has been written. Later same-thread SessionMeta lines are compatibility metadata writes, not a new thread definition.

Without this, an older binary could append a SessionMeta that omits history_mode; when a newer binary replays it, serde defaults that missing field to legacy and SQLite could downgrade a paginated thread.

Why

history_mode is the persisted thread storage contract. Paginated-thread fail-closed behavior and SQLite memory filtering depend on it staying aligned with canonical rollout metadata, especially when multiple Codex binary versions can touch the same local rollout.

What changed

  • Stop generic rollout metadata replay from overwriting history_mode from later SessionMeta items.
  • Remove history_mode from ThreadMetadataPatch, so mutable metadata sync and app-server metadata updates cannot rewrite it.
  • When local metadata sync has to recreate a missing SQLite row, recover history_mode from the rollout's canonical first SessionMeta instead of from a mutable patch.
  • Keep the in-memory thread store using the created thread's canonical history_mode instead of metadata patches.
  • Fill the one remaining core test CreateThreadParams initializer with the new history_mode field; Bazel CI caught this after the parent history-mode PR landed.

Validation

  • just fmt
  • just test -p codex-thread-store
  • just test -p codex-state session_meta_does_not_set_model_or_reasoning_effort

@owenlin0 owenlin0 marked this pull request as ready for review June 26, 2026 16:23
@owenlin0 owenlin0 requested a review from wiltzius-openai June 26, 2026 16:24
@owenlin0 owenlin0 requested a review from a team as a code owner June 26, 2026 16:39
self.observe_items_with_update(items, ThreadMetadataPatch::default())
let mut update = self.observe_items_with_update(items, ThreadMetadataPatch::default())?;
// Later SessionMeta lines do not redefine the canonical history_mode.
update.history_mode = Some(canonical_history_mode_from_rollout_items(items));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems possibly slightly inefficient to re-scan the items to rederive the old history mode, vs just omitting history mode from the ThreadMetadataPatch? But minor

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, much cleaner to omit it from ThreadMetadataPatch entirely. updated

@wiltzius-openai wiltzius-openai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this avoid the metadata sync rewriting the value; do we also need to forbid it in the app server APIs that can mutate metadata (or was it never exposed)?

@owenlin0

owenlin0 commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator Author

do we also need to forbid it in the app server APIs that can mutate metadata (or was it never exposed)?

yeah, we only allow history_mode to be settable from thread/start

@owenlin0 owenlin0 merged commit 812cd2b into main Jun 26, 2026
31 checks passed
@owenlin0 owenlin0 deleted the owen/immutable_history_mode branch June 26, 2026 19:32
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 26, 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.

3 participants