mirror of
https://github.com/openai/codex.git
synced 2026-11-24 15:21:20 +00:00
Copy current thread attachments into non-ephemeral forks (#45579)
## What changed Copy the source thread's current attachments when creating a non-ephemeral fork, including forks at an earlier turn. Copies receive new attachment IDs and creation timestamps while preserving resource identities and payloads. Attachment membership can then change independently on either thread; referenced resources are not copied. Await the atomic copy before publishing the fork. If copying fails, log the error and allow the conversation fork to succeed without attachments. Resuming a fork does not copy attachments again. Document that clients should use `forkedFromId` on `thread/started` and fetch the fork's attachments with `thread/attachment/list`; copying does not emit per-attachment updates. ## Testing Add coverage for atomic rollback, independent attachment membership, inheritance across history cutoffs, successful conversation forks after copy failures, and resuming without restoring removed attachments. GitOrigin-RevId: 939d2c6a3073ccfcd922380c6beda45d3deac606
This commit is contained in:
1 parent
4e6450bbfd
commit
19286b8819
10 files changed
+339
-15
No files matched your search
@@ -40,6 +40,72 @@ async fn runtime_with_threads(count: usize) -> Result<(Arc<StateRuntime>, PathBu
|
||||
Ok((runtime, codex_home, thread_ids))
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn copying_attachments_is_atomic_and_independent() -> Result<()> {
|
||||
let (runtime, _codex_home, thread_ids) = runtime_with_threads(/*count*/ 2).await?;
|
||||
let source = thread_ids[0];
|
||||
let destination = thread_ids[1];
|
||||
for key in ["first", "second"] {
|
||||
runtime
|
||||
.add_thread_attachment(source, "document", key, &json!({"path": key}))
|
||||
.await?;
|
||||
}
|
||||
sqlx::query(
|
||||
"CREATE TRIGGER fail_attachment_copy BEFORE INSERT ON thread_attachments WHEN NEW.identity_key = 'second' BEGIN SELECT RAISE(FAIL, 'copy failure'); END",
|
||||
)
|
||||
.execute(runtime.pool.as_ref())
|
||||
.await?;
|
||||
let error = runtime
|
||||
.copy_thread_attachments(source, destination)
|
||||
.await
|
||||
.expect_err("a failed insert must roll back the entire copy");
|
||||
assert!(error.to_string().contains("copy failure"));
|
||||
assert!(
|
||||
runtime
|
||||
.list_thread_attachments(destination, /*cursor*/ None, /*limit*/ 10)
|
||||
.await?
|
||||
.attachments
|
||||
.is_empty()
|
||||
);
|
||||
sqlx::query("DROP TRIGGER fail_attachment_copy")
|
||||
.execute(runtime.pool.as_ref())
|
||||
.await?;
|
||||
runtime.copy_thread_attachments(source, destination).await?;
|
||||
let originals = runtime
|
||||
.list_thread_attachments(source, /*cursor*/ None, /*limit*/ 10)
|
||||
.await?
|
||||
.attachments;
|
||||
let copied = runtime
|
||||
.list_thread_attachments(destination, /*cursor*/ None, /*limit*/ 10)
|
||||
.await?
|
||||
.attachments;
|
||||
assert_eq!(copied.len(), originals.len());
|
||||
for (original, copy) in originals.iter().zip(&copied) {
|
||||
assert_ne!(copy.id, original.id);
|
||||
assert_eq!(
|
||||
copy,
|
||||
&crate::ThreadAttachment {
|
||||
id: copy.id.clone(),
|
||||
thread_id: destination,
|
||||
created_at: copy.created_at,
|
||||
..original.clone()
|
||||
}
|
||||
);
|
||||
}
|
||||
runtime
|
||||
.remove_thread_attachment(source, "document", "first")
|
||||
.await?;
|
||||
runtime.delete_thread(source).await?;
|
||||
assert_eq!(
|
||||
runtime
|
||||
.list_thread_attachments(destination, /*cursor*/ None, /*limit*/ 10)
|
||||
.await?
|
||||
.attachments,
|
||||
copied
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn attachment_attachments_are_idempotent_and_scoped_to_their_thread() -> Result<()> {
|
||||
let (runtime, _codex_home, thread_ids) = runtime_with_threads(/*count*/ 2).await?;
|
||||
|
||||
Reference in new issue
Block a user