# ConnectionManager
Source: https://docs.maelstrom-ai.co/dev/reference/client/classes/connectionmanager/
Documentation revision: 89a8f5e9d10cedcf0b30376d7846113f06f26120
SDK manifests in this build: @maelstrom-co/react@0.2.1, @maelstrom-co/client@0.2.1, @maelstrom-co/connectors@0.2.1, @maelstrom-co/protocol@0.2.1, @maelstrom-co/engine@0.2.1
These docs follow this source revision. Manifest versions do not prove release compatibility; verify the installed package exports before using an API.

Defined in: [packages/client/src/lib/connection-manager/connection-manager.ts:70](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/connection-manager/connection-manager.ts#L70)

Manages connection lifecycle, retry logic, and circuit breaker patterns for Maelstrom engine connections.

Features:

-   Owns its own TanStack Store for connection state
-   TypedEmitter-based events exposed via `events: EventSubscriber`
-   Exponential backoff retry logic with configurable options
-   Circuit breaker pattern for fault tolerance
-   Auto-reconnect on unexpected disconnections

## Example

```ts
const manager = new ConnectionManager(connector, {
  maxRetries: 3,
  initialDelayMs: 1000,
});

await manager.connect();
manager.events.on('connection_status_changed', (event) => {
  console.log(`Connection: ${event.status}`);
});
```

## Constructors

### Constructor

> **new ConnectionManager**(`connector`, `options`): `ConnectionManager`

Defined in: [packages/client/src/lib/connection-manager/connection-manager.ts:94](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/connection-manager/connection-manager.ts#L94)

#### Parameters

##### connector

[`EngineConnector`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/engineconnector/)

##### options

[`ConnectionManagerOptions`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/connectionmanageroptions/)

#### Returns

`ConnectionManager`

## Properties

### events

> `readonly` **events**: [`EventSubscriber`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/eventsubscriber/)<[`ConnectionManagerEvents`](https://docs.maelstrom-ai.co/dev/reference/client/type-aliases/connectionmanagerevents/)\>

Defined in: [packages/client/src/lib/connection-manager/connection-manager.ts:73](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/connection-manager/connection-manager.ts#L73)

* * *

### store

> `readonly` **store**: `Store`<[`ConnectionManagerState`](https://docs.maelstrom-ai.co/dev/reference/client/type-aliases/connectionmanagerstate/)\>

Defined in: [packages/client/src/lib/connection-manager/connection-manager.ts:71](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/connection-manager/connection-manager.ts#L71)

## Methods

### connect()

> **connect**(): `Promise`<`void`\>

Defined in: [packages/client/src/lib/connection-manager/connection-manager.ts:122](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/connection-manager/connection-manager.ts#L122)

Establishes a connection to the engine with retry logic.

If the circuit breaker is open, this will throw an error immediately. Otherwise, it will attempt to connect with exponential backoff retry.

Startup waits for this Connector’s pending shutdowns owned by this manager. Superseded or disposed attempts do not dial after that wait.

This is the deliberate, user-initiated entry point, so it always starts with a full `maxRetries` budget: `connectionRetryCount` is reset to 0 here regardless of what a previous connect/disconnect cycle left behind. (The automatic-reconnect path is different — it only resets the count after a connection survives `stabilityThresholdMs`, so a server that accepts-then-immediately-closes still exhausts the budget. That delayed reset is unaffected by this one.)

#### Returns

`Promise`<`void`\>

* * *

### disconnect()

> **disconnect**(): `Promise`<`void`\>

Defined in: [packages/client/src/lib/connection-manager/connection-manager.ts:145](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/connection-manager/connection-manager.ts#L145)

Disconnects from the engine and cleans up connection state.

#### Returns

`Promise`<`void`\>

* * *

### dispose()

> **dispose**(): `Promise`<`void`\>

Defined in: [packages/client/src/lib/connection-manager/connection-manager.ts:255](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/connection-manager/connection-manager.ts#L255)

Permanently disposes the ConnectionManager and releases all resources. Waits for current and outgoing Connector shutdowns. After disposal, the ConnectionManager cannot be reused.

#### Returns

`Promise`<`void`\>
