fix: propagate context cancellation to background jobs and handle interrupted waits#3247
Open
lockp111 wants to merge 1 commit into
Open
fix: propagate context cancellation to background jobs and handle interrupted waits#3247lockp111 wants to merge 1 commit into
lockp111 wants to merge 1 commit into
Conversation
…errupted waits Background jobs started with context.Background() were immune to Esc/session cancellation, leaving zombie processes on cancel. Use the agent context so context cancellation kills the background process. Also check WaitContext return value in job_output so canceled waits return "interrupted" instead of proceeding with stale output. 💘 Generated with Crush Assisted-by: Crush:deepseek-v4-pro
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the Contributor License Agreement (CLA) and hereby sign the CLA. |
Author
|
@meowgorithm @andreynering who can take a look at this MR? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Background shell jobs were launched with
context.Background(), making them immune to Esc (agent cancellation) and session shutdown. This left zombie processes that couldn't be cleaned up without manualjob_kill.Additionally,
job_outputwithwait=truesilently discarded theWaitContextreturn value, so context cancellation during a wait was invisible — the tool returned stale output as if nothing happened.Changes
internal/agent/tools/bash.gorun_in_backgroundand synchronous auto-background paths now use the agent's request context (ctx) instead ofcontext.Background()when callingbgManager.Start.shellCtx→exec.CommandContext→ process killed → goroutine exits →donechannel closes.internal/agent/tools/job_output.goWaitContextreturn value is now checked. When it returnsfalse(context canceled), the tool returns an"interrupted"status with the current partial output, instead of silently falling through to the normal path.internal/agent/tools/job_test.goTestJobOutput_WaitContextCanceled— canceled context returns "interrupted"TestJobOutput_WaitCompletes— normal completion returns "completed"TestJobOutput_NoWaitReturnsRunning— no-wait path returns immediately with "running"Why
job_outputwait path no longer silently ignores context cancellation💘 Generated with Crush
Assisted-by: Crush:deepseek-v4-pro