fix(ctx_execute): prevent hang when background=true without timeout - #975
Open
ayuayue wants to merge 1 commit into
Open
fix(ctx_execute): prevent hang when background=true without timeout#975ayuayue wants to merge 1 commit into
ayuayue wants to merge 1 commit into
Conversation
When background=true is used without an explicit timeout, the infinite setInterval appended to keep the process alive would prevent the Node.js process from ever exiting (no timer to trigger the detach logic). This caused the tool call to hang forever. Fix: only append the infinite keepalive interval when a timeout is actually set (effTimeout !== undefined). Without a timeout, the process will exit naturally when its work is done, and the tool call completes normally. The background=true documentation already states it requires a timeout: 'Keep process running after timeout (for servers/daemons).'
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.
Problem
When
ctx_executeis called withbackground: truebut no explicittimeout, the tool call hangs forever and the session becomes stuck.Root cause
Two conflicting code paths:
setInterval(()=>{}, 2147483647)to keep the backgrounded process alivetimeoutis explicitly setWith
background: trueand notimeout:res()never called → tool call hangsFix
Only append the keepalive interval when a timeout is actually configured (
effTimeout !== undefined). Without a timeout, the process exits naturally when its code finishes, the "close" event fires, and the tool call completes normally.Changes
src/server.ts: MoveeffTimeout = resolveExecTimeout(timeout)before the instrumented code template, and gate the infinite interval onbackground && effTimeout !== undefinedImpact
background: true+timeoutbackground: true+ no timeout