> 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.3-acp-control-plane-and-integration-patterns.md). Agents can also search and read this documentation through its [MCP server](https://www.openclawbook.xyz/~gitbook/mcp).

# 40.3 ACP Control Plane and Integration Patterns

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

***

§40.2 covered session management. This section covers the control plane: **provenance tracking, tool streaming, persistent bindings, and error handling.**

## 40.3.1 Control Plane Architecture

The ACP control plane sits between the editor and the Gateway, translating in both directions:

```
editor (ACP client)
   ↕ stdio NDJSON
ACP bridge (openclaw acp)
   ↕ WebSocket
Gateway
```

The bridge is deliberately thin (§40.4): method mapping is nearly one-to-one, so semantics can't drift.

## 40.3.2 Provenance Tracking

ACP sessions can record where each input came from, controlled by a config key with three levels:

```
"off" | "meta" | "meta+receipt"
```

| Level          | Records                                    |
| -------------- | ------------------------------------------ |
| `off`          | Nothing                                    |
| `meta`         | Which client, which session, when          |
| `meta+receipt` | Additionally a receipt of the full request |

**Why does this matter?** Because an ACP session's input may come from an editor, a script, or another agent. When auditing what happened, "who asked for this" is the first question.

This connects to §13.6.6's `InputProvenance` — the same idea applied at the ACP layer.

## 40.3.3 Tool Streaming Enhancements

Editors want to show tool execution progress, not just the final answer.

The bridge translates Gateway `agent` events with `stream: "tool"` into ACP tool-progress notifications, so the editor can render "running `npm test`…" live.

One detail worth noting: **the translation is lossy in a controlled direction.** Gateway tool events carry more structure than ACP's notification shape can express, so the bridge picks what's displayable and drops the rest — rather than inventing an extension the editor wouldn't understand.

## 40.3.4 Persistent Bindings

The reverse direction: OpenClaw as an ACP **host**, running external ACP agents as its own agent runtime (paired with the acpx plugin).

`persistent-bindings` generates a **deterministic sessionKey**:

```
sha256(channel:accountId:conversationId) — first 16 characters
```

This pins a Discord thread or Telegram topic to a specific ACP session.

**Using a hash rather than an auto-increment ID or random UUID has one big advantage: it's stateless and recomputable.** After a Gateway restart, no lookup table is needed to derive the same key — the binding is durable by construction.

> The same technique as §26.4.2's cron staggering by job-id SHA-256: **replace a mapping table that would need persisting with a deterministic hash.**

### Configuration as desired state

```
config change → automatic close + re-init to converge
```

(`persistent-bindings.lifecycle.ts:14-90`)

The comment's phrasing is **"configuration as desired state"** — no incremental diffing; just tear down and rebuild so runtime converges to config.

For a resource like an ACP session where rebuild cost is acceptable, this is far more reliable than hand-written diff logic: diffing must cover every combination of changes, while "rebuild everything" has exactly one path.

> **The deciding factor is rebuild cost.** Rebuilding an ACP session takes milliseconds, so choose the simple reliable full rebuild; if you were rebuilding a multi-gigabyte index, incremental would be mandatory.

## 40.3.5 Runtime Control and Configuration

The ACP runtime can be controlled at runtime: which agents are available, which sessions are bound, and their current state — all queryable and adjustable through the standard Gateway methods, because (per §40.2.5) an ACP session is an ordinary Gateway session with extra metadata.

## 40.3.6 Error Handling and Security

Three defensive details on the bridge:

| Defense                                                 | Details                                                                                                                                             |
| ------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| **2 MB prompt cap, accumulated chunk by chunk**         | A CWE-400 (resource exhaustion) fix; it doesn't check the final size but **accumulates as it receives**, cutting off the moment the cap is exceeded |
| Session creation rate limit, 120 per 10s                | Against session floods                                                                                                                              |
| **Gateway `error` maps to ACP `end_turn`, not refusal** | Original comment: **"don't make transient backend errors look like a deliberate refusal"** (`translator.ts:810-814`)                                |

The third deserves the most attention. An editor receiving `refusal` renders it as "the agent refused your request," and the user concludes it's a content-policy problem — when in fact the gateway just hiccupped.

> **Misclassifying an error misleads the user's next action.** Shown "refused," a user rewrites the prompt; shown "ended," a user retries — and the latter is correct. Same instinct as §45.3's "who is the error message for": an error isn't just a record, it's guidance for downstream behavior.

The security posture inherits the whole model: an ACP session runs on the host, so **sandboxed sessions may not spawn ACP** and `sandbox="require"` is explicitly ineffective on the ACP path (§39.4.3).

***

## Section Summary

1. **The control plane is a bidirectional translator between the editor and the Gateway**, kept deliberately thin so semantics can't drift.
2. **Provenance tracking has three levels** (`off` / `meta` / `meta+receipt`) because ACP input may come from an editor, a script, or another agent — "who asked for this" is the first audit question.
3. **Tool streaming is lossy in a controlled direction** — it picks what's displayable rather than inventing extensions the editor wouldn't understand.
4. **Persistent bindings use `sha256(channel:account:conversation)` for a deterministic sessionKey** — stateless and recomputable, so bindings survive restarts without a lookup table.
5. **"Configuration as desired state"**: config changes trigger close + re-init rather than incremental diffing — **the deciding factor is rebuild cost**, and a millisecond rebuild should take the simple reliable path.
6. **Three defensive details**: a 2 MB prompt cap **accumulated as it receives** (not checked at the end), session creation rate limiting, and **mapping Gateway errors to `end_turn` rather than refusal** — misclassifying an error misleads the user's next action.

***

> ### 🔬 Going Deeper: 40.4 Source Deep Dive
>
> That's the end of the chapter's main text. If you're going to **modify this code**, or reproduce it in your own project, read on: [**40.4 Source Deep Dive: Two ACP Subsystems Pointing Opposite Ways**](https://www.openclawbook.xyz/en/ch40-acp/40.4-source-deep-dive-two-opposite-acp-subsystems.md) traces the real implementation line by line along with the issues behind it, at a noticeably higher information density.
>
> **The main text is for understanding structure; the deep dive is for understanding trade-offs.**
