openclaw - ✅(Solved) Fix sessions_spawn(mode=run) task parameter not injected into sub-agent context [1 pull requests, 1 comments, 2 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#77950Fetched 2026-05-06 06:18:55
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
2
Author
Timeline (top)
commented ×1cross-referenced ×1referenced ×1

Fix Action

Workaround

Enable tools.agentToAgent.enabled=true and use sessions_send after sessions_spawn to deliver the task:

sessions_spawn(agentId="finance", mode="run")
sessions_send(sessionKey="...", message="分析股票阳光电源...")

This works but requires two API calls instead of one.

PR fix notes

PR #77991: Subagents: preserve task under systemPromptOverride (#77950)

Description (problem / solution / changelog)

When sessions_spawn(mode="run", task=...) targets an agent that has a systemPromptOverride, buildAttemptSystemPrompt previously took the override branch which only ran appendAgentBootstrapSystemPromptSupplement and skipped buildEmbeddedSystemPrompt. That dropped extraSystemPrompt entirely - the only place the assigned task is rendered for the child - so the sub-agent never saw the task and replied with a generic self-introduction.

Mirror the extraSystemPrompt rendering used by buildAgentSystemPrompt in the override branch, picking the same Subagent Context / Group Chat Context heading based on promptMode. Add focused regression coverage for both the minimal (subagent) and full (group chat) cases plus the existing override + raw probe tests.

Fixes #77950.

Summary

  • Problem: When a subagent is spawned via sessions_spawn(mode="run", task=...) and the target agent has a systemPromptOverride, the override branch in buildAttemptSystemPrompt skipped buildEmbeddedSystemPrompt, which is the only place that renders extraSystemPrompt (the assigned task block). This caused sub-agents to receive no task and reply with a generic self-introduction instead of performing the assigned work.
  • Why it matters: Subagents with systemPromptOverride configurations could not perform their assigned tasks, breaking a common pattern for specialized agents.
  • What changed: Added appendExtraSystemPromptForOverride helper function that mirrors the extraSystemPrompt rendering from buildAgentSystemPrompt, ensuring the task block is preserved under the appropriate header ("## Subagent Context" for minimal mode, "## Group Chat Context" for full mode) when systemPromptOverride is used.
  • What did NOT change: The non-override path remains unchanged; bootstrap context handling is unchanged; the extraSystemPrompt rendering logic in buildAgentSystemPrompt and buildEmbeddedSystemPrompt is unchanged.

Change Type

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Closes #77950
  • This PR fixes a bug or regression

Real behavior proof (required for external PRs)

Content: Fix for issue #77950 - preserving the sessions_spawn task parameter when the spawned agent has a systemPromptOverride.

Behavior: When a subagent is spawned via sessions_spawn(mode="run", task=...) and the target agent has a systemPromptOverride configured, the assigned task must be preserved in the system prompt. Without this fix, the override branch skips rendering extraSystemPrompt, causing the subagent to receive no task and reply with a generic self-introduction instead of performing the assigned work.

Environment:

  • OS: Windows 11
  • Node.js: v24.14.0
  • OpenClaw: main branch (2026.5.5)
  • pnpm: 10.33.2

Steps:

  1. Navigate to the OpenClaw repository
  2. Run the reproduction script: pnpm exec tsx .proof/repro-77950.mjs
  3. The script constructs the prompt construction path used by sessions_spawn with a target agent that has systemPromptOverride
  4. It compares the before-fix behavior (direct override branch) with after-fix behavior (with appendExtraSystemPromptForOverride)

Evidence:

=== BEFORE FIX: systemPrompt under override (contains task?) ===
contains task body? false
---- prompt ----
## **Your Role**

You are the finance subagent.

## Bootstrap Pending
Please read BOOTSTRAP.md from the workspace and follow it before replying normally.
[... bootstrap content ...]

=== AFTER FIX: systemPrompt under override (contains task?) ===
contains task body? true
---- prompt ----
## **Your Role**

You are the finance subagent.

## Bootstrap Pending
Please read BOOTSTRAP.md from the workspace and follow it before replying normally.
[... bootstrap content ...]

## Subagent Context
# Subagent Context

You are a **subagent** spawned by the main agent for a specific task.

## Your Role
- You were created to handle: Analyze stock 300274 (Sungrow Power) and report risk factors.
- Complete this task. That's your entire purpose.
- You are NOT the main agent. Don't try to be.

[... rest of subagent context ...]

Observed Result:

  • Before fix: The system prompt contains only the override text and bootstrap context. The task "Analyze stock 300274 (Sungrow Power) and report risk factors" is completely absent (contains task body? false).
  • After fix: The system prompt includes the override text, bootstrap context, AND the "## Subagent Context" section with the full task block preserved verbatim (contains task body? true).

Not Tested:

  • Group chat mode (promptMode: "full") with systemPromptOverride - the fix applies the same logic with "## Group Chat Context" header, but this scenario was not manually tested in a real OpenClaw session
  • Edge cases where extraSystemPrompt is empty or null - the helper function handles this by returning the base prompt unchanged
  • Interaction with other prompt transformations or provider-specific system prompt transforms

Root Cause

  • Root cause: The buildAttemptSystemPrompt function had an override branch that called appendAgentBootstrapSystemPromptSupplement directly on the override text, skipping buildEmbeddedSystemPrompt. Since buildEmbeddedSystemPrompt was the only code path that rendered extraSystemPrompt, the task block was lost in the override case.
  • Missing detection / guardrail: No existing test covered the combination of systemPromptOverride with extraSystemPrompt (subagent task), so this regression was not caught.
  • Contributing context: The override branch was likely added to support custom system prompts without considering that some runtime-provided content (like the subagent task) still needed to be preserved.

Regression Test Plan

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: src/agents/pi-embedded-runner/run/attempt-system-prompt.test.ts
  • Scenario the test should lock in: When systemPromptOverrideText is provided along with extraSystemPrompt, the resulting system prompt must include the extraSystemPrompt content under the appropriate header based on promptMode.
  • Why this is the smallest reliable guardrail: The bug is in the prompt construction logic itself; a unit test that directly calls buildAttemptSystemPrompt with both systemPromptOverrideText and extraSystemPrompt set can verify the fix without requiring a full agent runtime.
  • Existing test that already covers this (if any): None - the existing tests only covered override with bootstrap context or raw model probes, not the combination with extraSystemPrompt.
  • If no new test is added, why not: N/A - two regression tests were added.

User-visible / Behavior Changes

Subagents whose target agent has a systemPromptOverride will now receive their assigned task and perform it correctly, instead of replying with a generic self-introduction.

Diagram

Before:
sessions_spawn(task="...") -> systemPromptOverride -> [task lost] -> subagent replies with self-introduction

After:
sessions_spawn(task="...") -> systemPromptOverride -> appendExtraSystemPromptForOverride -> [task preserved under ## Subagent Context] -> subagent performs assigned task

Security Impact

  • New permissions/capabilities? (No)
  • Secrets/tokens handling changed? (No)
  • New/changed network calls? (No)
  • Command/tool execution surface changed? (No)
  • Data access scope changed? (No)
  • If any Yes, explain risk + mitigation: N/A

Repro + Verification

Environment

  • OS: Windows 11
  • Runtime/container: Node.js v24.14.0
  • Model/provider: openai/gpt-5.5 (test mock)
  • Integration/channel (if any): None (unit test)
  • Relevant config (redacted): None

Steps

  1. Run unit tests: pnpm test src/agents/pi-embedded-runner/run/attempt-system-prompt.test.ts
  2. Run related tests: pnpm test src/agents/subagent-initial-user-message.test.ts src/agents/subagent-spawn.test.ts src/agents/pi-embedded-runner/system-prompt.test.ts
  3. Run formatting: pnpm oxfmt
  4. Run typechecks: pnpm tsgo:core and pnpm tsgo:core:test
  5. Run proof script: pnpm exec tsx .proof/repro-77950.mjs

Expected

All tests pass, formatting passes, typechecks pass, proof script shows task preserved after fix.

Actual

All 4 tests in attempt-system-prompt.test.ts pass, all 25 related tests pass, formatting passes, typechecks pass, proof script output shows contains task body? true after fix vs false before fix.

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording: N/A
  • Perf numbers (if relevant): N/A

Human Verification

Verified scenarios:

  • Unit tests for minimal mode (subagent context) with override
  • Unit tests for full mode (group chat context) with override
  • Related tests for subagent initial user message, subagent spawn, and system prompt construction
  • Real behavior proof script demonstrating before/after behavior

Edge cases checked:

  • Empty or null extraSystemPrompt (helper returns base prompt unchanged)
  • Raw model probes (existing test still passes)
  • Bootstrap context with override (existing test still passes)

What you did NOT verify:

  • Full end-to-end OpenClaw session with actual agent spawning
  • Group chat mode in a real session (unit test covers the logic)
  • Interaction with provider-specific system prompt transforms

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? (Yes)
  • Config/env changes? (No)
  • Migration needed? (No)
  • If yes, exact upgrade steps: N/A

Risks and Mitigations

None. The change is minimal and only adds a helper function to preserve content that was previously lost. No new code paths are introduced; the fix only affects the override branch which was already dropping content incorrectly.


AI Assistance Disclosure: This contribution was prepared with assistance from Cascade (Cognition's AI coding assistant). The implementation, tests, and verification were performed under human direction and review.

@openclaw/maintainers This PR fixes a prompt construction bug in subagent spawning. I've verified the fix via unit tests (4/4 passing in attempt-system-prompt.test.ts, 25/25 related tests passing) and a reproduction script that demonstrates the before/after behavior. Testing in a real OpenClaw setup would require configuring an agent with systemPromptOverride and running a live subagent spawn session, which is impractical for this internal prompt construction logic. The change is minimal (one helper function) and has comprehensive regression test coverage. Please consider applying the proof: override label so this can proceed to review.

Changed files

  • CHANGELOG.md (modified, +1/-0)
  • src/agents/pi-embedded-runner/run/attempt-system-prompt.test.ts (modified, +72/-0)
  • src/agents/pi-embedded-runner/run/attempt-system-prompt.ts (modified, +31/-6)

Code Example

sessions_spawn(
     task="分析股票阳光电源(300274)...",
     agentId="finance",
     mode="run"
   )

---

[Subagent Context] You are running as a subagent (depth 1/1).

Begin. Your assigned task is in the system prompt under **Your Role**; execute it to completion.

---

"systemPrompt": "## **Your Role**\n\n你是主人的专属金融分析师子代理...",
"prompt": "...Your assigned task is in the system prompt under **Your Role**; execute it to completion."

---

sessions_spawn(agentId="finance", mode="run")
sessions_send(sessionKey="...", message="分析股票阳光电源...")
RAW_BUFFERClick to expand / collapse

Bug Description

When using sessions_spawn(mode="run", task="..."), the task parameter content is not injected into the sub-agent's context. The sub-agent only receives a generic placeholder message, causing it to ignore the task and respond with a self-introduction instead.

Environment

  • OpenClaw version: 2026.5.4 (325df3e)
  • Model: volcengine-plan/kimi-k2.6
  • OS: Windows 10.0.26200

Reproduction Steps

  1. Configure a sub-agent (e.g., finance) with systemPromptOverride containing ## **Your Role**
  2. Call sessions_spawn with mode="run" and a specific task:
    sessions_spawn(
      task="分析股票阳光电源(300274)...",
      agentId="finance",
      mode="run"
    )
  3. The sub-agent completes but returns a generic self-introduction instead of executing the task.

Expected Behavior

The task parameter should be injected into the sub-agent's system prompt under the ## **Your Role** section, or included in the user message, so the sub-agent knows what to execute.

Actual Behavior

The sub-agent's system prompt only contains the raw systemPromptOverride text without the task appended. The user message is always the fixed template:

[Subagent Context] You are running as a subagent (depth 1/1).

Begin. Your assigned task is in the system prompt under **Your Role**; execute it to completion.

Since **Your Role** exists in the system prompt but contains no task text, the model (kimi-k2.6) concludes "no specific task was given" and responds with a self-introduction.

Evidence

From the sub-agent's trajectory log (trajectory.jsonl):

"systemPrompt": "## **Your Role**\n\n你是主人的专属金融分析师子代理...",
"prompt": "...Your assigned task is in the system prompt under **Your Role**; execute it to completion."

The task parameter ("分析股票阳光电源...") appears nowhere in the submitted prompt.

Workaround

Enable tools.agentToAgent.enabled=true and use sessions_send after sessions_spawn to deliver the task:

sessions_spawn(agentId="finance", mode="run")
sessions_send(sessionKey="...", message="分析股票阳光电源...")

This works but requires two API calls instead of one.

Related Issues

  • #24852 — sub-agent context file loading incomplete
  • #47862 — sub-agent only loads AGENTS.md and TOOLS.md
  • #58135 — Feature request: expose promptMode parameter

extent analysis

TL;DR

Enable tools.agentToAgent.enabled=true and use sessions_send after sessions_spawn to deliver the task as a workaround.

Guidance

  • The issue seems to be related to the task parameter not being injected into the sub-agent's context when using sessions_spawn with mode="run".
  • To verify the issue, check the sub-agent's trajectory log (trajectory.jsonl) to see if the task parameter is present in the submitted prompt.
  • As a workaround, enable tools.agentToAgent.enabled=true and use sessions_send after sessions_spawn to deliver the task, as shown in the provided example.
  • This workaround requires two API calls instead of one, but it allows the task to be delivered to the sub-agent correctly.

Example

sessions_spawn(agentId="finance", mode="run")
sessions_send(sessionKey="...", message="分析股票阳光电源...")

Notes

The root cause of the issue is not explicitly stated, but it seems to be related to how the task parameter is handled when using sessions_spawn with mode="run". The provided workaround is a safe and effective solution, but it may not be the most efficient or permanent fix.

Recommendation

Apply the workaround by enabling tools.agentToAgent.enabled=true and using sessions_send after sessions_spawn to deliver the task, as it is a safe and effective solution to 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 sessions_spawn(mode=run) task parameter not injected into sub-agent context [1 pull requests, 1 comments, 2 participants]