Skip to content

fix(cli): settle signal-terminated bash commands - #12679

Closed
Hardik180704 wants to merge 2 commits into
Kilo-Org:mainfrom
Hardik180704:fix/12677-bash-segfault-hang
Closed

fix(cli): settle signal-terminated bash commands#12679
Hardik180704 wants to merge 2 commits into
Kilo-Org:mainfrom
Hardik180704:fix/12677-bash-segfault-hang

Conversation

@Hardik180704

Copy link
Copy Markdown
Contributor

Issue

Fixes #12677

Context

When a command terminated the shell with a signal such as SIGSEGV, the process exit effect failed without producing a numeric exit code. The Bash tool passed that effect directly to Effect.raceAll, which continued waiting for the abort or timeout branches after the exit branch failed. As a result, the tool appeared to hang instead of reporting command failure.

Implementation

Convert expected exit-code lookup failures into a non-zero command status before entering the race. This lets signal-terminated commands settle immediately while preserving the existing abort, timeout, output-drain, and process-cleanup behavior.

A regression test terminates the real shell with SIGSEGV and verifies that the tool completes with a failed status instead of waiting for its configured timeout.

Screenshots / Video

N/A — this is a non-visual CLI process-lifecycle fix.

How to Test

Manual/local verification

  • Agent-executed: bun test test/tool/shell.test.ts in packages/opencode — 24 passed.
  • Agent-executed: bun run typecheck in packages/opencode — passed.
  • Agent-executed: repository pre-push type-check — all 22 non-JetBrains packages and the JetBrains package passed.
  • Agent-executed: bun run lint at the repository root — completed with 0 errors and existing warnings only.
  • Agent-executed: bun run script/check-opencode-annotations.ts --worktree — passed.

Reviewer test steps

  1. Invoke the Bash tool with kill -SEGV $$ on Linux or macOS.
  2. Confirm the tool returns promptly with a non-zero exit status.
  3. Confirm it does not wait for the configured Bash timeout.

Blocked checks and substitute verification

  • None.

Checklist

  • Issue linked above, or exception explained
  • Tests/verification described
  • Screenshots/video included for visual changes, or marked N/A
  • Changeset considered for user-facing changes
  • I personally reviewed the diff and can explain the changes, including any AI-assisted work.

Get in Touch

Please reach out through GitHub on this PR.

Comment thread packages/opencode/src/tool/shell.ts
@kilo-code-bot

kilo-code-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

The previous suggestion (missing logging on the exitCode fallback) has been addressed in 2f0827095e: an Effect.tapError now logs a warning with the underlying error before falling back to exit code 1. The change is minimal, correctly scoped within the existing kilocode_change block, and preserves the SIGSEGV-hang fix.

Files Reviewed (1 file)
  • packages/opencode/src/tool/shell.ts
Previous Review Summary (commit 3dd59a5)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 3dd59a5)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
packages/opencode/src/tool/shell.ts 632 Effect.catch fallback to exit code 1 swallows the underlying exitCode failure without logging, which could hide non-signal-related failures.

The fix itself is sound: converting the expected exitCode failure into a synthetic non-zero status before the raceAll correctly resolves the reported hang, the kilocode_change markers are scoped tightly, the regression test exercises the real shell with SIGSEGV (guarded on non-Windows) and asserts prompt settlement instead of a timeout, and the changeset is user-facing and accurately worded.

Files Reviewed (3 files)
  • .changeset/swift-shells-settle.md
  • packages/opencode/src/tool/shell.ts - 1 issue
  • packages/opencode/test/tool/shell.test.ts

Fix these issues in Kilo Cloud


Reviewed by claude-sonnet-5 · Input: 20 · Output: 2.3K · Cached: 372.5K

Review guidance: REVIEW.md from base branch main

@marius-kilocode

Copy link
Copy Markdown
Collaborator

Closing in favor of #12698, which fixes the same root cause one layer down: the spawner now reports signal termination as the conventional 128 + signum exit code (139 for SIGSEGV), so every exitCode consumer settles, not just the bash tool race, and the signal information survives instead of collapsing to exit 1. Your raceAll analysis was spot on, thanks for digging into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bash tool hangs when called command segfaults

2 participants