Skip to content

Normal sessions can inherit stale subagent lineage and incorrectly hit sessions_spawn depth limits #67943

Description

@pfrederiksen

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.staleMarked as stale due to inactivity

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions