Skip to content

Don't reap idle Claude sessions that still run background subagents #1443

Closed

Description

@currentbits

In the Solenta repo (~/code/coder), electron/runner.js scheduleClaudeIdleReap(threadId) retires idle kept-alive Claude CLI sessions in two ways:

  • after CLAUDE_IDLE_REAP_MS (30 min);
  • immediately for the oldest idle sessions once more than CLAUDE_IDLE_MAX (3) are idle.

Neither path checks whether the session still has background subagents running: thread.subagents entries with status: "running", e.g. Claude Agent launches that returned "Async agent launched" and outlive the turn. Disposing the session kills the CLI and those agents. finishRunningSubagents then marks them done, so the user silently loses the work. This happens to any thread that delegates to background agents while 3+ other threads go idle.

Fix it in one place so all callers are covered:

  • Never dispose a session while its thread has a running subagent. Skip it in the cap sweep, and don't arm (or re-arm on fire) the 30-min timer while one runs.
  • Re-schedule once they settle. Subagent rows settle via ingestTaskNotifications and finishRunningSubagents, which already push threads:changed after PR Keep threads with running background subagents on the Working shelf #1423. When the last running subagent settles, call scheduleClaudeIdleReap again so the session can be reaped normally.
  • Bound the exemption with a staleness cap (e.g. 2 h since the subagent row started, or since the session went idle), so a lost task-notification can't pin a session forever.

Write tests in electron/test/claude.test.js using the existing fake-claude scenarios (see "subagent-after-result", which keeps a background agent running after the turn's result):

  1. With CLAUDE_IDLE_MAX exceeded, a session with a running background subagent is not disposed, while an idle one without subagents is.
  2. After the subagent's task-notification settles it, the session becomes reapable again.

Run the tests with env -u CODER_GUARDRAILS_PATH node --test electron/test/claude.test.js. Before running the electron suite in a fresh worktree, clone node_modules and build core first. Then open a PR.

Filed from a Solenta suggested-work chip.

Activity

  1. currentbits commented on Oct 9, 2026

    @currentbits
    OwnerAuthor

    Re-verified on main @24d3c36b (v0.24.0): still live, and worse than reaping alone. The idle cap of 3 (electron/runner-claude-sessions.js:87-91) and the 30-min reap kill idle CLIs that still run background subagents. Then electron/runner-subagents.js:152 marks the killed subagents "done", which reads as success in the Agents panel. Suggest raising this to P1: the fix is S (exclude sessions with live subagents from both the cap and the reap, and mark killed ones failed/interrupted).

  2. added and removed on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions