Persist thread creator identity in rollouts and SQLite (#47113)

## What changed

- Capture optional `creator_user_id` and `creator_account_id` from authentication when creating a thread, including forks.
- Carry these fields through thread storage, rollout metadata, and a SQLite migration. Leave them absent when unavailable or when reading older threads.
- Preserve recorded creator values across resume and metadata updates. On revert, recover missing rollout values from SQLite before writing replacement metadata.

## Testing

Add coverage for ChatGPT and API-key sessions, resume under another account, forks using current authentication, metadata extraction and upserts, and repeated reverts after creator fields are removed from a rollout.

GitOrigin-RevId: 9839fa42f9392f12226002e2c27d05d5656f5695
This commit is contained in:
Jeremy Rose
2026-09-21 21:22:01 +00:00
committed by copyberry
parent bf91058b81
commit 23ae65bb06
37 changed files with 430 additions and 7 deletions
@@ -94,6 +94,13 @@ async fn revert_keeps_thread_id_and_hides_suffix_across_repeated_reverts() {
.expect("read replacement metadata")
.meta;
assert_eq!(replacement_meta.id, thread_id);
assert_eq!(
(
replacement_meta.creator_user_id.as_deref(),
replacement_meta.creator_account_id.as_deref()
),
(Some("creator-user"), Some("creator-account")),
);
assert_eq!(replacement_meta.memory_mode, None);
assert_eq!(
replacement_meta.runtime_workspace_roots,
@@ -101,6 +108,24 @@ async fn revert_keeps_thread_id_and_hides_suffix_across_repeated_reverts() {
);
assert_eq!(turn_ids(&store, thread_id).await, vec!["turn-1"]);
// Simulate an older binary replacing the rollout without the creator fields it does not know.
let rollout = tokio::fs::read_to_string(&first_replacement_path)
.await
.expect("read replacement rollout");
let (meta_line, remaining_lines) = rollout.split_once('\n').expect("session metadata line");
let mut meta_line: serde_json::Value = serde_json::from_str(meta_line).expect("parse metadata");
let payload = meta_line["payload"]
.as_object_mut()
.expect("metadata payload");
payload.remove("creator_user_id");
payload.remove("creator_account_id");
tokio::fs::write(
&first_replacement_path,
format!("{meta_line}\n{remaining_lines}"),
)
.await
.expect("write legacy replacement rollout");
store
.revert_thread(RevertThreadParams {
thread_id,
@@ -110,6 +135,22 @@ async fn revert_keeps_thread_id_and_hides_suffix_across_repeated_reverts() {
.await
.expect("revert before first turn");
assert_eq!(turn_ids(&store, thread_id).await, Vec::<String>::new());
let stored = state_db
.get_thread(thread_id)
.await
.expect("read metadata")
.expect("thread metadata");
let recovered = codex_rollout::read_session_meta_line(&stored.rollout_path)
.await
.expect("read recovered creator metadata")
.meta;
assert_eq!(
(recovered.creator_user_id, recovered.creator_account_id),
(
Some("creator-user".to_string()),
Some("creator-account".to_string())
),
);
store
.archive_thread(ArchiveThreadParams { thread_id })
@@ -231,6 +272,8 @@ async fn rollout_paths_for_thread(
async fn create_paginated_thread(store: &LocalThreadStore, thread_id: ThreadId) {
store
.create_thread(CreateThreadParams {
creator_user_id: Some("creator-user".to_string()),
creator_account_id: Some("creator-account".to_string()),
session_id: thread_id.into(),
thread_id,
extra_config: None,