[PR #195] [CLOSED] fix(terminal): use context.WithoutCancel for detached commands #224

Closed
opened 2026-06-06 22:09:46 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/vxcontrol/pentagi/pull/195
Author: @manusjs
Created: 3/11/2026
Status: Closed

Base: masterHead: fix/detached-command-context


📝 Commits (1)

  • 4ba2e12 fix(terminal): use context.WithoutCancel for detached commands to prevent parent cancellation

📊 Changes

3 files changed (+167 additions, -6 deletions)

View changed files

📝 backend/pkg/providers/performer.go (+9 -5)
📝 backend/pkg/tools/terminal.go (+2 -1)
backend/pkg/tools/terminal_detach_test.go (+156 -0)

📄 Description

What

Detached terminal commands (detach=true) now run with an independent context so they are not killed when the parent context is canceled. Also adds a sensible default agent execution timeout to specialist performers.

Fixes #176

Root Cause

In terminal.go, ExecCommand with detach=true passed the parent context to the goroutine's getExecResult call. When the parent context was canceled (~2.5 min via Cloudflare tunnel / upstream proxy), the "detached" background command was killed too — making detach=true effectively a no-op.

Changes

  • terminal.go: When detach=true, wraps with context.WithoutCancel(ctx) (Go 1.21+) so the goroutine's context is never canceled by the parent.
  • performers.go: Adds a configurable default agent execution timeout (10 min) to performPentester and other specialist performers via context.WithTimeout, giving each agent its own deadline.
  • terminal_detach_test.go (new): Two tests — verifies goroutine context survives parent cancellation; verifies timeout still fires correctly.

🔄 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/vxcontrol/pentagi/pull/195 **Author:** [@manusjs](https://github.com/manusjs) **Created:** 3/11/2026 **Status:** ❌ Closed **Base:** `master` ← **Head:** `fix/detached-command-context` --- ### 📝 Commits (1) - [`4ba2e12`](https://github.com/vxcontrol/pentagi/commit/4ba2e123700bce024512ce3ad21897527f28d543) fix(terminal): use context.WithoutCancel for detached commands to prevent parent cancellation ### 📊 Changes **3 files changed** (+167 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `backend/pkg/providers/performer.go` (+9 -5) 📝 `backend/pkg/tools/terminal.go` (+2 -1) ➕ `backend/pkg/tools/terminal_detach_test.go` (+156 -0) </details> ### 📄 Description ## What Detached terminal commands (`detach=true`) now run with an independent context so they are not killed when the parent context is canceled. Also adds a sensible default agent execution timeout to specialist performers. Fixes #176 ## Root Cause In `terminal.go`, `ExecCommand` with `detach=true` passed the **parent** context to the goroutine's `getExecResult` call. When the parent context was canceled (~2.5 min via Cloudflare tunnel / upstream proxy), the "detached" background command was killed too — making `detach=true` effectively a no-op. ## Changes - **`terminal.go`**: When `detach=true`, wraps with `context.WithoutCancel(ctx)` (Go 1.21+) so the goroutine's context is never canceled by the parent. - **`performers.go`**: Adds a configurable default agent execution timeout (10 min) to `performPentester` and other specialist performers via `context.WithTimeout`, giving each agent its own deadline. - **`terminal_detach_test.go`** (new): Two tests — verifies goroutine context survives parent cancellation; verifies timeout still fires correctly. --- <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-06-06 22:09:46 -04:00
yindo closed this issue 2026-06-06 22:09:46 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vxcontrol/pentagi#224