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
+31 -2
View File
@@ -17,6 +17,8 @@ SELECT
threads.recency_at_ms AS recency_at,
threads.source,
threads.originator,
threads.creator_user_id,
threads.creator_account_id,
threads.history_mode,
threads.thread_source,
threads.agent_nickname,
@@ -621,6 +623,8 @@ INSERT INTO threads (
recency_at_ms,
source,
originator,
creator_user_id,
creator_account_id,
history_mode,
thread_source,
agent_nickname,
@@ -649,7 +653,7 @@ INSERT INTO threads (
memory_mode,
project_id,
daybreak_enabled
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(id) DO NOTHING
"#,
)
@@ -663,6 +667,8 @@ ON CONFLICT(id) DO NOTHING
.bind(datetime_to_epoch_millis(recency_at))
.bind(metadata.source.as_str())
.bind(metadata.originator.as_deref())
.bind(metadata.creator_user_id.as_deref())
.bind(metadata.creator_account_id.as_deref())
.bind(metadata.history_mode.as_str())
.bind(
metadata
@@ -917,6 +923,8 @@ INSERT INTO threads (
recency_at_ms,
source,
originator,
creator_user_id,
creator_account_id,
history_mode,
thread_source,
agent_nickname,
@@ -945,7 +953,7 @@ INSERT INTO threads (
memory_mode,
project_id,
daybreak_enabled
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(id) DO UPDATE SET
rollout_path = excluded.rollout_path,
created_at = excluded.created_at,
@@ -956,6 +964,8 @@ ON CONFLICT(id) DO UPDATE SET
recency_at_ms = threads.recency_at_ms,
source = excluded.source,
originator = COALESCE(threads.originator, excluded.originator),
creator_user_id = COALESCE(threads.creator_user_id, excluded.creator_user_id),
creator_account_id = COALESCE(threads.creator_account_id, excluded.creator_account_id),
-- Paginated history is a one-way promotion; stale legacy metadata must not downgrade it.
history_mode = CASE
WHEN threads.history_mode = 'paginated' THEN threads.history_mode
@@ -993,6 +1003,8 @@ ON CONFLICT(id) DO UPDATE SET
.bind(datetime_to_epoch_millis(insert_recency_at))
.bind(metadata.source.as_str())
.bind(metadata.originator.as_deref())
.bind(metadata.creator_user_id.as_deref())
.bind(metadata.creator_account_id.as_deref())
.bind(metadata.history_mode.as_str())
.bind(
metadata
@@ -1300,6 +1312,8 @@ SELECT
threads.recency_at_ms AS recency_at,
threads.source,
threads.originator,
threads.creator_user_id,
threads.creator_account_id,
threads.history_mode,
threads.thread_source,
threads.agent_nickname,
@@ -2595,6 +2609,8 @@ mod tests {
);
let items = vec![RolloutItem::SessionMeta(SessionMetaLine {
meta: SessionMeta {
creator_user_id: None,
creator_account_id: None,
session_id: thread_id.into(),
id: thread_id,
forked_from_id: None,
@@ -2667,6 +2683,8 @@ mod tests {
);
let items = vec![RolloutItem::SessionMeta(SessionMetaLine {
meta: SessionMeta {
creator_user_id: None,
creator_account_id: None,
session_id: thread_id.into(),
id: thread_id,
forked_from_id: None,
@@ -2750,6 +2768,8 @@ mod tests {
let mut rollout_metadata = metadata.clone();
rollout_metadata.originator = Some("recorded_client".to_string());
rollout_metadata.creator_user_id = Some("creator-user".to_string());
rollout_metadata.creator_account_id = Some("creator-account".to_string());
rollout_metadata.git_sha = Some("rollout-sha".to_string());
rollout_metadata.git_branch = Some("rollout-branch".to_string());
rollout_metadata.git_origin_url = Some(
@@ -2777,6 +2797,8 @@ mod tests {
for incoming_originator in [None, Some("resume_client")] {
rollout_metadata.originator = incoming_originator.map(str::to_owned);
rollout_metadata.creator_user_id = incoming_originator.map(str::to_owned);
rollout_metadata.creator_account_id = incoming_originator.map(str::to_owned);
runtime
.upsert_thread(&rollout_metadata)
.await
@@ -2787,6 +2809,13 @@ mod tests {
.expect("thread should load")
.expect("thread should exist");
assert_eq!(persisted.originator.as_deref(), Some("recorded_client"));
assert_eq!(
(
persisted.creator_user_id.as_deref(),
persisted.creator_account_id.as_deref()
),
(Some("creator-user"), Some("creator-account")),
);
}
}