Skip to content

fix: auto-close spawned children on completion; subagent shutdown ordering - #849

Merged
Pizzaface merged 1 commit into
mainfrom
fix/child-session-lifecycle
Aug 24, 2026
Merged

fix: auto-close spawned children on completion; subagent shutdown ordering#849
Pizzaface merged 1 commit into
mainfrom
fix/child-session-lifecycle

Conversation

@Pizzaface

Copy link
Copy Markdown
Owner

Problem

Spawned child sessions had two lifecycle bugs:

  1. Completed spawn_session children never exited. PIZZAPI_WORKER_AUTO_CLOSE was only plumbed through the trigger-listener routes — the /api/runners/spawn path used by spawn_session never set it, so every spawned child idled on the runner forever after finishing its task. Killing the parent didn't help: children are independent worker processes by design.
  2. Shutdown ordering orphaned subagent mirrors. subagentExtension registered after remoteExtension, so on session_shutdown the remote extension disconnected the worker socket before the subagent extension could abort in-flight relay mirrors and end those ephemeral child sessions — leaving linked children showing as alive until the 10-minute ephemeral TTL sweep.

Closes the shutdown-ordering half of Godmother idea jj0WhkKm.

Changes

  • spawn_session tool: new autoClose param, default true. Plumbed through POST /api/runners/spawnnew_session → spawner env (PIZZAPI_WORKER_AUTO_CLOSE). Completed children now self-terminate instead of idling on the runner. The existing auto-close guard still applies — it won't close if new messages, subscriptions, or linked children arrive, and autoClose: false opts out for interactive follow-ups.
  • factories.ts: register subagentExtension before remoteExtension so shutdown aborts mirrors and ends their relay sessions before the worker socket disconnects.
  • Docs: autoClose documented in features/multi-agent.mdx.

Not in scope

Silent parent-link drop when the parent's Redis record is missing at child registration (child then renders top-level in the UI) — captured as Godmother idea ZwI6GkdP.

Testing

  • bun run typecheck clean.
  • 38 tests across touched files pass, incl. 2 new spawn_session autoClose plumbing tests (default true, explicit false).
  • Full extensions/ + routes/ batch has 7 pre-existing cross-file pollution failures reproduced identically on clean origin/main.

…ering

- spawn_session tool now defaults autoClose=true; plumbed through
  POST /api/runners/spawn -> new_session -> spawner env, so completed
  child workers self-terminate instead of idling on the runner forever
  (auto-close remains guarded against pending messages/subscriptions).
- Register subagentExtension before remoteExtension in factories so
  session_shutdown aborts in-flight relay mirrors and ends those child
  sessions before the remote extension disconnects the worker socket.
- Docs: document the autoClose param.
@Pizzaface
Pizzaface merged commit 990896e into main Aug 24, 2026
12 of 13 checks passed
@Pizzaface
Pizzaface deleted the fix/child-session-lifecycle branch August 24, 2026 18:47
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