Designing an Observable and Rollback-Capable Control Plane for AI Assistant Plugins
This article explains how to build a control plane for AI assistant plugins that run inside a host application. It covers four design principles, layered self-checks, pre-change snapshots with rollback, feature toggles, and a recommended install and verification workflow. It includes code examples for the file-check and snapshot layers.
1. Why Local Plugins Need a Control Plane
An AI assistant usually runs inside a host program. The host handles model calls, session management, and tool execution. Plugins extend the host’s capabilities. For example, they can adjust prompt templates, change interaction confirmation policies, or register additional rules. Because plugins directly change host behavior, installing or modifying them carries more risk than installing an ordinary tool.
In practice, problems fall into three categories:
- Opaque state: After installation, whether a patch has taken effect or whether injection is ready can only be judged by experience.
- Irreversible changes: Modifications are spread across several files. When something breaks, the original content cannot be reliably determined.
- Scattered switches: Feature toggles live in configuration files, command-line arguments, and UI options. Turning off one capability means searching for each switch.
A control plane brings these pieces together in one place. Every action has a readable status, every write has a snapshot, and every capability has a clear switch.
2. Four Design Principles
When designing a control plane, start with four baseline principles. The feature design follows from them.
- Local first. All checks and changes run on the local machine. Prompts, configuration, and session content are not uploaded. Any feature that needs network access should be declared separately and disabled by default.
- Visible. Each operation returns an explicit status, such as
applied,skipped,drifted, orfailed, along with evidence such as file paths, checksums, and timestamps. The system should not replace checked results with assumptions like “it should already be in effect.” - Reversible. Before writing to any file, generate a snapshot that saves the original content and a checksum manifest. Rollback reads the manifest and restores the files. It does not depend on memory or manual backups.
- Human in the loop. The tool exists to reduce repetitive work. The user decides what gets modified and which features get enabled. High-risk changes require explicit user consent.
These principles constrain each other. Reversibility requires a snapshot before every write, and visibility requires that snapshots can be inspected. The checksum manifest therefore becomes the shared foundation for both.
3. Layered Self-Checks
A single “installed successfully” flag cannot reflect the real state. A more reliable approach splits self-checks into layers. Each layer makes an independent judgment, and the results are combined into an overall conclusion.
Common layers include:
- Environment layer: Whether the host version, runtime platform, and dependencies meet the requirements.
- File layer: Whether the target files exist and whether their content hashes match the manifest.
- Injection layer: Whether the mount points declared by the plugin have been written into the host configuration.
- Behavior layer: Whether read-only probes confirm that key features can be invoked.
Below is a simplified example of the file layer. It shows the structure only and does not target any specific product.
from dataclasses import dataclassfrom pathlib import Pathimport hashlib@dataclassclass CheckResult:layer: strname: strstatus: str # ok / drift / missing / errorevidence: strdef sha256_of(path: Path) -> str:h = hashlib.sha256()with path.open("rb") as f:for chunk in iter(lambda: f.read(65536), b""):h.update(chunk)return h.hexdigest()def check_file_layer(manifest: dict[str, str]) -> list[CheckResult]:results = []for raw_path, expected in manifest.items():path = Path(raw_path)if not path.exists():results.append(CheckResult("file", raw_path, "missing", "file does not exist"))continueactual = sha256_of(path)status = "ok" if actual == expected else "drift"results.append(CheckResult("file", raw_path, status, f"sha256={actual[:12]}"))return results
The drift status means that a file was modified by an external party after the plugin wrote it. When drift is detected, the tool should not overwrite the file. It should show the differences to the user.
Define the aggregation rules in advance too. If any layer reports error, the overall result is abnormal. drift and missing are listed separately, and the user decides whether to reinject the content or leave the current state in place.
4. Pre-Change Snapshots and Rollback
The core of a snapshot is to record first and modify second. A snapshot should contain at least the following:
- A complete copy of each target file.
- The SHA-256 value of each file before modification.
- The operation ID, execution time, and operation type.
- A record for files that did not exist before, so rollback can delete the newly created files.
The example below reuses the sha256_of function from the previous section.
import jsonimport shutilimport timeimport uuidfrom pathlib import Pathdef snapshot(targets: list[Path], root: Path) -> str:op_id = f"{time.strftime('%Y%m%dT%H%M%S')}-{uuid.uuid4().hex[:8]}"dest = root / op_iddest.mkdir(parents=True)manifest = []for t in targets:if t.exists():backup = dest / t.nameshutil.copy2(t, backup)manifest.append({"path": str(t), "backup": str(backup),"sha256": sha256_of(t)})else:manifest.append({"path": str(t), "backup": None, "sha256": None})(dest / "manifest.json").write_text(json.dumps(manifest, ensure_ascii=False, indent=2), encoding="utf-8")return op_id
The rollback function reads the manifest and restores each item:
def rollback(op_dir: Path) -> None:manifest = json.loads((op_dir / "manifest.json").read_text(encoding="utf-8"))for item in manifest:target = Path(item["path"])if item["backup"] is None:if target.exists():target.unlink()else:shutil.copy2(item["backup"], target)
Before rolling back, compare each file’s current hash with the hash recorded after the change. If they differ, the file was changed again in the meantime. In that case, stop and ask the user.
Snapshot directories may contain sensitive configuration, so they should have the same or stricter access permissions as the original files. Snapshots also use disk space. Set an upper limit on the number of snapshots kept or on how long they are retained.
5. Designing Feature Toggles
Toggle design mainly answers two questions: how fine-grained the toggles should be, and what their defaults should be.
For granularity, group toggles by capability rather than setting one for each modification point. Grouping changes that affect the same type of permission under one toggle prevents users from weighing dozens of options separately.
For defaults, capabilities that relax permissions or rewrite context should be off by default. Read-only and observability capabilities carry lower risk and can be on by default.
Log every toggle state change. Record the time, the old value, the new value, and the actor. When a problem occurs, these records show which toggle change caused it.
A configuration might look like this:
features:observability:default: truerisk: lowpermission_relax:default: falserisk: highcontext_rewrite:default: falserisk: medium
Toggles often depend on one another. If basic injection is disabled, the enhancement features that depend on it should be marked unavailable, and the interface should explain why. Validate these dependencies in the configuration layer. Do not leave them to fail at runtime.
6. Recommended Installation and Verification Workflow
A reliable installation process usually includes these steps:
- Environment check: Confirm that the host version and runtime platform are within the supported range. Stop if they are not.
- Create a snapshot: Record the operation ID so that any later failure can return to this point.
- Preview differences: Show the user which files will change and what the content differences are. Proceed only after the user confirms.
- Write and verify: Immediately after writing, recalculate the hashes and compare them with the expected values.
- Layered self-check: Treat the installation as successful only when every layer reports
ok. - Failure handling: If any step fails, roll back using the operation ID and keep the complete log.
The difference preview step is easy to skip, but it puts the human-in-the-loop principle into practice. Only after seeing the differences can the user judge whether a change matches expectations.
7. Boundaries and Risks
A control plane can only manage the content it wrote. Host upgrades may change mount points or configuration structures. Self-checks need to detect these changes and prompt the user to verify the installation again.
Rollback cannot undo side effects that have already happened outside the files. Messages that were sent, commands that were executed, and external APIs that were called will not be restored by restoring files. For this reason, features that trigger external actions should require separate confirmation before they run.
Automated tools should also keep an audit log. The log should record when an operation ran, who ran it, what type of operation it was, and the matching operation ID. The log should not contain sensitive content such as prompts or session data.
8. Implementation Checklist
- Generate a snapshot before every write, and record hashes and an operation ID
- Output self-check results by layer, with evidence that can be verified
- Compare current hashes before rollback, and stop and ask the user if drift is found
- Turn off high-risk toggles by default, and label their risk level
- Validate toggle dependencies in the configuration layer
- Set permissions and a retention policy for snapshot directories
- Keep sensitive content out of operation logs
