Skip to main content

Function: closeAll()

closeAll(...roots): Promise<void>

Defined in: packages/core/src/close.ts:45

Close every processable reachable from roots, the roots included.

A node that owns nothing does not implement close() and is skipped, so this is safe to point at a whole composition — closeAll(pipeline) finds the one sandbox-configured bot on step three without the caller knowing it is there.

Nodes are visited once even when several roots share one, so a crew whose agents were built from the same bot stops that bot's sandbox once.

Closes are issued concurrently. No node's teardown depends on another still being up, and a sandbox stop is a round trip to a container — sequencing a ten-agent crew would make teardown ten times the wait for no ordering anyone asked for. A node that does need an order enforces it inside its own close(), the way Baleybot stops its tool bridge before its sandbox.

Every node is closed even when an earlier one throws; the failures are rethrown together as a CloseFailedError. Stopping at the first failure would leak exactly the containers this exists to release.

Parameters

roots

...Processable<unknown, unknown>[]

Returns

Promise<void>

Example

const crewSession = await crew.start('Ship the auth feature');
const result = await crewSession.stop(); // ends the conversation
await crew.dispose(); // releases what the crew owns

// Directly, for anything you built yourself — including the agents you
// handed a crew, which it deliberately leaves alone:
await closeAll(myPipeline, ...myBots);