> For the complete documentation index, see [llms.txt](https://www.openclawbook.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.openclawbook.xyz/en/ch40-acp/40.2-acp-session-management-and-runtime.md). Agents can also search and read this documentation through its [MCP server](https://www.openclawbook.xyz/~gitbook/mcp).

# 40.2 ACP Session Management and Runtime

> **Generated by**: Claude Opus 5 (claude-opus-5\[1m]) **Token usage**: Input \~226,000 tokens, Output \~9,000 tokens (this section) **Source baseline**: `v2026.3.9` (`v2026.3.8-170-g665f67726`)

***

§40.1 introduced the ACP protocol. This section covers how OpenClaw manages ACP sessions: **where session state lives, how session keys resolve, how sessions resume, and how the runtime cache evicts.**

## 40.2.1 Session Storage (`AcpSessionStore`)

ACP sessions have **two layers of identity** (`src/acp/session.ts`):

```
ACP sessionId       in process memory, acp:<uuid>
       ↕
Gateway sessionKey  persisted
```

The store maps between them and tracks each session's active run.

The two-layer design exists because the two identities have different lifetimes: an ACP `sessionId` is meaningful only within one editor connection, while a Gateway `sessionKey` is the persistent unit of conversation.

**Isolation is the default.** A newly created ACP session gets `acp:<uuid>` — its own sandbox with no connection to any existing conversation.

Sharing an existing agent session requires **explicit opt-in through `_meta.sessionKey` / `sessionLabel`**.

> That default is correct: opening an ACP session in an editor shouldn't silently take over the main session context you have running on Telegram.

## 40.2.2 Session Key Resolution

`src/acp/session-mapper.ts` handles resolution. Three paths:

| Input                      | Result                                              |
| -------------------------- | --------------------------------------------------- |
| Nothing specified          | Generate a fresh `acp:<uuid>`, fully isolated       |
| `_meta.sessionKey` given   | Bind to that Gateway session directly               |
| `_meta.sessionLabel` given | Look up the session by label, creating it if absent |

The label path exists for human ergonomics — remembering `work-notes` is easier than remembering `agent:main:acp:3f2a...`.

## 40.2.3 Session Resume

An editor reconnecting shouldn't lose its conversation. Resume works by:

```
the editor supplies a previously used sessionId
        ↓
the store looks up the corresponding Gateway sessionKey
        ↓
found     → rebind, history intact
not found → treat as a new session
```

**Falling back to a new session rather than erroring** is the right degradation: from the user's perspective the worst case is starting a fresh conversation, not a broken editor integration.

## 40.2.4 Session Identity Tracking

Each ACP session records which client created it (editor name and version) and when.

Two uses:

1. **Diagnostics** — `openclaw sessions list` shows which sessions came from which editor;
2. **Cleanup decisions** — identifying stale sessions from an editor that's long gone.

## 40.2.5 Session Metadata Persistence

ACP session metadata is persisted alongside the ordinary session store (§13.6.6's `sessions.json`) rather than in a separate file.

That's a consequence of "one storage layer, many entry points": an ACP session is a Gateway session with extra metadata, not a parallel species. So `sessions.list`, `sessions.patch`, and the rest work on it unchanged.

## 40.2.6 Runtime Cache and Eviction

`AcpSessionManager` manages concurrency with **a per-sessionKey serial actor queue** plus **a TTL-evicted runtime cache**.

The serial queue is the same instinct as §13.6.1's session lane — **same session serial, different sessions parallel**. The same concurrency primitive gets reused twice in the system.

TTL eviction handles a specific problem: an editor may open dozens of ACP sessions and abandon them without closing. Without eviction, runtime objects accumulate indefinitely.

***

## Section Summary

1. **ACP sessions carry two layers of identity** — the in-memory `acp:<uuid>` and the persisted Gateway `sessionKey` — because the two have different lifetimes.
2. **Isolation is the default**; sharing an existing agent session requires explicit `_meta.sessionKey` / `sessionLabel` opt-in — an editor session shouldn't silently take over your Telegram main session.
3. **Session key resolution has three paths** (fresh / by key / by label), with the label path existing for human memorability.
4. **Resume falls back to a new session rather than erroring** — the worst outcome is a fresh conversation, not a broken integration.
5. **Metadata persists in the ordinary session store** — an ACP session is a Gateway session with extra metadata, not a parallel species, so all `sessions.*` methods work on it unchanged.
6. **Concurrency uses a per-sessionKey serial actor queue** (the same primitive as session lanes) plus **TTL eviction** against abandoned sessions accumulating.
