🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(local-system): guard oversized glob and spawn errors (#17792)
Arvin Xu3295b933cc08
diff --git a/packages/local-file-shell/src/shell/__tests__/runner.test.ts b/packages/local-file-shell/src/shell/__tests__/runner.test.tsindex 8841606cb46..7fae29c10a5 100644--- a/packages/local-file-shell/src/shell/__tests__/runner.test.ts+++ b/packages/local-file-shell/src/shell/__tests__/runner.test.ts@@ -105,6 +105,19 @@ describe('runCommand', () => {expect(result.stdout).toContain('/tmp');});+ it('should report the real spawn error when cwd does not exist', async () => {+ const missingCwd = path.join(tmpDir, 'missing-worktree');+ const result = await runCommand(+ { command: 'echo unreachable', cwd: missingCwd },+ { processManager },+ );++ expect(result.success).toBe(false);+ expect(result.exit_code).toBeUndefined();+ expect(result.error).toContain(`working directory: ${missingCwd}`);+ expect(result.error).toContain('ENOENT');+ });+it('should merge env into child process environment', async () => {const result = await runCommand({diff --git a/packages/local-file-shell/src/shell/process-manager.ts b/packages/local-file-shell/src/shell/process-manager.tsindex d69623fb361..00088981ce6 100644--- a/packages/local-file-shell/src/shell/process-manager.ts+++ b/packages/local-file-shell/src/shell/process-manager.ts@@ -37,6 +37,7 @@ export interface ShellProcess {exitCode: number | null;outputFiles: ShellOutputFiles;process: ChildProcess;+ spawnError?: Error;startedAt?: number;}@@ -234,7 +235,8 @@ export class ShellProcessManager {return {duration_ms: durationMs,- exit_code: exitCode ?? undefined,+ error: shellProcess.spawnError?.message,+ exit_code: shellProcess.spawnError ? undefined : (exitCode ?? undefined),output: stdout + stderr,output_files: {stderr: {@@ -250,7 +252,7 @@ export class ShellProcessManager {},stderr,stdout,- success: true,+ success: !shellProcess.spawnError,};}diff --git a/packages/local-file-shell/src/shell/runner.ts b/packages/local-file-shell/src/shell/runner.tsindex 847a694b1fb..13c65d3f787 100644--- a/packages/local-file-shell/src/shell/runner.ts+++ b/packages/local-file-shell/src/shell/runner.ts@@ -96,6 +96,13 @@ export async function runCommand(childProcess.on('error', (error) => {logger?.error(`${logPrefix} Command failed:`, error);+ const cwdContext = cwd ? ` (working directory: ${cwd})` : '';+ shellProcess.spawnError = new Error(+ `Failed to start command${cwdContext}: ${error.message}`,+ {+ cause: error,+ },+ );shellProcess.exitCode = 1;});childProcess.once('close', () => releaseSandbox?.());diff --git a/packages/tool-runtime/src/ComputerRuntime.ts b/packages/tool-runtime/src/ComputerRuntime.tsindex b9e9d613ddb..7c196271928 100644--- a/packages/tool-runtime/src/ComputerRuntime.ts+++ b/packages/tool-runtime/src/ComputerRuntime.ts@@ -42,6 +42,8 @@ import type {WriteFileState,} from './types';+const MAX_AGENT_GLOB_RESULTS = 1000;+/*** ComputerRuntime — abstract base for computer operations (file system, shell, search).*@@ -474,7 +476,14 @@ export abstract class ComputerRuntime {async globFiles(args: GlobFilesParams): Promise<BuiltinServerRuntimeOutput> {try {- const result = await this.callService('globLocalFiles', args);+ const requestedLimit =+ Number.isFinite(args.limit) && args.limit && args.limit > 0+ ? Math.floor(args.limit)+ : MAX_AGENT_GLOB_RESULTS;+ const result = await this.callService('globLocalFiles', {+ ...args,+ limit: Math.min(requestedLimit, MAX_AGENT_GLOB_RESULTS),+ });if (!result.success) {return this.errorOutput(result, {diff --git a/packages/tool-runtime/src/__tests__/LocalSystemExecutionRuntime.test.ts b/packages/tool-runtime/src/__tests__/LocalSystemExecutionRuntime.test.tsindex 476e81c3058..b48d0638f37 100644--- a/packages/tool-runtime/src/__tests__/LocalSystemExecutionRuntime.test.ts+++ b/packages/tool-runtime/src/__tests__/LocalSystemExecutionRuntime.test.ts@@ -93,6 +93,36 @@ describe('LocalSystemExecutionRuntime.globFiles', () => {scope: '/tmp',});});++ it('applies the agent-facing default glob limit', async () => {+ const service = createService({+ globFiles: vi.fn().mockResolvedValue({ files: [], success: true, total_files: 0 }),+ });+ const runtime = new LocalSystemExecutionRuntime(service);++ await runtime.globFiles({ directory: '/tmp', pattern: '**/*' });++ expect(service.globFiles).toHaveBeenCalledWith({+ limit: 1000,+ pattern: '**/*',+ scope: '/tmp',+ });+ });++ it('caps oversized agent-facing glob limits without changing the file search service', async () => {+ const service = createService({+ globFiles: vi.fn().mockResolvedValue({ files: [], success: true, total_files: 0 }),+ });+ const runtime = new LocalSystemExecutionRuntime(service);++ await runtime.globFiles({ directory: '/tmp', limit: 5000, pattern: '**/*' });++ expect(service.globFiles).toHaveBeenCalledWith({+ limit: 1000,+ pattern: '**/*',+ scope: '/tmp',+ });+ });});describe('LocalSystemExecutionRuntime.grepContent', () => {