openclaw - ✅(Solved) Fix Regression in v2026.3.8: sessions_spawn inherits requester's workspace instead of target agent's configured workspace [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#43636Fetched 2026-04-08 00:16:33
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
closed ×1commented ×1cross-referenced ×1locked ×1

Root Cause

resolveSpawnedWorkspaceInheritance() (introduced in v2026.3.8, reply-DeXK9BLT.js:28331) resolves the requester's agent workspace instead of the target's:

function resolveSpawnedWorkspaceInheritance(params) {
    const explicit = normalizeOptionalText$1(params.explicitWorkspaceDir);
    if (explicit) return explicit;
    const requesterAgentId = params.requesterSessionKey
        ? parseAgentSessionKey(params.requesterSessionKey)?.agentId
        : void 0;
    return requesterAgentId
        ? resolveAgentWorkspaceDir(params.config, normalizeAgentId(requesterAgentId))
        //                         ^^^ resolves PARENT's workspace, not TARGET's
        : void 0;
}

This value is then passed via spawnedMetadata.workspaceDir to the gateway ingress, where it takes precedence over the target agent's configured workspace:

// At ingress (line ~61348):
const workspaceDirRaw = normalizedSpawned.workspaceDir   // ← parent's workspace (always set)
    ?? resolveAgentWorkspaceDir(cfg, sessionAgentId);     // ← target's config (never reached)

In v2026.3.2, spawnSubagentDirect() did not pass workspaceDir in the spawn params at all, so the gateway ingress correctly fell back to resolveAgentWorkspaceDir(cfg, targetAgentId).

Fix Action

Fixed

PR fix notes

PR #45298: fix: Use agent's configured workspace when spawned as subagent

Description (problem / solution / changelog)

Summary

When an agent is spawned via sessions_spawn, the parent's workspaceDir is forwarded to the child. resolveRunWorkspaceDir accepts this inherited value without checking whether the child agent has its own workspace configured, causing subagents to run in the parent's workspace instead of their own.

This means the subagent loads the wrong AGENTS.md, TOOLS.md, SOUL.md, etc. — it gets the parent's personality and instructions instead of its own.

Fixes

  • #43900 — sessions_spawn cross-agent subagents run in requester workspace (cwd ignored)
  • #43636 — Regression: sessions_spawn inherits requester's workspace instead of target agent's
  • #41695 — Sub-agent inherits requester's workspace instead of its own configured workspace
  • #21770 — agents.list[].workspace override ignored

Previously submitted as #22917, which was closed for inactivity.

Solution

In resolveRunWorkspaceDir, check resolveAgentConfig() for the target agent's configured workspace before accepting any provided workspaceDir. If the agent has an explicit workspace in agents.list, prefer it over the inherited value.

This only activates when a non-empty workspaceDir is provided; the null/undefined fallback path already correctly consults the agent config via resolveAgentWorkspaceDir.

Changed files

  • src/agents/workspace-run.ts — Add agent config lookup before accepting inherited workspace
  • src/agents/workspace-run.test.ts — Tests for subagent workspace isolation, no-config fallback, and missing/blank/invalid workspaceDir scenarios

Testing

  • 9 new test cases covering subagent isolation, no-config fallback, and edge cases
  • All existing tests pass (no behavioral change for agents without explicit workspace config)
  • Tested in production multi-agent setup with cross-agent sessions_spawn

Changed files

  • src/agents/workspace-run.test.ts (modified, +91/-0)
  • src/agents/workspace-run.ts (modified, +34/-1)
  • src/commands/agent.ts (modified, +9/-3)

Code Example

{
  agents: {
    defaults: {
      workspace: "/path/to/main-workspace"
    },
    list: [
      { id: "main" },  // uses defaults.workspace → /path/to/main-workspace
      {
        id: "ob",
        workspace: "/path/to/ob-workspace"  // explicit override
      }
    ]
  }
}

---

function resolveSpawnedWorkspaceInheritance(params) {
    const explicit = normalizeOptionalText$1(params.explicitWorkspaceDir);
    if (explicit) return explicit;
    const requesterAgentId = params.requesterSessionKey
        ? parseAgentSessionKey(params.requesterSessionKey)?.agentId
        : void 0;
    return requesterAgentId
        ? resolveAgentWorkspaceDir(params.config, normalizeAgentId(requesterAgentId))
        //                         ^^^ resolves PARENT's workspace, not TARGET's
        : void 0;
}

---

// At ingress (line ~61348):
const workspaceDirRaw = normalizedSpawned.workspaceDir   // ← parent's workspace (always set)
    ?? resolveAgentWorkspaceDir(cfg, sessionAgentId);     // ← target's config (never reached)
RAW_BUFFERClick to expand / collapse

Bug Description

In v2026.3.8, when a parent agent spawns a child agent via sessions_spawn, the child session inherits the requester's (parent's) workspace instead of using the target agent's own configured workspace. This is a regression from v2026.3.2 where the behavior was correct.

