fix(tracing): link spawned sub-agent Langfuse traces to their parent turn#4678
Conversation
…turn A spawned sub-agent's real work landed as a separate Langfuse trace whose metadata had run_id/parent_run_id/root_run_id all null, so it was not linked to the parent turn — you could not navigate from the opaque spawn span to the sub-agent's detail. Every journalled AgentObservation already carries the RunContext run lineage (run_id, parent_run_id, root_run_id), but trace metadata (built from TraceContext) dropped it. Add the lineage to TraceContext and, at journal export, derive it from the run's observations and stamp it into the trace metadata. Sub-agent traces now point back at the spawning turn (parent_run_id/root_run_id), so Langfuse can thread them as a trace tree.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughTraceContext is extended with optional run_id, parent_run_id, and root_run_id fields plus a with_run_lineage builder method. The Langfuse module derives these lineage values from journal observations and stamps them into trace metadata during push_observations, with accompanying unit tests. ChangesRun Lineage Metadata
Estimated code review effort: 2 (Simple) | ~15 minutes Sequence Diagram(s)sequenceDiagram
participant PushObservations as push_observations
participant LineageHelper as trace_ctx_with_run_lineage
participant ConfigBuilder as trace_config_from_context
participant Langfuse as LangfuseTraceConfig
PushObservations->>LineageHelper: derive lineage from first observation
LineageHelper-->>PushObservations: enriched TraceContext
PushObservations->>ConfigBuilder: build config with enriched context
ConfigBuilder->>Langfuse: stamp run_id/parent_run_id/root_run_id into metadata
Possibly related issues
Possibly related PRs
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 12b59dc748
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| let trace_ctx = trace_ctx_with_run_lineage(trace_ctx, observations); | ||
| let trace = trace_config_from_context(&trace_ctx, environment); |
There was a problem hiding this comment.
Propagate lineage on the live-span export path
This enrichment only runs for journal exports. In the autonomous/bgdeliver path I inspected, run_autonomous attaches the bridge with source: "autonomous" but runs under AgentTurnOrigin::Cli (src/openhuman/agent/task_dispatcher/executor.rs:173-205), while request→journal registration is limited to AgentTurnOrigin::WebChat (src/openhuman/tinyagents/mod.rs:727-734). That makes shadow_compare_journal_projection return None and the bridge falls back to export_run_trace/push_spans (src/openhuman/channels/providers/web/progress_bridge.rs:1420-1444), where these new lineage fields are never stamped. Those ...:bgdeliver... traces therefore remain unlinked unless lineage is also propagated into the live-span path or autonomous runs get journal-exported.
Useful? React with 👍 / 👎.
A spawned sub-agent's real work landed as a separate Langfuse trace (e.g.
…:bgdeliver-…) whose metadata hadrun_id/parent_run_id/root_run_idall null, so it was not linked to the parent turn — you couldn't navigate from the opaque spawn span to the sub-agent's detail.Root cause: trace metadata is built from
TraceContext, which carried no run-lineage fields, sotrace_config_from_contextnever emitted them. But every journalledAgentObservationalready carries the tinyagentsRunContextlineage, and a singlepush_observationsexport is exactly one run's observation stream.Fix: add
run_id/parent_run_id/root_run_idtoTraceContext; at journal export derive the lineage from the run's own observations (trace_ctx_with_run_lineage) and stamp it into the trace metadata. Sub-agent traces now point back at the spawning turn (parent_run_id/root_run_id), so Langfuse can thread them as a trace tree. Top-level turns getrun_idwith no parent. Added unit tests for the stamping + derivation.Note:
cargo check --libcan't complete in this environment (pre-existingwhisper-rs-sysC++ build failure, unrelated); change verified statically.Closes #4657
Summary by CodeRabbit
New Features
Bug Fixes