Description
In SubAgentScope.runInteractive(), prepareRun() calls armTimeout(abortController) which starts a setTimeout. Control then returns to runInteractive() which calls await this.initScheduler(options) outside the try/finally block whose finally calls clearTimeoutHandle().
If initScheduler() rejects, the timeout handle is never cleared. After max_time_minutes the timer fires and calls abortController.abort() against a defunct subagent instance, causing a resource leak and potentially confusing error logs.
Reproduction
- Configure a subagent with
max_time_minutes set
- Cause
initScheduler() to reject (e.g., scheduler factory throws)
- Observe the timeout fires after the configured minutes despite the subagent already having failed
Expected Behavior
The timeout should be cleared if initScheduler() (or any setup after armTimeout) fails.
Suggested Fix
Either:
- Move
armTimeout() to after initScheduler() succeeds, or
- Wrap
initScheduler() inside the same try/finally boundary that calls clearTimeoutHandle()
Location
packages/core/src/core/subagent.ts \u2014 runInteractive() method (lines ~337\u2013342)
Context
Identified during code review of PR #1876. Pre-existing issue, not introduced by that PR.
Description
In
SubAgentScope.runInteractive(),prepareRun()callsarmTimeout(abortController)which starts asetTimeout. Control then returns torunInteractive()which callsawait this.initScheduler(options)outside thetry/finallyblock whosefinallycallsclearTimeoutHandle().If
initScheduler()rejects, the timeout handle is never cleared. Aftermax_time_minutesthe timer fires and callsabortController.abort()against a defunct subagent instance, causing a resource leak and potentially confusing error logs.Reproduction
max_time_minutessetinitScheduler()to reject (e.g., scheduler factory throws)Expected Behavior
The timeout should be cleared if
initScheduler()(or any setup afterarmTimeout) fails.Suggested Fix
Either:
armTimeout()to afterinitScheduler()succeeds, orinitScheduler()inside the sametry/finallyboundary that callsclearTimeoutHandle()Location
packages/core/src/core/subagent.ts\u2014runInteractive()method (lines ~337\u2013342)Context
Identified during code review of PR #1876. Pre-existing issue, not introduced by that PR.