Related: #21770 (per-agent workspace override ignored — same root cause area)

Config

{
  agents: {
    defaults: {
      workspace: "/path/to/main-workspace"
    },
    list: [
      { id: "main" },  // uses defaults.workspace → /path/to/main-workspace
      {
        id: "ob",
        workspace: "/path/to/ob-workspace"  // explicit override
      }
    ]
  }
}

Expected Behaviour

When main spawns ob via sessions_spawn, the ob session should use /path/to/ob-workspace (ob's own configured workspace).

Actual Behaviour

The ob session gets cwd: "/path/to/main-workspace" (the parent's workspace). Skills and scripts located in ob's workspace are not found, causing execution failures.

Root Cause

resolveSpawnedWorkspaceInheritance() (introduced in v2026.3.8, reply-DeXK9BLT.js:28331) resolves the requester's agent workspace instead of the target's:

function resolveSpawnedWorkspaceInheritance(params) {
    const explicit = normalizeOptionalText$1(params.explicitWorkspaceDir);
    if (explicit) return explicit;
    const requesterAgentId = params.requesterSessionKey
        ? parseAgentSessionKey(params.requesterSessionKey)?.agentId
        : void 0;
    return requesterAgentId
        ? resolveAgentWorkspaceDir(params.config, normalizeAgentId(requesterAgentId))
        //                         ^^^ resolves PARENT's workspace, not TARGET's
        : void 0;
}

This value is then passed via spawnedMetadata.workspaceDir to the gateway ingress, where it takes precedence over the target agent's configured workspace:

// At ingress (line ~61348):
const workspaceDirRaw = normalizedSpawned.workspaceDir   // ← parent's workspace (always set)
    ?? resolveAgentWorkspaceDir(cfg, sessionAgentId);     // ← target's config (never reached)

In v2026.3.2, spawnSubagentDirect() did not pass workspaceDir in the spawn params at all, so the gateway ingress correctly fell back to resolveAgentWorkspaceDir(cfg, targetAgentId).

Reproduction Steps

  1. Configure two agents with different workspace paths (e.g., main/workspace-a, ob/workspace-b)
  2. Send a message to main asking it to spawn ob via sessions_spawn
  3. Check the spawned ob session's cwd in the JSONL header
  4. Observe: cwd = /workspace-a (main's workspace) instead of /workspace-b (ob's configured workspace)

Suggested Fix

resolveSpawnedWorkspaceInheritance() should return undefined when there is no explicit workspace override, allowing the gateway ingress to resolve the target agent's own configured workspace. The current behavior of looking up the requester's workspace defeats the per-agent workspace configuration.

Version Info

  • Broken: v2026.3.8 (3caab92)
  • Working: v2026.3.2
  • Reproduced on both macOS (Darwin arm64) and Linux (x86_64)
  • The v2026.3.8 release note "Bootstrap runtime plugins once at embedded-run, compaction, and subagent boundaries" likely corresponds to this change

extent analysis

Fix Plan

To resolve the issue, we need to modify the resolveSpawnedWorkspaceInheritance() function to return undefined when there is no explicit workspace override. This will allow the gateway ingress to resolve the target agent's own configured workspace.

Code Changes

function resolveSpawnedWorkspaceInheritance(params) {
    const explicit = normalizeOptionalText$1(params.explicitWorkspaceDir);
    if (explicit) return explicit;
    // Return undefined instead of resolving the requester's workspace
    return undefined;
}

Alternatively, if you want to keep the original logic but fix the issue, you can modify the function to resolve the target agent's workspace instead of the requester's:

function resolveSpawnedWorkspaceInheritance(params) {
    const explicit = normalizeOptionalText$1(params.explicitWorkspaceDir);
    if (explicit) return explicit;
    const targetAgentId = params.targetAgentId;
    return targetAgentId
        ? resolveAgentWorkspaceDir(params.config, normalizeAgentId(targetAgentId))
        : void 0;
}

Verification

To verify the fix, follow the reproduction steps:

  1. Configure two agents with different workspace paths.
  2. Send a message to main asking it to spawn ob via sessions_spawn.
  3. Check the spawned ob session's cwd in the JSONL header.
  4. The cwd should now be set to the target agent's configured workspace (e.g., /workspace-b).

Extra Tips

  • Make sure to test the fix on both macOS and Linux platforms to ensure compatibility.
  • Review the release notes for v2026.3.8 to understand the changes made and how they affected the workspace resolution logic.
  • Consider adding unit tests to ensure the resolveSpawnedWorkspaceInheritance() function behaves correctly in different scenarios.

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 Regression in v2026.3.8: sessions_spawn inherits requester's workspace instead of target agent's configured workspace [1 pull requests, 1 comments, 2 participants]