Skip to content

fix: migrate subagent tracing hook#142

Open
jleonelion wants to merge 1 commit into
comet-ml:mainfrom
jleonelion:fix/subagent-hook-api
Open

fix: migrate subagent tracing hook#142
jleonelion wants to merge 1 commit into
comet-ml:mainfrom
jleonelion:fix/subagent-hook-api

Conversation

@jleonelion

@jleonelion jleonelion commented Jul 26, 2026

Copy link
Copy Markdown

User description

Summary

  • Removes the deprecated api.on("subagent_spawning", ...) registration from the Opik OpenClaw plugin.
  • Creates and enriches Opik subagent lifecycle spans from the supported subagent_spawned hook instead, preserving label/requester/thread metadata.
  • Updates tests and the README event table to match the non-deprecated hook surface.

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.ts
  • npm run lint
  • npm run build
  • npm run test
  • npm run smoke
  • npm run typecheck
  • npm run pack:check

Gate and validation evidence

  • Pre-PR gate: decision=proceed, artifact /tmp/forge-loop/2026-07-26T1000Z-dev-sprint/pre-pr-gate-opik-openclaw.json
  • Protected-file decision: no protected files matched
  • Open-PR conflict decision: proceed, checked 0 open PRs
  • Changed-file count: 4
  • Verifier evidence: not applicable (no sessions_spawn helper used)
  • CI note: CI-will-verify (.github/workflows present).

Co-Authored-By: Forge noreply@openclaw.local


Generated description

Below is a concise technical summary of the changes proposed in this PR:
Migrate registerSubagentHooks to create and enrich subagent lifecycle spans from the supported subagent_spawned hook instead of the deprecated subagent_spawning path. Update the service tests and README event table to reflect the new hook flow and preserved metadata in the Opik plugin.

Latest Contributors(0)
UserCommitDate
Review this PR on Baz | Customize your next review

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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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?

Severity

Want Baz to fix this for you? Activate Fixer

Other fix methods

Fix in Cursor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant