Skip to content

Shell tool crashes with nil pointer dereference #199

Open
@PierrunoYT

Description

@PierrunoYT

Problem

The shell tool has multiple crash scenarios that cause OpenCode to fail when AI agents try to execute shell commands.

Crashes Observed

1. TUI Mode Crash

runtime error: slice bounds out of range [15:13]
  • Command: ./opencode.exe -d
  • Location: github.com/charmbracelet/bubbles/viewport
  • Appears to be related to chat UI rendering

2. Shell Command Execution Crash

runtime error: invalid memory address or nil pointer dereference
  • Location: internal/llm/tools/shell.(*PersistentShell).Exec line 272
  • Occurs when AI agent tries to execute shell commands
  • Logged in panic file: opencode-panic-agent.Run-20250606-142055.log

3. Non-Interactive Mode Crash

Error: agent processing failed: panic while running the agent
  • Command: ./opencode.exe -p "test prompt" -d
  • Related to shell tool nil pointer issue

Environment

  • OS: Windows 10
  • OpenCode version: Built from latest main branch
  • Shell: PowerShell

Expected Behavior

Shell commands should execute without crashing the application.

Actual Behavior

Application crashes with nil pointer dereference when shell tool is used.

Workaround

Simple prompts that don't require shell commands work fine:

./opencode.exe -p "What is 2+2?" -q

Returns: 4

Investigation Needed

The issue appears to be in internal/llm/tools/shell/shell.go around line 272 in the PersistentShell.Exec method. This needs investigation to identify why the shell tool is not properly initialized or why it's encountering nil pointer references during execution.

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