opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Getting stuck at 'Running commands' > Shell > undefined

Open badrul opened this issue 1 month ago • 12 comments

Image

Application hangs indefinitely at the shell execution stage with an undefined reference.

Environment:

OS: Windows 10 OpenCode Version: 1.0.164 Console: cmder

badrul avatar Dec 17 '25 02:12 badrul

This issue might be a duplicate of existing issues. Please check:

  • #4239: TUI hangs when shell outputs massive log
  • #2940: OpenCode just hangs randomly after receiving instructions
  • #3273: MCP client failing makes opencode hang
  • #4061: Session hangs after file write tool execution with massive latency spike

Feel free to ignore if none of these address your specific case.

github-actions[bot] avatar Dec 17 '25 02:12 github-actions[bot]

/oc any idea what could be causing this? look at what shell the packages/desktop uses for the pty ajd figure out what could result in this

rekram1-node avatar Dec 17 '25 02:12 rekram1-node

Now I have a complete picture. Let me summarize the findings:


Analysis: "Running commands > Shell > undefined" Issue

Root Cause

The issue is not directly related to the PTY shell detection in the desktop package. Instead, this appears to be related to how the bash tool renders in the UI when props.input.description is undefined.

Looking at the UI component in packages/ui/src/components/message-part.tsx lines 426-431:

<BasicTool
  icon="console"
  trigger={{
    title: "Shell",
    subtitle: props.input.description,
  }}
>

The subtitle is set to props.input.description. When the LLM calls the bash tool without providing the description parameter, this value is undefined.

In basic-tool.tsx line 51-60, there's a <Show when={trigger().subtitle}> check that should hide it when falsy. However, if the description is the literal string "undefined" (which can happen during JSON serialization/deserialization), it would still display.

Potential Causes

  1. The model is sending the literal string "undefined" as the description parameter instead of omitting it or sending null.

  2. JSON serialization issue: When tool inputs are serialized/deserialized, undefined values might be converted to the string "undefined".

  3. Windows-specific issue: On Windows with cmder, there may be something unusual about how the environment or tool inputs are being processed.

Shell Detection on Windows

The shell detection in packages/opencode/src/shell/shell.ts is actually robust and should never return undefined:

function fallback() {
  if (process.platform === "win32") {
    if (Flag.OPENCODE_GIT_BASH_PATH) return Flag.OPENCODE_GIT_BASH_PATH
    const git = Bun.which("git")
    if (git) {
      const bash = path.join(git, "..", "..", "bin", "bash.exe")
      if (Bun.file(bash).size) return bash  // ⚠️ Potential issue here
    }
    return process.env.COMSPEC || "cmd.exe"  // Always has fallback
  }
  // ...
}

One edge case: Bun.file(bash).size is async but is being used synchronously. This could return a Promise object that's truthy but not a valid shell path. However, this wouldn't produce the string "undefined".

Recommendation

The issue is most likely that the bash tool's description parameter is being displayed as the literal string "undefined". The fix would be to add defensive handling in the UI:

subtitle: props.input.description || undefined,

This ensures that falsy strings like empty string or the string "undefined" aren't displayed.

New%20session%20-%202025-12-17T02%3A14%3A08.920Z opencode session  |  github run

opencode-agent[bot] avatar Dec 17 '25 02:12 opencode-agent[bot]

running with --print-logs, i get these:

ERROR 2025-12-17T02:09:45 +151ms service=acp-command promise={} reason=NotFoundError Unhandled rejection ERROR 2025-12-17T02:09:45 +1ms service=default e=NotFoundError rejection INFO 2025-12-17T02:09:46 +461ms service=bus type=session.updated publishing INFO 2025-12-17T02:09:46 +2ms service=bus type=session.diff publishing ERROR 2025-12-17T02:09:47 +1013ms service=acp-command promise={} reason=NotFoundError Unhandled rejection ERROR 2025-12-17T02:09:47 +0ms service=default e=NotFoundError rejection INFO 2025-12-17T02:09:53 +6233ms service=session.summary title=Checking Current Status title INFO 2025-12-17T02:09:53 +1ms service=bus type=message.updated publishing ERROR 2025-12-17T02:09:54 +1005ms service=acp-command promise={} reason=NotFoundError Unhandled rejection ERROR 2025-12-17T02:09:54 +0ms service=default e=NotFoundError rejection INFO 2025-12-17T02:10:02 +8317ms service=snapshot hash=3745f8b408349c5a1ab621d58ef9f5f0642b16c1 cwd=C:[project path] git=C:[user path].local\share\opencode\snapshot\c5b6b9820d4608b7746befe7c7b05d559b3e8f05 tracking INFO 2025-12-17T02:10:02 +3ms service=bus type=message.part.updated publishing INFO 2025-12-17T02:10:02 +5ms service=bus type=message.part.updated publishing ERROR 2025-12-17T02:10:03 +1002ms service=acp-command promise={} reason=NotFoundError Unhandled rejection ERROR 2025-12-17T02:10:03 +0ms service=default e=NotFoundError rejection INFO 2025-12-17T02:10:04 +978ms service=bus type=message.part.updated publishing INFO 2025-12-17T02:10:05 +331ms service=bus type=message.part.updated publishing INFO 2025-12-17T02:10:05 +8ms service=bus type=message.part.updated publishing INFO 2025-12-17T02:10:05 +29ms service=permission sessionID=ses_4d84b8842ffedJ5Fi5cf25T3wS messageID=msg_b2a120e73002idlMUkP93KoBoH toolCallID=call_d4906847513741d9b6c3011e pattern=["git status *"] asking INFO 2025-12-17T02:10:05 +1ms service=bus type=permission.updated publishing ERROR 2025-12-17T02:10:05 +646ms service=acp-command promise={} reason=NotFoundError Unhandled rejection ERROR 2025-12-17T02:10:05 +1ms service=default e=NotFoundError rejection INFO 2025-12-17T02:10:05 +7ms service=bus type=message.part.updated publishing INFO 2025-12-17T02:10:05 +2ms service=bus type=message.part.updated publishing ERROR 2025-12-17T02:10:06 +1005ms service=acp-command promise={} reason=NotFoundError Unhandled rejection ERROR 2025-12-17T02:10:06 +1ms service=default e=NotFoundError rejection

badrul avatar Dec 17 '25 02:12 badrul

hm need to figure out that not found error looks like cause

rekram1-node avatar Dec 17 '25 02:12 rekram1-node