Skip to content

Bug: Subagent spawn crashes with TypeError on trim() #10089

@GHesericsu

Description

@GHesericsu

Bug Report: Subagent Spawn Crashes with TypeError on trim()

Summary

sessions_spawn consistently fails with TypeError: Cannot read properties of undefined (reading 'trim') when attempting to spawn a subagent. The subagent never executes and crashes at the OpenClaw framework level before any user code runs.

Environment

  • OpenClaw Version: 2026.2.3-1 (d84eb46)
  • Platform: Ubuntu 6.8.0-94-generic (x64)
  • Node Version: v25.5.0
  • Installation Method: npm global install
  • Agent: main
  • Model: anthropic/claude-sonnet-4-5

Steps to Reproduce

  1. Call sessions_spawn tool with any simple task:
    sessions_spawn({
      task: "Test subagent spawn. Report back 'Subagent working!'",
      label: "test-spawn",
      runTimeoutSeconds: 60
    })
  2. Observe immediate failure (within ~2 seconds)

Expected Behavior

  • Subagent spawns in isolated session
  • Task executes
  • Result announces back to parent session

Actual Behavior

  • Spawn appears to be accepted (status: "accepted" with childSessionKey + runId)
  • Immediate crash before any subagent code runs
  • Error: TypeError: Cannot read properties of undefined (reading 'trim')
  • No output in transcript
  • Session JSONL file does not exist at reported path

Error Details

TypeError: Cannot read properties of undefined (reading 'trim')

Stats: 
- runtime: 2s
- tokens: n/a
- sessionKey: agent:main:subagent:<uuid>
- transcript: /root/.openclaw/agents/main/sessions/<sessionId>.jsonl (file not found)

Root Cause Analysis

The crash occurs because params.workspaceDir is undefined when the spawner calls resolveUserPath(), which attempts to call .trim() on the undefined value.

Affected Code Locations (compiled bundles)

The issue appears in the embedded runner initialization, likely in:

  • run.ts:95 (or compiled equivalent in /dist)
  • cli-runner.ts:54
  • utils.ts:4-5 (resolveUserPath function)

Why It Happens

The subagent spawner does not always provide workspaceDir in the params object, but resolveUserPath() assumes it's always a string and directly calls .trim() without a null/undefined check.

Proposed Fix (Two-Layer Defense)

1. Call Site Fix (Root Cause)

run.ts:95 and cli-runner.ts:54

const resolvedWorkspace = resolveUserPath(params.workspaceDir || process.cwd());

This provides a fallback to process.cwd() when workspaceDir is undefined.

2. Utility Hardening (Defense in Depth)

utils.ts:4-5

export function resolveUserPath(input: string): string {
  if (!input) return process.cwd();
  const trimmed = input.trim();
  // ... rest unchanged
}

This prevents future crashes if other callers make the same mistake.

Impact

  • Severity: Critical — completely blocks subagent functionality
  • Workaround: None — no way to spawn subagents in current version
  • Affected Users: Anyone attempting to use sessions_spawn tool

Additional Context

  • Config version mismatch warnings observed before crash (config written by 2026.2.3-1, running 2026.2.3)
  • However, after updating to 2026.2.3-1, the issue persists
  • The error happens at the OpenClaw framework level, not in user/agent code
  • Session history for failed subagent returns empty messages array
  • No TypeScript source files found in /node_modules/openclaw/ — only compiled bundles in /dist

Reproducibility

100% reproducible — fails on every spawn attempt with any task.

Suggested Priority

P0 / High — Core feature completely broken, no workaround available.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions