store and expose parent_thread_id on Threads (#25113)

## Why

This PR
https://github.com/openai/codex/pull/24161#discussion_r3325692763
revealed a subagent data modeling issue, where we overloaded
`forked_from_id` to also mean `parent_thread_id`. That's incorrect since
guardian and review subagents can be a subagent and NOT fork the main
thread's history.

The solution here is to explicitly store a new `parent_thread_id` on
`SessionMeta`, alongside `forked_from_id` which already exists. While
we're at it, also expose it in the app-server protocol on the `Thread`
object.

A thread->subagent relationship and a fork of thread history are
orthogonal concepts.

## What Changed

- Added top-level `parent_thread_id` persistence on `SessionMeta` and
runtime/session plumbing through `SessionConfiguredEvent`,
`CodexSpawnArgs`, `SessionConfiguration`, `ThreadConfigSnapshot`,
`TurnContext`, and `ModelClient`.
- Made turn metadata, request headers, analytics, and subagent-start
events read the separate runtime/top-level parent field instead of
deriving general parent lineage from `SessionSource` or
`forked_from_thread_id`.
- Passed parent lineage separately at delegated subagent, review,
guardian, agent-job, and multi-agent spawn construction sites;
copied-history fork lineage remains derived only from `InitialHistory`.
- Persisted and exposed parent lineage through rollout/thread-store
projections and app-server v2 `Thread.parentThreadId`.
- Updated app-server README text and regenerated app-server schema
fixtures for the additive `parentThreadId` response field.
This commit is contained in:
Owen Lin
2026-06-01 04:33:20 +00:00
committed by GitHub
parent 3b7334d099
commit cf0911076f
92 changed files with 504 additions and 111 deletions
+12
View File
@@ -606,6 +606,7 @@ async fn test_list_conversations_latest_first() {
git_sha: None,
git_origin_url: None,
source: Some(SessionSource::VSCode),
parent_thread_id: None,
agent_nickname: None,
agent_role: None,
model_provider: Some(TEST_PROVIDER.to_string()),
@@ -623,6 +624,7 @@ async fn test_list_conversations_latest_first() {
git_sha: None,
git_origin_url: None,
source: Some(SessionSource::VSCode),
parent_thread_id: None,
agent_nickname: None,
agent_role: None,
model_provider: Some(TEST_PROVIDER.to_string()),
@@ -640,6 +642,7 @@ async fn test_list_conversations_latest_first() {
git_sha: None,
git_origin_url: None,
source: Some(SessionSource::VSCode),
parent_thread_id: None,
agent_nickname: None,
agent_role: None,
model_provider: Some(TEST_PROVIDER.to_string()),
@@ -750,6 +753,7 @@ async fn test_pagination_cursor() {
git_sha: None,
git_origin_url: None,
source: Some(SessionSource::VSCode),
parent_thread_id: None,
agent_nickname: None,
agent_role: None,
model_provider: Some(TEST_PROVIDER.to_string()),
@@ -767,6 +771,7 @@ async fn test_pagination_cursor() {
git_sha: None,
git_origin_url: None,
source: Some(SessionSource::VSCode),
parent_thread_id: None,
agent_nickname: None,
agent_role: None,
model_provider: Some(TEST_PROVIDER.to_string()),
@@ -820,6 +825,7 @@ async fn test_pagination_cursor() {
git_sha: None,
git_origin_url: None,
source: Some(SessionSource::VSCode),
parent_thread_id: None,
agent_nickname: None,
agent_role: None,
model_provider: Some(TEST_PROVIDER.to_string()),
@@ -837,6 +843,7 @@ async fn test_pagination_cursor() {
git_sha: None,
git_origin_url: None,
source: Some(SessionSource::VSCode),
parent_thread_id: None,
agent_nickname: None,
agent_role: None,
model_provider: Some(TEST_PROVIDER.to_string()),
@@ -882,6 +889,7 @@ async fn test_pagination_cursor() {
git_sha: None,
git_origin_url: None,
source: Some(SessionSource::VSCode),
parent_thread_id: None,
agent_nickname: None,
agent_role: None,
model_provider: Some(TEST_PROVIDER.to_string()),
@@ -1052,6 +1060,7 @@ async fn test_get_thread_contents() {
git_sha: None,
git_origin_url: None,
source: Some(SessionSource::VSCode),
parent_thread_id: None,
agent_nickname: None,
agent_role: None,
model_provider: Some(TEST_PROVIDER.to_string()),
@@ -1251,6 +1260,7 @@ async fn test_updated_at_uses_file_mtime() -> Result<()> {
meta: SessionMeta {
id: conversation_id,
forked_from_id: None,
parent_thread_id: None,
timestamp: ts.to_string(),
cwd: ".".into(),
originator: "test_originator".into(),
@@ -1403,6 +1413,7 @@ async fn test_timestamp_only_cursor_skips_same_second_filesystem_ties() {
git_sha: None,
git_origin_url: None,
source: Some(SessionSource::VSCode),
parent_thread_id: None,
agent_nickname: None,
agent_role: None,
model_provider: Some(TEST_PROVIDER.to_string()),
@@ -1420,6 +1431,7 @@ async fn test_timestamp_only_cursor_skips_same_second_filesystem_ties() {
git_sha: None,
git_origin_url: None,
source: Some(SessionSource::VSCode),
parent_thread_id: None,
agent_nickname: None,
agent_role: None,
model_provider: Some(TEST_PROVIDER.to_string()),