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.
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_spawnfail 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:
spawnedByspawnDepthsubagentRolesubagentControlScopeLater normal runs can then reuse the stored lineage instead of only using live spawned-session context.
Depth checks in
sessions_spawnultimately derive nesting from this persisted lineage, so stale metadata can make an ordinary chat turn look like a nested session.Impact
Proposed fix
sessionEntry.spawnedByas normal-run spawn contextNotes
This appears to be a product bug in session-state persistence/reuse, not a configuration problem.