fix: migrate subagent tracing hook#142
Open
jleonelion wants to merge 1 commit into
Open
Conversation
Use the non-deprecated subagent_spawned lifecycle hook to create Opik subagent spans, preserving the metadata formerly captured during the legacy subagent_spawning hook. Co-Authored-By: Forge <noreply@openclaw.local>
Comment on lines
63
to
+74
| input: { | ||
| childSessionKey, | ||
| agentId: eventObj.agentId, | ||
| label: eventObj.label, | ||
| mode: eventObj.mode, | ||
| requester: eventObj.requester, | ||
| threadRequested: eventObj.threadRequested, | ||
| }, | ||
| metadata: { | ||
| status: "spawned", | ||
| requesterSessionKey, | ||
| childSessionKey, |
There was a problem hiding this comment.
delivery-target span reused as lifecycle
If childSessionKey was already used by subagent_delivery_target, subagent_spawned only updates the existing span's input and metadata, so it can stay recorded as subagent:delivery-target instead of the intended subagent:<agentId> lifecycle span — should we recreate or rename it here?
Want Baz to fix this for you? Activate Fixer
Other fix methods
Prompt for AI Agents
Before applying, verify this suggestion against the current code. In
`src/service/hooks/subagent.ts` around lines 63-79 inside the
`deps.api.on("subagent_spawned", ...)` handler, the code reuses an existing span if one
exists (from earlier hooks like `subagent_delivery_target`) and only calls
`deps.safeSpanUpdate` for metadata, never recreating/renaming the span to the intended
`subagent:<agentId>` lifecycle semantics. Refactor this logic so that when
`subagent_spawned` fires and the current stored span was created for a different stage
(e.g., name/status mismatch), you end the old span (via the existing `deps.safeSpanEnd`
pattern if available), create a new span with `name: subagent:${agentId}` and the
intended `input` fields (childSessionKey, label, mode, requester, threadRequested),
replace `host.active.subagentSpans` and the remembered host association with the new
span, and then apply the `safeSpanUpdate` enrichment. Ensure the map always points at
the correct “spawned” span for that `childSessionKey` after this handler runs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
Summary
api.on("subagent_spawning", ...)registration from the Opik OpenClaw plugin.subagent_spawnedhook instead, preserving label/requester/thread metadata.Risk: Medium — runtime observability hook behavior changes, but scope is limited to the Opik plugin subagent span lifecycle and covered by focused/full plugin tests.
Test plan
npm run test -- src/service.test.tsnpm run lintnpm run buildnpm run testnpm run smokenpm run typechecknpm run pack:checkGate and validation evidence
decision=proceed, artifact/tmp/forge-loop/2026-07-26T1000Z-dev-sprint/pre-pr-gate-opik-openclaw.jsonCo-Authored-By: Forge noreply@openclaw.local
Generated description
Below is a concise technical summary of the changes proposed in this PR:
Migrate
registerSubagentHooksto create and enrich subagent lifecycle spans from the supportedsubagent_spawnedhook instead of the deprecatedsubagent_spawningpath. Update the service tests and README event table to reflect the new hook flow and preserved metadata in the Opik plugin.Latest Contributors(0)