Skip to content

Commit 75dbe52

Browse files
authored
refactor: one code path behind doctor legacy-state migrations (#120716)
* refactor(doctor): prefer manifest route-state owners * refactor(doctor): unify config repair declarations * refactor(doctor): unify legacy state migrations * fix(doctor): satisfy migration pipeline guards * fix(plugin-sdk): keep doctor adapter inside boundary
1 parent ba7561d commit 75dbe52

94 files changed

Lines changed: 1207 additions & 608 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/concepts/agent-runtimes.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ canonical subscription `github-copilot` provider and is **never** selected by
214214
}
215215
```
216216

217-
The harness claims its provider, runtime, CLI session key, and auth profile
218-
prefix in `extensions/copilot/doctor-contract-api.ts`, which `openclaw doctor`
219-
auto-loads. For configuration, auth, transcript mirroring, compaction, the
217+
The plugin manifest declares the harness provider, runtime, CLI session key,
218+
and auth profile prefix without requiring `openclaw doctor` to load plugin
219+
code. For configuration, auth, transcript mirroring, compaction, the
220220
declarative doctor contract, and the broader PI vs Codex vs Copilot SDK
221221
decision, see [GitHub Copilot agent runtime](/plugins/copilot).
222222

‎docs/plugins/copilot.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,13 @@ keeps `/btw` behavior identical to other non-Codex runtimes.
260260

261261
## Doctor
262262

263-
`extensions/copilot/doctor-contract-api.ts` is auto-loaded by
264-
`src/plugins/doctor-contract-registry.ts`. It contributes:
263+
The Copilot plugin contributes doctor repair metadata through its manifest and
264+
doctor contract:
265265

266266
- An empty `legacyConfigRules` (no retired fields yet).
267267
- A no-op `normalizeCompatibilityConfig` (kept so future field retirements
268268
have a stable in-tree home).
269-
- One `sessionRouteStateOwners` entry: provider `github-copilot`, runtime
269+
- Its manifest declares one `sessionRouteStateOwners` entry: provider `github-copilot`, runtime
270270
`copilot`, CLI session key `copilot`, auth profile prefix `github-copilot:`.
271271

272272
## Limitations

‎docs/plugins/manifest.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ See [Plugins](/tools/plugin) for the full plugin system guide, and [Capability m
162162
| `providerAuthChoices` | No | `object[]` | Cheap auth-choice metadata for onboarding pickers, preferred-provider resolution, and simple CLI flag wiring. |
163163
| `activation` | No | `object` | Cheap activation planner metadata for startup, provider, command, channel, route, and capability-triggered loading. Metadata only; plugin runtime still owns actual behavior. |
164164
| `setup` | No | `object` | Cheap setup/onboarding descriptors that discovery and setup surfaces can inspect without loading plugin runtime. |
165+
| `doctorContract` | No | `object` | Declares which dynamic doctor-contract surfaces the plugin artifact exports so doctor loads only relevant modules. |
166+
| `sessionRouteStateOwners` | No | `object[]` | Static session-route ownership for doctor cleanup. Each entry declares an `id`, `label`, and optional `providerIds`, `runtimeIds`, `cliSessionKeys`, and `authProfilePrefixes`. |
165167
| `qaRunners` | No | `object[]` | Cheap QA runner descriptors used by the shared `openclaw qa` host before plugin runtime loads. |
166168
| `dashboard` | No | `object` | Dashboard widget data bindings and action verbs. Each entry is validated against a Gateway method registered by this plugin with the required read or write scope. See [dashboard reference](#dashboard-reference). |
167169
| `mcpServers` | No | `Record<string, object>` | Static MCP server definitions contributed while this plugin is enabled. Relative command arguments and working directories resolve from the plugin root. Operator `mcp.servers` entries override or disable definitions with the same name. See [MCP server reference](#mcp-server-reference). |
@@ -181,6 +183,18 @@ See [Plugins](/tools/plugin) for the full plugin system guide, and [Capability m
181183
| `version` | No | `string` | Informational plugin version. |
182184
| `uiHints` | No | `Record<string, object>` | UI labels, placeholders, and sensitivity hints for config fields. |
183185

186+
Prefer top-level `sessionRouteStateOwners` for static doctor ownership. The
187+
older `doctorContract.sessionRouteStateOwners: true` declaration plus a
188+
`sessionRouteStateOwners` export from `doctor-contract-api` remains supported
189+
for external plugins, but is deprecated. When the manifest field is present,
190+
OpenClaw uses it without loading the doctor-contract module. Removal plan:
191+
remove the module fallback in OpenClaw 2027.1 after the external-plugin
192+
migration window.
193+
194+
Set `doctorContract.configRepair: true` when the doctor-contract module exports
195+
non-empty `legacyConfigRules`, a `normalizeCompatibilityConfig` function, or
196+
both. One declaration covers the complete config-repair artifact.
197+
184198
## MCP server reference
185199

186200
`mcpServers` lets a native plugin ship an MCP server, including an MCP App, without requiring operators to duplicate its static process definition in `openclaw.json`:

‎docs/plugins/sdk-migration.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,23 @@ External-plugin compatibility work follows this order:
8383
6. Remove only after the announced migration window, usually in a major
8484
release.
8585

86+
### Channel state migration declarations
87+
88+
Channel plugins should declare `doctorContract.stateMigrations: true` in
89+
`openclaw.plugin.json` and export `stateMigrations` from their doctor-contract
90+
artifact. Plan-based migrations can use
91+
`definePluginDoctorMigrationFromPlans(...)` from
92+
`openclaw/plugin-sdk/runtime-doctor` to preserve existing move, copy, preview,
93+
and plugin-state import behavior.
94+
95+
The setup-entry `legacyStateMigrations` option and feature flag,
96+
`setupFeatures.legacyStateMigrations`,
97+
`BundledChannelLegacyStateMigrationDetector`, and
98+
`ChannelPlugin.lifecycle.detectLegacyStateMigrations` remain supported through
99+
one doctor-pipeline adapter for external plugins, but are deprecated. Removal
100+
plan: remove that adapter after OpenClaw 2027.1 only when a published-plugin
101+
reader sweep finds no remaining users.
102+
86103
### AuthStorage SQLite migration
87104

88105
`AuthStorage.forAgent(agentDir)` is the canonical provider-keyed session SDK

‎extensions/anthropic/doctor-contract-api.ts‎

Lines changed: 0 additions & 20 deletions
This file was deleted.

‎extensions/anthropic/openclaw.plugin.json‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
{
22
"id": "anthropic",
3-
"doctorContract": {
4-
"sessionRouteStateOwners": true
5-
},
3+
"doctorContract": {},
4+
"sessionRouteStateOwners": [
5+
{
6+
"id": "anthropic",
7+
"label": "Anthropic",
8+
"providerIds": ["anthropic", "claude-cli"],
9+
"runtimeIds": ["claude-cli"],
10+
"cliSessionKeys": ["claude-cli"],
11+
"authProfilePrefixes": ["anthropic:", "claude-cli:"]
12+
}
13+
],
614
"name": "Anthropic",
715
"description": "Anthropic models, Claude CLI, and native Claude session catalog.",
816
"icon": "https://cdn.simpleicons.org/anthropic",

‎extensions/clickclack/openclaw.plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "clickclack",
33
"doctorContract": {
4-
"normalizeCompatibilityConfig": true
4+
"configRepair": true
55
},
66
"activation": {
77
"onStartup": false

‎extensions/codex/doctor-contract-api.ts‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/**
2-
* Doctor contract hooks for Codex plugin config migrations and session-route
3-
* ownership warnings.
2+
* Doctor contract hooks for Codex plugin config and state migrations.
43
*/
54
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
6-
import type { DoctorSessionRouteStateOwner } from "openclaw/plugin-sdk/runtime-doctor-migrations";
75

86
type LegacyConfigRule = {
97
path: string[];
@@ -137,16 +135,4 @@ export function normalizeCompatibilityConfig({ cfg }: { cfg: OpenClawConfig }):
137135
};
138136
}
139137

140-
/** Session/auth ownership metadata used by doctor route-state checks. */
141-
export const sessionRouteStateOwners: DoctorSessionRouteStateOwner[] = [
142-
{
143-
id: "codex",
144-
label: "Codex",
145-
providerIds: ["codex", "codex-cli", "openai-codex"],
146-
runtimeIds: ["codex", "codex-cli"],
147-
cliSessionKeys: ["codex-cli"],
148-
authProfilePrefixes: ["codex:", "codex-cli:", "openai-codex:"],
149-
},
150-
];
151-
152138
export { stateMigrations } from "./src/migration/session-binding-sidecars.js";

‎extensions/codex/openclaw.plugin.json‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
{
22
"id": "codex",
33
"doctorContract": {
4-
"legacyConfigRules": true,
5-
"normalizeCompatibilityConfig": true,
6-
"sessionRouteStateOwners": true,
4+
"configRepair": true,
75
"stateMigrations": true
86
},
7+
"sessionRouteStateOwners": [
8+
{
9+
"id": "codex",
10+
"label": "Codex",
11+
"providerIds": ["codex", "codex-cli", "openai-codex"],
12+
"runtimeIds": ["codex", "codex-cli"],
13+
"cliSessionKeys": ["codex-cli"],
14+
"authProfilePrefixes": ["codex:", "codex-cli:", "openai-codex:"]
15+
}
16+
],
917
"name": "Codex",
1018
"description": "Codex app-server harness and native session catalog.",
1119
"contracts": {
Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
// Copilot tests cover doctor contract api plugin behavior.
2-
import { expectDefined } from "@openclaw/normalization-core";
32
import { describe, expect, it } from "vitest";
4-
import {
5-
legacyConfigRules,
6-
normalizeCompatibilityConfig,
7-
sessionRouteStateOwners,
8-
} from "./doctor-contract-api.js";
3+
import { legacyConfigRules, normalizeCompatibilityConfig } from "./doctor-contract-api.js";
94

105
describe("copilot doctor contract", () => {
11-
function requireSessionRouteOwner() {
12-
return expectDefined(sessionRouteStateOwners[0], "Copilot session route state owner");
13-
}
14-
156
it("has no legacy config rules at MVP (no retired fields exist yet)", () => {
167
expect(legacyConfigRules).toEqual([]);
178
});
@@ -26,23 +17,4 @@ describe("copilot doctor contract", () => {
2617
expect(result.config).toBe(cfg);
2718
expect(result.changes).toEqual([]);
2819
});
29-
30-
it("declares exactly one session route state owner for copilot", () => {
31-
expect(sessionRouteStateOwners).toHaveLength(1);
32-
const owner = requireSessionRouteOwner();
33-
expect(owner.id).toBe("copilot");
34-
expect(owner.label).toBe("GitHub Copilot agent runtime");
35-
});
36-
37-
it("claims the subscription Copilot providers (matches attempt.ts SUPPORTED_PROVIDERS)", () => {
38-
const owner = requireSessionRouteOwner();
39-
expect(owner.providerIds).toEqual(["github-copilot"]);
40-
});
41-
42-
it("claims the copilot runtime, session key, and auth profile prefix", () => {
43-
const owner = requireSessionRouteOwner();
44-
expect(owner.runtimeIds).toEqual(["copilot"]);
45-
expect(owner.cliSessionKeys).toEqual(["copilot"]);
46-
expect(owner.authProfilePrefixes).toEqual(["github-copilot:"]);
47-
});
4820
});

0 commit comments

Comments
 (0)