Add subagent lineage metadata for responsesapi#24161
Conversation
458564d to
9051b29
Compare
ad012a5 to
2a029fc
Compare
6872d84 to
fb9ad23
Compare
2682fb1 to
65f6b05
Compare
3e24bb9 to
ade82a4
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 48b7b4049d
ℹ️ 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".
| session_id: Some(session_id), | ||
| thread_id: Some(thread_id), | ||
| forked_from_thread_id, | ||
| parent_thread_id: session_source.parent_thread_id(), |
There was a problem hiding this comment.
Should this carry the known parent for non-thread-spawn subagents too?
There was a problem hiding this comment.
done! now it's populated for guardian and review subagents as well
| SubAgentSource::Compact => "compact", | ||
| SubAgentSource::ThreadSpawn { .. } => "thread_spawn", | ||
| SubAgentSource::MemoryConsolidation => "memory_consolidation", | ||
| SubAgentSource::Other(_) => "other", |
There was a problem hiding this comment.
Can we preserve the Other label here instead of serializing every custom subagent as other?
There was a problem hiding this comment.
good call, yes let's do that
| SessionSource::SubAgent(subagent_source) => Some(subagent_source.kind()), | ||
| let (parent_thread_id, subagent_kind) = match session_source { | ||
| SessionSource::SubAgent(subagent_source) => ( | ||
| subagent_source.parent_thread_id().or(forked_from_thread_id), |
There was a problem hiding this comment.
@jif-oai this was the fix so that we can properly set parent_id for guardian and review subagents. forked_from_thread_id happens to work but it's actually misleading, since in the case of guardian (and probably review? not as sure) we don't actually fork the parent thread's history.
I realized that this exposes a data modeling problem - we should be storing parent_thread_id directly on these subagent sources. I'll put up a followup PR to clean that up
There was a problem hiding this comment.
That makes sense for guardian/review as a short-term bridge
But what about agent_job? (that arguably we should refactor but it still represent a high volume for the security team)
That means they’ll now send subagent_kind="agent_job:$$$" but still no parent_thread_id
But I'm in to find an elegant solution that prevents tons of wiring
c49cdf7 to
0b3894c
Compare
| SessionSource::SubAgent(subagent_source) => Some(subagent_source.kind()), | ||
| let (parent_thread_id, subagent_kind) = match session_source { | ||
| SessionSource::SubAgent(subagent_source) => ( | ||
| subagent_source.parent_thread_id().or(forked_from_thread_id), |
There was a problem hiding this comment.
That makes sense for guardian/review as a short-term bridge
But what about agent_job? (that arguably we should refactor but it still represent a high volume for the security team)
That means they’ll now send subagent_kind="agent_job:$$$" but still no parent_thread_id
But I'm in to find an elegant solution that prevents tons of wiring
Why
We recently added
forked_from_thread_idwhich lets us trace where a thread's context comes from, but we also want to understand subagent lineage (e.g. which parent thread spawned this subagent? what kind of subagent is it?) which is orthogonal.This PR adds
parent_thread_idandsubagent_kindto thex-codex-turn-metadataheader sent to ResponsesAPI.What changed
parent_thread_idandsubagent_kindto core-ownedx-codex-turn-metadata.SessionSourceandThreadSourcefrom resumed session metadata so cold-resumed subagent threads keep their lineage on later Responses API requests.SessionSource/SubAgentSourceand reuses it in the Responses client, analytics, agent control, and state parsing paths.Verification
core/src/turn_metadata_tests.rsandapp-server/tests/suite/v2/client_metadata.rs.