Skip to content

Reusable worker sessions: close_agent / resume_agent (CL-6943) - #618

Merged
TheGreatAxios merged 1 commit into
mainfrom
cl-6943-reusable-worker-sessions-interrupt_agent-close_agent
Aug 24, 2026
Merged

Reusable worker sessions: close_agent / resume_agent (CL-6943)#618
TheGreatAxios merged 1 commit into
mainfrom
cl-6943-reusable-worker-sessions-interrupt_agent-close_agent

Conversation

@TheGreatAxios

Copy link
Copy Markdown
Collaborator

Summary

  • spawn_agent workers no longer tear down on a clean completion — the session (agent, workdir, context store) stays open and reusable, per the standing signal that terminate-only lifecycle is what manufactured the salvage/thrash detectors 0.2.109 just removed.
  • Added close_agent(target): permanently closes a session, descendants closed first, each bounded by a ~30s cleanup deadline so a wedged descendant cannot hang the call.
  • Added resume_agent(id): reopens a retained, completed session so it is addressable again (no prompt argument — actually pushing new input is interrupt_agent/followup_task, a separate later change).
  • New AgentLifecycleStatus (pending_init | running | interrupted | completed | shutdown | not_found), tracked alongside the existing TUI display status on SubAgentSession.
  • A retained session is exempt from the finished-session display cap (DEFAULT_MAX_COMPLETED = 20) until close_agent actually shuts it down.

Out of scope (separate lane): interrupt_agent, followup_task. close_agent/resume_agent were already reserved in FLEET_VERBS/gated via assertTierMayMountFleetVerb; leaves cannot mount either.

Teardown notes

close() in the vendored agent package sets closed = true before teardown completes and releases its lock last — a failed/wedged close can leave a workdir lock held. Bounding the cleanup deadline here does not fix that (known issue, CL-6984); it only stops a wedged descendant from hanging the caller's close_agent call.

Test plan

  • bun test src/subagent/session-store.test.ts src/subagent/lifecycle-tools.test.ts src/subagent/authority.test.ts src/subagent/agent-fleet.test.ts src/subagent/run-authority.test.ts
  • bun run check (lint/typecheck/build/test) — full suite green except one pre-existing timing-flaky test (tool execution watchdog > stale resume after a forced ceiling resume does not unfreeze a newer pause), unrelated to this change and passes on its own in isolation.
  • scripts/verify-corbits-only-scope.sh

@linear-code

linear-code Bot commented Aug 24, 2026

Copy link
Copy Markdown

CL-6943

Worker sessions from spawn_agent no longer tear down on a clean
completion — they stay open and retained until close_agent runs.
close_agent(target) permanently closes a session (descendants first,
bounded by a ~30s deadline per session so a wedged descendant cannot
hang the call); resume_agent(id) reopens a retained, completed session.
A new AgentLifecycleStatus enum (pending_init/running/interrupted/
completed/shutdown/not_found) tracks this independent of the existing
TUI display status, and a retained session is exempt from the
finished-session display cap until it is actually closed.

interrupt_agent and followup_task are a separate, later change.
@TheGreatAxios
TheGreatAxios force-pushed the cl-6943-reusable-worker-sessions-interrupt_agent-close_agent branch from 387291e to 0c9b554 Compare August 24, 2026 10:42
@TheGreatAxios
TheGreatAxios enabled auto-merge (squash) August 24, 2026 10:42
@TheGreatAxios
TheGreatAxios merged commit 7a3efc9 into main Aug 24, 2026
5 checks passed
TheGreatAxios added a commit that referenced this pull request Aug 27, 2026
)

Worker sessions from spawn_agent no longer tear down on a clean
completion — they stay open and retained until close_agent runs.
close_agent(target) permanently closes a session (descendants first,
bounded by a ~30s deadline per session so a wedged descendant cannot
hang the call); resume_agent(id) reopens a retained, completed session.
A new AgentLifecycleStatus enum (pending_init/running/interrupted/
completed/shutdown/not_found) tracks this independent of the existing
TUI display status, and a retained session is exempt from the
finished-session display cap until it is actually closed.

interrupt_agent and followup_task are a separate, later change.
TheGreatAxios added a commit that referenced this pull request Aug 27, 2026
)

Worker sessions from spawn_agent no longer tear down on a clean
completion — they stay open and retained until close_agent runs.
close_agent(target) permanently closes a session (descendants first,
bounded by a ~30s deadline per session so a wedged descendant cannot
hang the call); resume_agent(id) reopens a retained, completed session.
A new AgentLifecycleStatus enum (pending_init/running/interrupted/
completed/shutdown/not_found) tracks this independent of the existing
TUI display status, and a retained session is exempt from the
finished-session display cap until it is actually closed.

interrupt_agent and followup_task are a separate, later change.
@TheGreatAxios
TheGreatAxios deleted the cl-6943-reusable-worker-sessions-interrupt_agent-close_agent branch August 28, 2026 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant