Add experimental attached thread forks (#56351)

## What changed

- Add `attachToSource` to `thread/fork` to persist a fork attached to its source without emitting `thread/started`. Attached forks require local storage and cannot use `ephemeral` or `deferGoalContinuation`.
- Hide attached threads from ordinary listings and add `attachedToThreadId` to `thread/list` for explicit discovery, including empty threads. Keep this relationship separate from spawned-agent parent and ancestor filters.
- Persist attachment metadata in rollouts and SQLite so it survives restarts and database recovery. Reject source deletion until its attached threads are deleted.

## Testing

Add coverage for legacy and paginated history, restart and missing or corrupt database recovery, filtered listings and pagination, resume, conflicting options, and deletion safeguards across store instances.

GitOrigin-RevId: 589f3174fc36f6054e75d65818360695645a5913
This commit is contained in:
Brent Traut
2026-10-23 04:52:47 +00:00
committed by copyberry
parent 4610b573e5
commit 30587d7885
70 changed files with 1078 additions and 68 deletions
+3
View File
@@ -485,6 +485,7 @@ impl From<CompactedHistoryMetadata> for CompactedHistoryInstallation<'_> {
}
pub(crate) struct SessionSpawnArgs {
pub(crate) attached_thread: bool,
pub(crate) startup: Option<Arc<startup::SessionStartup>>,
pub(crate) config: Config,
pub(crate) prompt_cache_key: PromptCacheKey,
@@ -605,6 +606,7 @@ impl Session {
.ensure_config_server_applied()?;
args.config.validate_windows_mxc_requirement()?;
let SessionSpawnArgs {
attached_thread,
startup,
config,
prompt_cache_key,
@@ -972,6 +974,7 @@ impl Session {
let session = Box::pin(Session::new(
startup.clone(),
session_configuration,
attached_thread,
prompt_cache_key,
&environment_selections,
config.clone(),
+2
View File
@@ -812,6 +812,7 @@ impl Session {
pub(crate) async fn new(
startup: Option<Arc<super::startup::SessionStartup>>,
mut session_configuration: SessionConfiguration,
attached_thread: bool,
prompt_cache_key: PromptCacheKey,
environment_selections: &[TurnEnvironmentSelection],
config: Arc<Config>,
@@ -1087,6 +1088,7 @@ impl Session {
InitialHistory::New | InitialHistory::Cleared | InitialHistory::Forked(_) => {
let auth = persistence_auth.await;
let params = CreateThreadParams {
attached_thread,
creator_user_id: auth.as_ref().and_then(CodexAuth::get_chatgpt_user_id),
creator_account_id: auth.as_ref().and_then(CodexAuth::get_account_id),
session_id,
+6
View File
@@ -4933,6 +4933,7 @@ async fn open_thread_persistence(session: &mut Session) -> PathBuf {
let live_thread = LiveThread::create(
Arc::clone(&session.services.thread_store),
CreateThreadParams {
attached_thread: false,
creator_user_id: None,
creator_account_id: None,
session_id: session.session_id(),
@@ -7186,6 +7187,7 @@ async fn make_session_with_config_and_rx(
let session = Session::new(
/*startup*/ None,
session_configuration,
/*attached_thread*/ false,
PromptCacheKey::default(),
&default_environments,
Arc::clone(&config),
@@ -7323,6 +7325,7 @@ async fn make_session_with_history_source_and_agent_control_and_rx(
let session = Session::new(
/*startup*/ None,
session_configuration,
/*attached_thread*/ false,
PromptCacheKey::default(),
&default_environments,
Arc::clone(&config),
@@ -8682,6 +8685,7 @@ async fn shutdown_complete_does_not_append_to_thread_store_after_shutdown() {
let live_thread = LiveThread::create(
Arc::clone(&thread_store),
CreateThreadParams {
attached_thread: false,
creator_user_id: None,
creator_account_id: None,
session_id: session.session_id(),
@@ -8802,6 +8806,7 @@ async fn submission_loop_channel_close_runs_full_thread_teardown() {
let live_thread = LiveThread::create(
Arc::clone(&thread_store),
CreateThreadParams {
attached_thread: false,
creator_user_id: None,
creator_account_id: None,
session_id: session.session_id(),
@@ -11736,6 +11741,7 @@ async fn attach_in_memory_thread_store(
let live_thread = LiveThread::create(
Arc::clone(&thread_store),
CreateThreadParams {
attached_thread: false,
creator_user_id: None,
creator_account_id: None,
session_id: session.session_id(),
@@ -1293,6 +1293,7 @@ async fn guardian_subagent_does_not_inherit_parent_exec_policy_rules() {
let mut thread_extension_init = codex_extension_api::ExtensionDataInit::default();
thread_extension_init.insert(codex_extension_api::SessionIsolation::Isolated);
let (session, io) = Session::spawn(SessionSpawnArgs {
attached_thread: false,
startup: None,
config,
prompt_cache_key: PromptCacheKey::default(),