Skip to content

[Bug]: truncated assistant tool-call turn executes unintended sessions_spawn #97091

Description

@galiniliev

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

A streamed assistant turn that stopped at the output limit still committed and executed an incomplete sessions_spawn tool call, creating an unintended child session.

Steps to reproduce

  1. Have a parent agent emit a batch of sessions_spawn calls.
  2. Hit a stream/max-token truncation condition while the assistant is producing that batch.
  3. Observe whether any incomplete tool call from the partial assistant turn is committed and executed.

Observed live session:

  • The parent was dispatching five intended specialist child tasks.
  • At 2026-06-26T02:17:39.819Z, the assistant emitted visible text saying it would dispatch all five specialists in parallel.
  • At 2026-06-26T02:17:44.026Z, an extra sessions_spawn result was accepted for a child session with no taskName.
  • At 2026-06-26T02:18:59.234Z, the parent identified the bad spawn as a truncated sixth spawn from an incomplete prompt and ignored its output.

Expected behavior

Tool calls from a streamed assistant turn should only execute when the provider completed the turn as tool use. If the assistant turn ends because of length/max-token truncation, newly observed partial tool calls should not execute and should not be replayed as dangling assistant tool calls without matching tool results.

Actual behavior

The incomplete sixth sessions_spawn was accepted and ran as a child:

2026-06-26T02:17:44.026Z extra sessions_spawn accepted
  childSessionKey: [redacted child session key]
  runId: [redacted run id]
  mode: run
  taskName: absent

2026-06-26T02:18:59.234Z parent notes that the truncated sixth spawn was an incomplete prompt

2026-06-26T02:17:46.897Z accidental child first log record
2026-06-26T02:25:40.519Z accidental child last log record
duration: about 7m54s
assistant tool calls: 87
tool results: 87
tool names: exec=81, process=4, read=2

Source context checked on current main before the fix:

  • packages/agent-core/src/agent-loop.ts streams assistant partials into context and replaces them with response.result() on terminal events.
  • The loop executed every toolCall present in the returned assistant message, regardless of whether the assistant stopReason was toolUse or length.
  • The Anthropic Messages transport maps upstream max_tokens to OpenClaw stopReason: "length".

OpenClaw version

2026.6.9

Operating system

linux 6.6.114.1-microsoft-standard-WSL2 (x64)

Install method

Source checkout / local gateway

Model

github-copilot/claude-opus-4.7

Provider / routing chain

OpenClaw -> github-copilot -> claude-opus-4.7 using Anthropic Messages API

Additional provider/model setup details

Telegram channel parent session with OpenClaw subagents. Local logs show provider github-copilot, model id claude-opus-4.7, model API anthropic-messages, Node v26.3.0.

Logs, screenshots, and evidence

2026-06-26T02:17:39.819Z assistant visible text:
  "Worktree is up at PR head ... Now let me dispatch all five specialists in parallel."

2026-06-26T02:17:43.997Z accepted first intended child task
2026-06-26T02:17:44.008Z accepted second intended child task
2026-06-26T02:17:44.018Z accepted third intended child task
2026-06-26T02:17:44.026Z accepted extra child with no taskName
2026-06-26T02:18:53.205Z accepted fourth intended child task
2026-06-26T02:18:53.246Z accepted fifth intended child task

Accidental child counts:
  first=2026-06-26T02:17:46.897Z
  last=2026-06-26T02:25:40.519Z
  assistantMsgs=88
  toolCalls=87
  toolResults=87
  names={"exec":81,"process":4,"read":2}

Duplicate search:

gitcrawl search openclaw/openclaw --query "sessions_spawn truncated assistant frame mid stream tool calls" --mode hybrid --json
=> hits: []

Live GitHub search found closed issue #70694 about child task prompt truncation; that is related but distinct from this parent turn committing an extra tool call after a length-truncated assistant response.

Impact and severity

Affected: users of streamed agent tool calls, especially expensive or side-effectful tools such as subagent spawn.

Severity: High for harness safety/cost; an unintended child session executed side-effectful work for nearly eight minutes.

Frequency: Observed once in a live parent/subagent review session.

Consequence: wasted runtime/tool budget, noisy child completion events, and risk of unintended side effects if the partial tool call is not harmless.

Additional information

This report is about commit/execution behavior for truncated assistant tool-call turns. Separate reports cover the later missed parent wake-up and session-history recovery limitations after the incident.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.bugSomething isn't workingclawsweeper: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:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.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.maintainerMaintainer-authored PR

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions