mirror of
https://github.com/openai/codex.git
synced 2026-12-03 00:41:03 +00:00
Clean up legacy Guardian thread metadata in SQLite (#47303)
## Why Guardian prompts are synthetic review context, but legacy thread metadata can duplicate them in titles, previews, and first messages. Keep SQLite metadata small while retaining rollout JSONL as the canonical record. ## What changed Add a migration for Guardian threads that: - Replaces blank or prompt-derived titles with `Guardian review`. - Preserves nonblank names and distinct nonblank titles, using the title as the name when no name exists. - Sets `preview` to `Approval review` and clears `first_user_message`. ## Testing Add a migration test covering prompt-derived and blank titles, custom titles and names, and unchanged metadata for a non-Guardian worker thread. GitOrigin-RevId: 65b5ff5200a39a19fb11f494de6dca7710ff6cc6
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
-- Guardian prompts are synthetic review context, not user-authored messages.
|
||||
-- Keep the SQLite projection small; rollout JSONL remains canonical.
|
||||
-- Legacy automatic titles were empty or copied first_user_message; preserve a
|
||||
-- different non-empty title because it may have been set explicitly.
|
||||
UPDATE threads
|
||||
SET title = CASE
|
||||
WHEN trim(title) = '' OR trim(title) = trim(first_user_message)
|
||||
THEN 'Guardian review'
|
||||
ELSE title
|
||||
END,
|
||||
name = CASE
|
||||
WHEN trim(COALESCE(name, '')) != ''
|
||||
THEN name
|
||||
WHEN trim(title) != ''
|
||||
AND trim(title) != trim(COALESCE(first_user_message, ''))
|
||||
THEN title
|
||||
ELSE 'Guardian review'
|
||||
END,
|
||||
preview = 'Approval review',
|
||||
first_user_message = ''
|
||||
WHERE source = '{"subagent":{"other":"guardian"}}';
|
||||
@@ -32,6 +32,123 @@ fn migrator_through(version: i64) -> Migrator {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn guardian_metadata_cleanup_preserves_custom_names_and_titles() {
|
||||
let sqlite_home = crate::runtime::test_support::unique_temp_dir();
|
||||
tokio::fs::create_dir_all(&sqlite_home)
|
||||
.await
|
||||
.expect("sqlite home should be created");
|
||||
let _cleanup = scopeguard::guard(sqlite_home.clone(), |sqlite_home| {
|
||||
let _ = std::fs::remove_dir_all(sqlite_home);
|
||||
});
|
||||
let sqlite = crate::SqliteConfig::new_for_testing(sqlite_home.as_path().abs());
|
||||
let pool = sqlite
|
||||
.open_read_write_pool(&sqlite.state_db_path())
|
||||
.await
|
||||
.expect("sqlite database should open");
|
||||
migrator_through(/*version*/ 56)
|
||||
.run(&pool)
|
||||
.await
|
||||
.expect("pre-cleanup migrations should apply");
|
||||
|
||||
sqlx::query(
|
||||
r#"
|
||||
INSERT INTO threads (
|
||||
id, rollout_path, created_at, updated_at, source, model_provider, cwd,
|
||||
title, name, preview, sandbox_policy, approval_mode, first_user_message
|
||||
) VALUES
|
||||
('derived', '/tmp/guardian.jsonl', 1700000000, 1700000100,
|
||||
'{"subagent":{"other":"guardian"}}', 'openai', '/tmp',
|
||||
' large guardian prompt ', NULL, 'large guardian prompt',
|
||||
'read-only', 'on-request', 'large guardian prompt'),
|
||||
('empty', '/tmp/empty-guardian.jsonl', 1700000000, 1700000100,
|
||||
'{"subagent":{"other":"guardian"}}', 'openai', '/tmp',
|
||||
' ', ' ', 'large guardian prompt',
|
||||
'read-only', 'on-request', 'large guardian prompt'),
|
||||
('worker', '/tmp/worker.jsonl', 1700000000, 1700000100,
|
||||
'{"subagent":{"other":"worker"}}', 'openai', '/tmp',
|
||||
'worker title', 'worker name', 'worker preview',
|
||||
'read-only', 'on-request', 'worker first message'),
|
||||
('custom-title', '/tmp/named-guardian.jsonl', 1700000000, 1700000100,
|
||||
'{"subagent":{"other":"guardian"}}', 'openai', '/tmp',
|
||||
'Named Guardian review', NULL, 'large guardian prompt',
|
||||
'read-only', 'on-request', 'large guardian prompt'),
|
||||
('custom-name', '/tmp/explicitly-named-guardian.jsonl', 1700000000, 1700000100,
|
||||
'{"subagent":{"other":"guardian"}}', 'openai', '/tmp',
|
||||
'large guardian prompt', 'Explicit Guardian name', 'large guardian prompt',
|
||||
'read-only', 'on-request', 'large guardian prompt')
|
||||
"#,
|
||||
)
|
||||
.execute(&pool)
|
||||
.await
|
||||
.expect("legacy metadata rows should insert");
|
||||
|
||||
STATE_MIGRATOR
|
||||
.run(&pool)
|
||||
.await
|
||||
.expect("guardian metadata cleanup should apply");
|
||||
|
||||
let rows =
|
||||
sqlx::query("SELECT id, title, name, preview, first_user_message FROM threads ORDER BY id")
|
||||
.fetch_all(&pool)
|
||||
.await
|
||||
.expect("cleaned metadata rows should load");
|
||||
let actual = rows
|
||||
.iter()
|
||||
.map(|row| {
|
||||
(
|
||||
row.get::<&str, _>("id"),
|
||||
row.get::<&str, _>("title"),
|
||||
row.get::<Option<&str>, _>("name"),
|
||||
row.get::<&str, _>("preview"),
|
||||
row.get::<&str, _>("first_user_message"),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(
|
||||
actual,
|
||||
vec![
|
||||
(
|
||||
"custom-name",
|
||||
"Guardian review",
|
||||
Some("Explicit Guardian name"),
|
||||
"Approval review",
|
||||
""
|
||||
),
|
||||
(
|
||||
"custom-title",
|
||||
"Named Guardian review",
|
||||
Some("Named Guardian review"),
|
||||
"Approval review",
|
||||
""
|
||||
),
|
||||
(
|
||||
"derived",
|
||||
"Guardian review",
|
||||
Some("Guardian review"),
|
||||
"Approval review",
|
||||
""
|
||||
),
|
||||
(
|
||||
"empty",
|
||||
"Guardian review",
|
||||
Some("Guardian review"),
|
||||
"Approval review",
|
||||
""
|
||||
),
|
||||
(
|
||||
"worker",
|
||||
"worker title",
|
||||
Some("worker name"),
|
||||
"worker preview",
|
||||
"worker first message"
|
||||
),
|
||||
]
|
||||
);
|
||||
|
||||
pool.close().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn thread_section_migration_preserves_legacy_pin_compatibility() {
|
||||
let sqlite_home = crate::runtime::test_support::unique_temp_dir();
|
||||
|
||||
Reference in New Issue
Block a user