Skip to content

store and expose parent_thread_id on Threads#25113

Merged
owenlin0 merged 2 commits into
mainfrom
owen/improve_subagent_data_modeling
Jun 1, 2026
Merged

store and expose parent_thread_id on Threads#25113
owenlin0 merged 2 commits into
mainfrom
owen/improve_subagent_data_modeling

Conversation

@owenlin0
Copy link
Copy Markdown
Collaborator

@owenlin0 owenlin0 commented May 29, 2026

Why

This PR #24161 (comment) 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.

@owenlin0 owenlin0 changed the title Owen/improve subagent data modeling Model subagent parent lineage in source May 29, 2026
@owenlin0 owenlin0 changed the title Model subagent parent lineage in source Model subagent parent lineage separately from source May 29, 2026
@owenlin0 owenlin0 force-pushed the owen/improve_subagent_data_modeling branch from 79f0199 to 5019c4d Compare May 29, 2026 18:30
@owenlin0 owenlin0 changed the title Model subagent parent lineage separately from source expose a reliable parent_thread_id on Threads May 29, 2026
@owenlin0 owenlin0 force-pushed the owen/improve_subagent_data_modeling branch 4 times, most recently from 5e9ee64 to 21583d8 Compare May 29, 2026 22:19
@owenlin0 owenlin0 changed the title expose a reliable parent_thread_id on Threads store and expose parent_thread_id on Threads May 29, 2026
Copy link
Copy Markdown
Collaborator

@jif-oai jif-oai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm if you're sure it does not break anything in the app UX for multi-agent (I guess not but double check please)

})?;
if let Ok(meta_line) = read_session_meta_line(path.as_path()).await {
thread.forked_from_id = meta_line.meta.forked_from_id;
thread.parent_thread_id = meta_line.meta.parent_thread_id;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for the record: this is not backward compatible
But it's good for now

@owenlin0 owenlin0 force-pushed the owen/improve_subagent_data_modeling branch 2 times, most recently from bcad0d2 to 903dcac Compare June 1, 2026 03:20
@owenlin0 owenlin0 marked this pull request as ready for review June 1, 2026 03:55
@owenlin0 owenlin0 requested a review from a team as a code owner June 1, 2026 03:56
Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 768000f484

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@@ -1690,6 +1699,7 @@ fn thread_item_from_state_metadata(item: codex_state::ThreadMetadata) -> ThreadI
.or_else(|_| serde_json::from_value(Value::String(item.source)))
.unwrap_or(SessionSource::Unknown),
),
parent_thread_id: None,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve parent IDs when listing from SQLite

When SQLite is available, the normal unfiltered thread list path returns db_page.into(), which maps every codex_state::ThreadMetadata through this newly added field. Because state metadata is not extended to store parent_thread_id, this hard-coded None makes app-server thread/list report parentThreadId: null for subagent threads even though the rollout SessionMeta has the parent ID; this defeats the new API field for the common DB-backed listing path.

Useful? React with 👍 / 👎.

Comment thread codex-rs/protocol/src/protocol.rs
Comment thread codex-rs/core/src/agent/control.rs Outdated
Comment thread codex-rs/app-server-protocol/src/protocol/v2/thread_data.rs
@owenlin0 owenlin0 force-pushed the owen/improve_subagent_data_modeling branch from f42275f to b90f37f Compare June 1, 2026 04:14
@owenlin0 owenlin0 enabled auto-merge (squash) June 1, 2026 04:21
@owenlin0 owenlin0 merged commit cf09110 into main Jun 1, 2026
31 checks passed
@owenlin0 owenlin0 deleted the owen/improve_subagent_data_modeling branch June 1, 2026 04:33
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants