Skip to content

Bug: ShellTool sets ProcessStartInfo.WorkingDirectory without verifying directory exists #1286

@petabridge-netclaw

Description

@petabridge-netclaw

Bug

When shell_execute is called with a WorkingDirectory outside the session directory (e.g. ~/.freshdesk-analysis/tickets/601/), ShellTool.ExecuteAsync sets ProcessStartInfo.WorkingDirectory directly without checking if the directory exists.

The code creates the directory only when IsResolvedSessionDirectory() returns true:

// ShellTool.cs lines ~85-100
var resolvedCwd = context.ResolveShellCwd(args.WorkingDirectory);
if (!string.IsNullOrWhiteSpace(resolvedCwd))
{
    if (IsResolvedSessionDirectory(resolvedCwd, context.SessionDirectory))
    {
        Directory.CreateDirectory(resolvedCwd);  // Only here
    }
    psi.WorkingDirectory = resolvedCwd;  // Set regardless
}

When the directory doesn't exist, Process.Start() throws DirectoryNotFoundException, which bubbles up as a generic "Error starting process: ..." message.

Root Cause

ProcessStartInfo.WorkingDirectory requires the path to exist — this is a .NET runtime requirement, not an OS limitation. Forcing agents to create directories via skills before using them as working directories leads to infinite approval-expires loops because the error message doesn't explain why the command failed.

Proposed Fix

Check directory existence before setting WorkingDirectory, and return a helpful error:

if (!string.IsNullOrWhiteSpace(resolvedCwd))
{
    if (IsResolvedSessionDirectory(resolvedCwd, context.SessionDirectory))
    {
        Directory.CreateDirectory(resolvedCwd);
    }
    else if (!Directory.Exists(resolvedCwd))
    {
        return $"Error: Working directory '{resolvedCwd}' does not exist. Create it first (e.g., mkdir -p {resolvedCwd}).";
    }

    psi.WorkingDirectory = resolvedCwd;
}

Impact

  • Affects all shell commands with non-session working directories
  • Affects PowerShell support when it lands (same code path)
  • Agents get stuck in retry loops because the error message doesn't indicate the directory is missing

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions