Skip to content

Subagent armTimeout fires against defunct instance if initScheduler rejects #1877

@acoliver

Description

@acoliver

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

  1. Configure a subagent with max_time_minutes set
  2. Cause initScheduler() to reject (e.g., scheduler factory throws)
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Code Quality / ModularizationIssues to do with the quality of llxprt code and its maintainability.

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions