Add forked_from_thread_id turn metadata (#24160)

## Why

When Codex calls responsesapi, we currently send `session_id`,
`thread_id`, and `turn_id` among other things as
`client_metadata["x-codex-turn-metadata"]`. This PR adds
`forked_from_thread_id` which helps explain the "lineage" of a forked
thread.

## What's changed

- Track the immediate history source copied into a forked thread through
thread/session creation, including subagent and review turn metadata
paths.
- Include `forked_from_thread_id` in Codex turn metadata while
preventing turn-scoped Responses API client metadata from overwriting
Codex-owned lineage fields.
- Add coverage for fork lineage in turn metadata and the app-server
Responses API request path.
This commit is contained in:
Owen Lin authored and GitHub committed 2026-05-26 14:05:28 -07:00
1 parent 5cd9b8086a
commit 1911021c0e
14 files changed
+404 -69

No files matched your search

@@ -482,6 +482,7 @@ impl Session {
let turn_metadata_state = Arc::new(TurnMetadataState::new(
session_id.to_string(),
thread_id.to_string(),
session_configuration.forked_from_thread_id,
session_configuration.thread_source,
sub_id.clone(),
cwd.clone(),