mirror of
https://github.com/vxcontrol/pentagi.git
synced 2026-07-21 08:15:23 -04:00
[PR #179] [MERGED] fix: isolate detached command context from parent cancellation #216
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/vxcontrol/pentagi/pull/179
Author: @mason5052
Created: 3/5/2026
Status: ✅ Merged
Merged: 3/11/2026
Merged by: @asdek
Base:
feature/next_release← Head:fix/detached-cmd-context-isolation📝 Commits (3)
8701f15fix: isolate detached command context from parent cancellation55aef6atest: add context cancellation tests for detached command isolation1e2cf11Rename mock type to avoid cross-PR symbol collision📊 Changes
2 files changed (+188 additions, -1 deletions)
View changed files
📝
backend/pkg/tools/terminal.go(+2 -1)➕
backend/pkg/tools/terminal_context_test.go(+186 -0)📄 Description
Description of the Change
Problem
Detached terminal commands (
detach=true) inherit the parent context. When the parent context is canceled (e.g., agent delegation timeout after ~2.5 minutes), the detached goroutine'sctx.Done()fires ingetExecResultand kills the background command, even though the command has its own timeout (300-1200 seconds).This makes agent delegation effectively unusable for commands that take more than ~2.5 minutes (which is most penetration testing tasks like
nmapscans).Closes #176
Solution
Use
context.WithoutCancel(ctx)(Go 1.21+) for the detached goroutine. This:context.WithTimeoutingetExecResult)Non-detached commands are unchanged -- they still use the original
ctxand respect parent cancellation as before.Type of Change
Areas Affected
Testing and Verification
Test Configuration
Test Steps
context.WithoutCancelis available in Go 1.24 (introduced in Go 1.21)ExecCommand) still uses originalctxt.tlp.PutMsg) are preserved throughWithoutCancelgetExecResult'sdefer cancel()still prevents goroutine leakSecurity Considerations
No security impact. The change only affects context propagation for background commands. Commands still terminate when their own timeout expires.
Checklist
go fmtandgo vet🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.