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
+5
View File
@@ -306,6 +306,8 @@ pub struct StartThreadOptions {
pub history_mode: Option<ThreadHistoryMode>,
pub session_source: Option<SessionSource>,
pub thread_source: Option<ThreadSource>,
/// Creation metadata forwarded to storage; never inherited from a fork source.
pub attached_thread: bool,
pub dynamic_tools: Vec<codex_protocol::dynamic_tools::DynamicToolSpec>,
pub metrics_service_name: Option<String>,
pub parent_trace: Option<W3cTraceContext>,
@@ -337,6 +339,7 @@ impl StartThreadOptions {
history_mode: None,
session_source: None,
thread_source: None,
attached_thread: false,
dynamic_tools: Vec::new(),
metrics_service_name: None,
parent_trace: None,
@@ -2175,6 +2178,7 @@ impl ThreadManagerState {
history_mode,
session_source,
thread_source,
attached_thread,
dynamic_tools,
metrics_service_name,
parent_trace,
@@ -2397,6 +2401,7 @@ impl ThreadManagerState {
let attachment_source =
forked_from_thread_id.filter(|_| matches!(&initial_history, InitialHistory::Forked(_)));
let spawn_result = Session::spawn(SessionSpawnArgs {
attached_thread,
startup,
config,
prompt_cache_key,