openclaw - ✅(Solved) Fix Fix: spawned subagent sessions inherit parent agentId instead of spawned agentId [1 pull requests, 5 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#53613Fetched 2026-04-08 01:25:45
View on GitHub
Comments
5
Participants
1
Timeline
6
Reactions
0
Author
Participants
Timeline (top)
commented ×5cross-referenced ×1

Root Cause

Any downstream UI or analytics consumer that relies on session/activity agentId for identity, presence, cost attribution, or status mapping can misattribute spawned specialists to the parent agent.

Fix Action

Fixed

PR fix notes

PR #53622: fix: preserve canonical subagent agent ids in usage

Description (problem / solution / changelog)

Summary

  • preserve canonical child agent ids in usage discovery instead of restamping with the scan agent
  • add schema support for agentId in sessions.patch
  • persist and validate canonical agentId safely
  • add targeted regression tests

Validation

  • pnpm build ✅
  • targeted vitest suite ✅
  • schema spot-check for sessions.patch agentId

Fixes #53613

Changed files

  • src/agents/subagent-spawn.ts (modified, +1/-0)
  • src/config/sessions/types.ts (modified, +2/-0)
  • src/gateway/protocol/schema/sessions.ts (modified, +1/-0)
  • src/gateway/server-methods/agent.ts (modified, +1/-0)
  • src/gateway/server-methods/usage.sessions-usage.test.ts (modified, +56/-0)
  • src/gateway/server-methods/usage.ts (modified, +47/-11)
  • src/gateway/sessions-patch.test.ts (modified, +59/-0)
  • src/gateway/sessions-patch.ts (modified, +27/-0)
RAW_BUFFERClick to expand / collapse

Problem

Spawned specialist sessions can be attributed to the parent agent instead of the spawned agent in downstream consumers.

Why this matters

Any downstream UI or analytics consumer that relies on session/activity agentId for identity, presence, cost attribution, or status mapping can misattribute spawned specialists to the parent agent.

Expected

If an agent spawns a specialist, the downstream session/activity identity should reflect the spawned specialist's canonical agent identity.

Requested fix

Inspect subagent session creation, persistence, and usage/session discovery so the spawned session identity preserves the spawned agent consistently for downstream consumers.

Validation

A spawned specialist should be observable downstream with the correct canonical agentId, allowing dashboards and observability tools to attribute activity correctly.

extent analysis

Fix Plan

To fix the issue, we need to update the session creation and persistence logic to preserve the spawned agent's identity.

Steps to Fix

  • Update the createSession method to accept the spawned agent's ID and use it to set the agentId field in the session object.
  • Modify the persistSession method to store the session object with the correct agentId.
  • Update the getSession method to return the session object with the correct agentId.

Example Code

# Before
def createSession(parent_agent_id):
    session = Session()
    session.agentId = parent_agent_id
    return session

# After
def createSession(spawned_agent_id):
    session = Session()
    session.agentId = spawned_agent_id
    return session

# Example usage:
spawned_agent_id = "specialist-123"
session = createSession(spawned_agent_id)
print(session.agentId)  # Output: specialist-123

Verification

To verify the fix, spawn a specialist and check the agentId field in the downstream consumers. The agentId should match the spawned specialist's canonical ID.

Extra Tips

  • Make sure to update all relevant code paths that create or update sessions to use the spawned agent's ID.
  • Consider adding logging or monitoring to detect any misattributed sessions.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix Fix: spawned subagent sessions inherit parent agentId instead of spawned agentId [1 pull requests, 5 comments, 1 participants]