From f10e2fb24bd88d967d484bf056e7060bc5fd9e7b Mon Sep 17 00:00:00 2001 From: Fuad Date: Sat, 26 Apr 2025 23:00:50 +0300 Subject: [PATCH 1/3] Fix nil pointer dereference in GetPersistentShell Added nil check in GetPersistentShell before accessing shellInstance.isAlive to prevent panic when newPersistentShell returns nil due to shell startup errors. This resolves the "invalid memory address or nil pointer dereference" error that was occurring in the shell tool. --- internal/llm/tools/shell/shell.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/llm/tools/shell/shell.go b/internal/llm/tools/shell/shell.go index e25bdf3e..08d8a986 100644 --- a/internal/llm/tools/shell/shell.go +++ b/internal/llm/tools/shell/shell.go @@ -47,7 +47,7 @@ func GetPersistentShell(workingDir string) *PersistentShell { shellInstance = newPersistentShell(workingDir) }) - if !shellInstance.isAlive { + if shellInstance == nil || !shellInstance.isAlive { shellInstance = newPersistentShell(shellInstance.cwd) } From 612258c474019dc03e14f7c01ddb37af275835fc Mon Sep 17 00:00:00 2001 From: Fuad Date: Sun, 27 Apr 2025 06:46:22 +0300 Subject: [PATCH 2/3] use provided workingg dir --- internal/llm/tools/shell/shell.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/llm/tools/shell/shell.go b/internal/llm/tools/shell/shell.go index 08d8a986..10fa3779 100644 --- a/internal/llm/tools/shell/shell.go +++ b/internal/llm/tools/shell/shell.go @@ -48,7 +48,7 @@ func GetPersistentShell(workingDir string) *PersistentShell { }) if shellInstance == nil || !shellInstance.isAlive { - shellInstance = newPersistentShell(shellInstance.cwd) + shellInstance = newPersistentShell(workingDir) } return shellInstance From a3dc97f9b5906d3dde31019bbad676062dbe1beb Mon Sep 17 00:00:00 2001 From: Fuad Date: Sun, 27 Apr 2025 07:25:33 +0300 Subject: [PATCH 3/3] use workingDir if shellInstance is nil otherwise use cwd if shellInstance is not nil --- internal/llm/tools/shell/shell.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/llm/tools/shell/shell.go b/internal/llm/tools/shell/shell.go index 10fa3779..5731faec 100644 --- a/internal/llm/tools/shell/shell.go +++ b/internal/llm/tools/shell/shell.go @@ -47,8 +47,10 @@ func GetPersistentShell(workingDir string) *PersistentShell { shellInstance = newPersistentShell(workingDir) }) - if shellInstance == nil || !shellInstance.isAlive { + if shellInstance == nil { shellInstance = newPersistentShell(workingDir) + } else if !shellInstance.isAlive { + shellInstance = newPersistentShell(shellInstance.cwd) } return shellInstance