PicoD subprocess execution does not respect incoming HTTP request cancellation

Open
#499 7 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@SoumaCloud is already working on this.

Since Nov 2, 2026.

  • #505 by @SoumaCloud — open

Assessment

This issue has not been assessed yet.

Description

kind/bug

Title

PicoD subprocess execution does not respect incoming HTTP request cancellation

Description

The PicoD execution handler creates the command context using context.Background() rather than the incoming HTTP request context:

ctx, cancel := context.WithTimeout(context.Background(), timeoutDuration)
defer cancel()

cmd := exec.CommandContext(ctx, req.Command[0], req.Command[1:]...)

Because this context is independent of c.Request.Context(), cancellation of the HTTP request does not propagate to the command's execution context. If a client disconnects or cancels the request while a long-running command is executing, the subprocess may continue running until the configured execution timeout expires.

This can leave unnecessary processes running after the client has abandoned the request, consuming resources and potentially continuing work whose result can no longer be returned.

Steps to Reproduce
  1. Start the Agentcube PicoD server.
  2. Send a request to POST /api/execute that starts a long-running command, with an execution timeout longer than the client wait time.
  3. Cancel the HTTP request or disconnect the client before the command finishes.
  4. Check whether the subprocess is still running after the request has been cancelled.
Expected Behavior

Cancellation of the incoming HTTP request should cancel the command's execution context, causing the subprocess to be terminated rather than continuing until the configured timeout.

Actual Behavior

The command context is derived from context.Background(), so it does not inherit cancellation from the incoming HTTP request. The subprocess can therefore continue executing after the client disconnects, subject to the configured timeout.

Suggested Fix

Derive the timeout context from the incoming request context:

ctx, cancel := context.WithTimeout(c.Request.Context(), timeoutDuration)
defer cancel()

This allows request cancellation and the configured timeout to propagate through exec.CommandContext.

Relevant Code
  • pkg/picod/execute.go, around the context.WithTimeout and exec.CommandContext calls in ExecuteHandler.
Additional Context

This is distinct from handling child processes that outlive their direct parent or inherit stdout/stderr pipes. The issue here is specifically that the execution context is not connected to the HTTP request lifecycle.

Verification status: The context construction is confirmed by source inspection. Runtime reproduction of a subprocess surviving client cancellation is still pending.

Dominant language
Go
Stars
175
Forks
96
Avg merge
3d 17h
Merged PRs (30d)
9

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from volcano-sh/agentcube

All issues in volcano-sh/agentcube

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.