Skip to content

Support new sub_agent_activity events when resolving subagent traces #41

Description

@yunhungo

Summary

Subagent turns can be omitted from exported Langfuse traces when Codex rollouts use the newer sub_agent_activity lifecycle event.

The current parser only extracts child thread IDs from:

{
  "type": "collab_agent_spawn_end",
  "new_thread_id": "thread-child"
}

Newer rollouts may represent the same lifecycle transition as:

{
  "type": "sub_agent_activity",
  "kind": "started",
  "agent_thread_id": "thread-child"
}

Because plugins/tracing/src/parse.ts does not recognize the latter shape, turn.subagentThreadIds remains empty and the existing child rollout is not nested as a Codex Subagent Turn.

Expected behavior

Support both formats and deduplicate child thread IDs:

if (et === "collab_agent_spawn_end" && typeof p.new_thread_id === "string") {
  turn.subagentThreadIds.push(p.new_thread_id);
}

if (
  et === "sub_agent_activity" &&
  p.kind === "started" &&
  typeof p.agent_thread_id === "string"
) {
  turn.subagentThreadIds.push(p.agent_thread_id);
}

Suggested test coverage

Add a rollout fixture using sub_agent_activity/agent_thread_id and assert that:

  • the child thread ID is captured exactly once;
  • its rollout is resolved;
  • Codex Subagent Turn is nested under the parent turn;
  • the child generations are emitted as LLM Subagent.

This differs from #12: the parent turn export can succeed while only subagent resolution is missing.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions