openclaw - ✅(Solved) Fix Normal sessions can inherit stale subagent lineage and incorrectly hit sessions_spawn depth limits [1 pull requests, 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#67943Fetched 2026-04-17 08:28:53
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Participants
Timeline (top)
cross-referenced ×1

Normal top-level sessions can inherit stale subagent lineage metadata, which causes later ordinary runs to be treated as nested child sessions. That can make sessions_spawn fail with depth-limit errors like:

  • sessions_spawn is not allowed at this depth (current depth: 2, max: 1)

...even when the visible conversation is a normal top-level group/direct chat.

Root Cause

Session metadata for ordinary turns currently preserves subagent lineage fields from prior state:

  • spawnedBy
  • spawnDepth
  • subagentRole
  • subagentControlScope
  • related parent lineage fields

Later normal runs can then reuse the stored lineage instead of only using live spawned-session context.

Depth checks in sessions_spawn ultimately derive nesting from this persisted lineage, so stale metadata can make an ordinary chat turn look like a nested session.

Fix Action

Fixed

PR fix notes

PR #67946: Clear stale subagent lineage on top-level sessions

Description (problem / solution / changelog)

Fixes #67943.

Summary

Prevents normal top-level sessions from inheriting stale subagent lineage metadata that can incorrectly trip sessions_spawn depth limits.

What changed

  • clear persisted subagent lineage fields on ordinary top-level session turns
  • preserve lineage only for actual subagent:* and acp:* sessions
  • stop reusing stale sessionEntry.spawnedBy for normal top-level agent runs
  • add regression coverage proving top-level sessions no longer pass stale lineage through

Validation

  • npm test -- --run src/agents/agent-command.live-model-switch.test.ts

Changed files

  • src/agents/agent-command.live-model-switch.test.ts (modified, +65/-19)
  • src/agents/agent-command.ts (modified, +6/-1)
  • src/agents/skills.test.ts (modified, +72/-51)
  • src/auto-reply/reply/session.ts (modified, +13/-5)
  • src/gateway/server.hooks.test.ts (modified, +2/-0)
  • src/plugin-sdk/facade-activation-check.runtime.ts (modified, +3/-1)
  • test/extension-test-boundary.test.ts (modified, +1/-1)
RAW_BUFFERClick to expand / collapse

Summary

Normal top-level sessions can inherit stale subagent lineage metadata, which causes later ordinary runs to be treated as nested child sessions. That can make sessions_spawn fail with depth-limit errors like:

  • sessions_spawn is not allowed at this depth (current depth: 2, max: 1)

...even when the visible conversation is a normal top-level group/direct chat.

Root cause

Session metadata for ordinary turns currently preserves subagent lineage fields from prior state:

  • spawnedBy
  • spawnDepth
  • subagentRole
  • subagentControlScope
  • related parent lineage fields

Later normal runs can then reuse the stored lineage instead of only using live spawned-session context.

Depth checks in sessions_spawn ultimately derive nesting from this persisted lineage, so stale metadata can make an ordinary chat turn look like a nested session.

Impact

  • normal chats can lose the ability to spawn subagents
  • behavior is confusing because the visible session looks top-level
  • failures are sticky because the stale lineage keeps being persisted across future turns

Proposed fix

  • clear subagent lineage fields on ordinary top-level session turns
  • preserve lineage only for actual spawned/subagent sessions
  • avoid reusing stale sessionEntry.spawnedBy as normal-run spawn context
  • add regression coverage for a top-level session after stale lineage was previously present

Notes

This appears to be a product bug in session-state persistence/reuse, not a configuration problem.

extent analysis

TL;DR

Clearing subagent lineage fields on ordinary top-level session turns is likely to fix the issue with stale metadata causing depth-limit errors.

Guidance

  • Identify and clear the specific subagent lineage fields (spawnedBy, spawnDepth, subagentRole, subagentControlScope, and related parent lineage fields) on ordinary top-level session turns to prevent reuse of stale metadata.
  • Preserve lineage fields only for actual spawned/subagent sessions to maintain correct session context.
  • Verify that the sessions_spawn function is using the live spawned-session context instead of the persisted lineage to derive nesting.
  • Test the fix by running a normal top-level session after stale lineage was previously present to ensure the issue is resolved.

Example

No code snippet is provided as the issue does not contain specific code references.

Notes

This fix assumes that the issue is indeed caused by the reuse of stale subagent lineage metadata. If the issue persists after applying the fix, further investigation into the session-state persistence and reuse mechanism may be necessary.

Recommendation

Apply the proposed fix of clearing subagent lineage fields on ordinary top-level session turns, as it directly addresses the identified root cause of the issue.

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 Normal sessions can inherit stale subagent lineage and incorrectly hit sessions_spawn depth limits [1 pull requests, 1 participants]