[PR #661] [CLOSED] fix: prevent app hanging when executing sudo commands #9677

Closed
opened 2026-02-16 18:13:58 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opencode/pull/661
Author: @delorenj
Created: 7/3/2025
Status: Closed

Base: devHead: fix/sudo-command-hanging


📝 Commits (3)

  • 4aa458f Update download stats 2025-07-02
  • 159a3d3 Update download stats 2025-07-03
  • b41130f fix: prevent app hanging when executing sudo commands

📊 Changes

4 files changed (+154 additions, -0 deletions)

View changed files

📝 STATS.md (+2 -0)
📝 packages/opencode/src/tool/bash.ts (+22 -0)
packages/opencode/test/tool/__snapshots__/bash.test.ts.snap (+3 -0)
packages/opencode/test/tool/bash.test.ts (+127 -0)

📄 Description

Summary

  • Fixes app becoming unresponsive when executing commands requiring sudo password
  • Adds proactive detection and clear error messaging for sudo commands
  • Includes comprehensive test coverage

Problem

When opencode executes a command requiring sudo password, the bash tool spawns the process without stdin connected, causing it to hang indefinitely waiting for password input that can never be provided.

Solution

Added sudo command detection in the bash tool that:

  1. Checks if commands start with sudo
  2. Detects sudo after common command separators (;, &&, ||, |)
  3. Throws a clear error message before execution
  4. Suggests alternative approaches without elevated privileges

Test Coverage

Added comprehensive tests in bash.test.ts:

  • Rejects commands starting with sudo
  • Rejects sudo in command chains
  • Allows commands with "sudo" in non-command context
  • Snapshot test for error message consistency
  • Basic bash functionality tests

Related

Fixes #652

🤖 Generated with opencode


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/anomalyco/opencode/pull/661 **Author:** [@delorenj](https://github.com/delorenj) **Created:** 7/3/2025 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `fix/sudo-command-hanging` --- ### 📝 Commits (3) - [`4aa458f`](https://github.com/anomalyco/opencode/commit/4aa458f29fc7e0a4fa9a194d71e95c8ac8f77eb5) Update download stats 2025-07-02 - [`159a3d3`](https://github.com/anomalyco/opencode/commit/159a3d3abec1c7a8c49bc21582509b4811a1cf91) Update download stats 2025-07-03 - [`b41130f`](https://github.com/anomalyco/opencode/commit/b41130fbe9aeb75f34a7f1928e27fd2cf6d2be15) fix: prevent app hanging when executing sudo commands ### 📊 Changes **4 files changed** (+154 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `STATS.md` (+2 -0) 📝 `packages/opencode/src/tool/bash.ts` (+22 -0) ➕ `packages/opencode/test/tool/__snapshots__/bash.test.ts.snap` (+3 -0) ➕ `packages/opencode/test/tool/bash.test.ts` (+127 -0) </details> ### 📄 Description ## Summary - Fixes app becoming unresponsive when executing commands requiring sudo password - Adds proactive detection and clear error messaging for sudo commands - Includes comprehensive test coverage ## Problem When opencode executes a command requiring sudo password, the bash tool spawns the process without stdin connected, causing it to hang indefinitely waiting for password input that can never be provided. ## Solution Added sudo command detection in the bash tool that: 1. Checks if commands start with `sudo` 2. Detects sudo after common command separators (`;`, `&&`, `||`, `|`) 3. Throws a clear error message before execution 4. Suggests alternative approaches without elevated privileges ## Test Coverage Added comprehensive tests in `bash.test.ts`: - ✅ Rejects commands starting with sudo - ✅ Rejects sudo in command chains - ✅ Allows commands with "sudo" in non-command context - ✅ Snapshot test for error message consistency - ✅ Basic bash functionality tests ## Related Fixes #652 🤖 Generated with [opencode](https://opencode.ai) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 18:13:58 -05:00
yindo closed this issue 2026-02-16 18:13:58 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#9677