Skip to content

Commit 1e9a620

Browse files
authored
refactor(gateway): remove deferred channel load flag; 503 plugin routes until runtime ready (#117852)
* refactor(gateway): remove deferred channel load flag; 503 plugin routes until runtime ready * test(agents): make setup middleware load intent explicit * test(gateway): pin webhook startup routing outside SPA
1 parent 8103101 commit 1e9a620

94 files changed

Lines changed: 667 additions & 1070 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/plugins/architecture-internals.md‎

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ Notes:
670670
- Sandboxed external Control UI tabs backed by `auth: "gateway"` routes use a short-lived signed cookie grant minted only by authenticated bootstrap; plugin-auth tabs keep their direct iframe path. Before mounting, the parent runs a route-owned probe inside the same opaque sandbox and fails closed when browser privacy policy blocks the cookie. The grant is bound to the owning plugin, matched route root, and current auth generation; its process-random cookie name prevents trusted same-host Gateways from overwriting one another, but cookies never isolate TCP ports. The Gateway hostname is therefore one credential boundary: do not cohost mutually untrusted services on that hostname, including other ports. Route dispatch rejects reuse against a nested route owned by another plugin. Because sandbox descendants are cross-site for cookie purposes, the grant accepts only `GET` and `HEAD` with `operator.read`; mutations and WebSocket upgrades stay on explicit Gateway-authenticated surfaces. The cookie intentionally cannot use CHIPS: current browsers include a cross-site-ancestor bit in the partition key, so nested opaque sandbox frames would lose access to same-route assets. The cookie requires a secure context and browser permission for cross-site cookies, so gateway-auth external tabs are unavailable on plain-HTTP LAN origins or under full third-party-cookie blocking; use HTTPS/Tailscale Serve or browser-trusted loopback with a compatible cookie policy.
671671
- The grant prevents Gateway bearer-token disclosure and accidental route/scope reuse; it does not create a security boundary between native plugins. Native plugin code and the UI content it serves remain part of the same trusted in-process plugin boundary.
672672
- Practical rule: do not assume a gateway-auth plugin route is an implicit admin surface. If your route needs admin-only behavior, opt into `trusted-operator` scope surface, require an identity-bearing auth mode, and document the explicit `x-openclaw-scopes` header contract.
673+
- Startup plugins register HTTP routes with their full runtime after the Gateway starts listening. Until startup sidecars are ready, an otherwise-unclaimed HTTP request returns `503` with `Retry-After: 1`; core routes continue to dispatch normally. This generic fallback covers plugin routes before the runtime registry can identify their owners.
673674
- After route matching and authentication, ordinary handlers participate in Gateway root-work admission. A prepared or restarting Gateway returns `503` before invoking the handler. The narrow exception is a manifest-entitled `auth: "gateway"` route that also opts into the route-specific `trusted-operator` surface; it remains reachable so suspension control dispatch cannot be stranded, while ordinary sibling routes from the same plugin remain behind the admission boundary. WebSocket `handleUpgrade` ownership uses the same atomic admission boundary; once the handler accepts a socket, the socket's later lifetime is plugin-owned and is not tracked by this boundary.
674675

675676
## Plugin SDK import paths
@@ -907,22 +908,6 @@ instead of the full plugin entry. This keeps startup and setup lighter
907908
when your main plugin entry also wires tools, hooks, or other runtime-only
908909
code.
909910

910-
Optional: `openclaw.startup.deferConfiguredChannelFullLoadUntilAfterListen`
911-
can opt a channel plugin into the same `setupEntry` path during the gateway's
912-
pre-listen startup phase, even when the channel is already configured.
913-
914-
Use this only when `setupEntry` fully covers the startup surface that must exist
915-
before the gateway starts listening. In practice, that means the setup entry
916-
must register every channel-owned capability that startup depends on, such as:
917-
918-
- channel registration itself
919-
- any HTTP routes that must be available before the gateway starts listening
920-
- any gateway methods, tools, or services that must exist during that same window
921-
922-
If your full entry still owns any required startup capability, do not enable
923-
this flag. Keep the plugin on the default behavior and let OpenClaw load the
924-
full entry during startup.
925-
926911
Bundled channels can also publish setup-only contract-surface helpers that core
927912
can consult before the full channel runtime is loaded. The current setup
928913
promotion surface is:
@@ -942,26 +927,11 @@ Those setup patch adapters keep bundled contract-surface discovery lazy. Import
942927
time stays light; the promotion surface is loaded only on first use instead of
943928
re-entering bundled channel startup on module import.
944929

945-
When those startup surfaces include gateway RPC methods, keep them on a
930+
When setup surfaces include gateway RPC methods, keep them on a
946931
plugin-specific prefix. Core admin namespaces (`config.*`,
947932
`exec.approvals.*`, `wizard.*`, `update.*`) remain reserved and always resolve
948933
to `operator.admin`, even if a plugin requests a narrower scope.
949934

950-
Example:
951-
952-
```json
953-
{
954-
"name": "@scope/my-channel",
955-
"openclaw": {
956-
"extensions": ["./index.ts"],
957-
"setupEntry": "./setup-entry.ts",
958-
"startup": {
959-
"deferConfiguredChannelFullLoadUntilAfterListen": true
960-
}
961-
}
962-
}
963-
```
964-
965935
### Channel catalog metadata
966936

967937
Channel plugins can advertise setup/discovery metadata via `openclaw.channel` and

‎docs/plugins/architecture.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ After startup, Gateway keeps the current metadata snapshot as a replaceable runt
146146
The snapshot and lookup table keep repeated startup decisions on the fast path:
147147

148148
- channel ownership
149-
- deferred channel startup
149+
- startup plugin planning
150150
- startup plugin ids
151151
- provider and CLI backend ownership
152152
- setup provider, command alias, model catalog provider, and manifest contract ownership

‎docs/plugins/manifest.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ Important examples:
12241224
| ------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
12251225
| `openclaw.extensions` | Declares native plugin entrypoints. Must stay inside the plugin package directory. |
12261226
| `openclaw.runtimeExtensions` | Declares built JavaScript runtime entrypoints for installed packages. Must stay inside the plugin package directory. |
1227-
| `openclaw.setupEntry` | Lightweight setup-only entrypoint used during onboarding, deferred channel startup, and read-only channel status/SecretRef discovery. Must stay inside the plugin package directory. |
1227+
| `openclaw.setupEntry` | Lightweight setup-only entrypoint used during onboarding, channel setup, and read-only channel status/SecretRef discovery. Must stay inside the plugin package directory. |
12281228
| `openclaw.runtimeSetupEntry` | Declares the built JavaScript setup entrypoint for installed packages. Requires `setupEntry`, must exist, and must stay inside the plugin package directory. |
12291229
| `openclaw.channel` | Cheap channel catalog metadata like labels, docs paths, aliases, and selection copy. |
12301230
| `openclaw.channel.approvalFlags` | Closed approval behavior flags available before runtime load. `native` means the channel owns native approval UI and same-turn resolution. |
@@ -1239,10 +1239,11 @@ Important examples:
12391239
| `openclaw.install.expectedIntegrity` | Expected npm dist integrity string such as `sha512-...`; install and update flows verify the fetched artifact against it. |
12401240
| `openclaw.install.allowInvalidConfigRecovery` | Allows a narrow bundled-plugin reinstall recovery path when config is invalid. |
12411241
| `openclaw.install.requiredPlatformPackages` | npm package aliases that must materialize when their lockfile platform constraints match the current host. |
1242-
| `openclaw.startup.deferConfiguredChannelFullLoadUntilAfterListen` | Lets setup-runtime channel surfaces load before listen, then defers the full configured channel plugin until post-listen activation. |
12431242

12441243
Manifest metadata decides which provider/channel/setup choices appear in onboarding before runtime loads. `package.json#openclaw.install` tells onboarding how to fetch or enable that plugin when the user picks one of those choices. Do not move install hints into `openclaw.plugin.json`.
12451244

1245+
Configured startup plugins register HTTP routes from their full runtime after the Gateway starts listening. Until startup sidecars are ready, an otherwise-unclaimed HTTP request returns `503` with `Retry-After: 1`; core routes remain available throughout startup.
1246+
12461247
For `openclaw.channel.cliAddOptions`, use Commander's long-option syntax, such as `--initial-sync-limit <n>`. Set `valueType: "int"` to parse a non-negative integer or `valueType: "list"` to split comma-, semicolon-, or newline-delimited input into strings before the plugin setup adapter receives it. Omit `valueType` to pass the parsed Commander value through unchanged.
12471248

12481249
`openclaw.install.minHostVersion` is enforced during install and manifest registry loading for non-bundled plugin sources. Invalid values are rejected; newer-but-valid values skip external plugins on older hosts. Bundled source plugins are assumed to be co-versioned with the host checkout.

‎docs/plugins/sdk-entrypoints.md‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ import { defineSetupPluginEntry } from "openclaw/plugin-sdk/channel-core";
275275
export default defineSetupPluginEntry(myChannelPlugin);
276276
```
277277

278-
OpenClaw loads this instead of the full entry when a channel is disabled,
279-
unconfigured, or when deferred loading is enabled. See
278+
OpenClaw loads this instead of the full entry when a channel is disabled or
279+
unconfigured. See
280280
[Setup and Config](/plugins/sdk-setup#setup-entry) for when this matters.
281281

282282
Pair `defineSetupPluginEntry(...)` with the narrow setup helper families:
@@ -326,10 +326,9 @@ export default defineBundledChannelSetupEntry({
326326
```
327327

328328
Use this only when a setup flow truly needs a lightweight runtime setter or
329-
setup-safe gateway surface before the full channel entry loads.
329+
setup-safe gateway surface for an unconfigured channel.
330330
`registerSetupRuntime` runs only for `"setup-runtime"` loads; keep it
331-
limited to config-only routes or methods that must exist before deferred
332-
full activation.
331+
limited to config-only routes or methods required by that setup flow.
333332

334333
## Registration mode
335334

@@ -341,7 +340,7 @@ full activation.
341340
| `"discovery"` | Read-only capability discovery | Channel registration, static CLI descriptors, and inert providers; skip sockets, workers, clients, and services |
342341
| `"tool-discovery"` | Scoped load to list or run specific plugins' tools | Capability/tool registration only; no channel activation |
343342
| `"setup-only"` | Disabled/unconfigured channel | Channel registration only |
344-
| `"setup-runtime"` | Setup flow with runtime available | Channel registration plus only the lightweight runtime needed before the full entry loads |
343+
| `"setup-runtime"` | Setup flow with runtime available | Channel registration plus only the lightweight runtime needed during setup |
345344
| `"cli-metadata"` | Root help / CLI metadata capture | CLI descriptors only |
346345

347346
`defineChannelPluginEntry` handles this split automatically. If you use
@@ -421,6 +420,6 @@ Use `openclaw plugins inspect <id>` to see a plugin's shape.
421420

422421
- [SDK Overview](/plugins/sdk-overview) - registration API and subpath reference
423422
- [Runtime Helpers](/plugins/sdk-runtime) - `api.runtime` and `createPluginRuntimeStore`
424-
- [Setup and Config](/plugins/sdk-setup) - manifest, setup entry, deferred loading
423+
- [Setup and Config](/plugins/sdk-setup) - manifest and setup entry loading
425424
- [Channel Plugins](/plugins/sdk-channel-plugins) - building the `ChannelPlugin` object
426425
- [Provider Plugins](/plugins/sdk-provider-plugins) - provider registration and hooks

‎docs/plugins/sdk-overview.md‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -690,20 +690,20 @@ shutdown, see [Safe external cron projection](/plugins/hooks#safe-external-cron-
690690

691691
### API object fields
692692

693-
| Field | Type | Description |
694-
| ------------------------ | ------------------------- | ------------------------------------------------------------------------------------------- |
695-
| `api.id` | `string` | Plugin id |
696-
| `api.name` | `string` | Display name |
697-
| `api.version` | `string?` | Plugin version (optional) |
698-
| `api.description` | `string?` | Plugin description (optional) |
699-
| `api.source` | `string` | Plugin source path |
700-
| `api.rootDir` | `string?` | Plugin root directory (optional) |
701-
| `api.config` | `OpenClawConfig` | Current config snapshot (active in-memory runtime snapshot when available) |
702-
| `api.pluginConfig` | `Record<string, unknown>` | Plugin-specific config from `plugins.entries.<id>.config` |
703-
| `api.runtime` | `PluginRuntime` | [Runtime helpers](/plugins/sdk-runtime) |
704-
| `api.logger` | `PluginLogger` | Scoped logger (`debug`, `info`, `warn`, `error`) |
705-
| `api.registrationMode` | `PluginRegistrationMode` | Current load mode; `"setup-runtime"` is the lightweight pre-full-entry startup/setup window |
706-
| `api.resolvePath(input)` | `(string) => string` | Resolve path relative to plugin root |
693+
| Field | Type | Description |
694+
| ------------------------ | ------------------------- | ----------------------------------------------------------------------------------------- |
695+
| `api.id` | `string` | Plugin id |
696+
| `api.name` | `string` | Display name |
697+
| `api.version` | `string?` | Plugin version (optional) |
698+
| `api.description` | `string?` | Plugin description (optional) |
699+
| `api.source` | `string` | Plugin source path |
700+
| `api.rootDir` | `string?` | Plugin root directory (optional) |
701+
| `api.config` | `OpenClawConfig` | Current config snapshot (active in-memory runtime snapshot when available) |
702+
| `api.pluginConfig` | `Record<string, unknown>` | Plugin-specific config from `plugins.entries.<id>.config` |
703+
| `api.runtime` | `PluginRuntime` | [Runtime helpers](/plugins/sdk-runtime) |
704+
| `api.logger` | `PluginLogger` | Scoped logger (`debug`, `info`, `warn`, `error`) |
705+
| `api.registrationMode` | `PluginRegistrationMode` | Current load mode; `"setup-runtime"` is the lightweight setup flow with runtime available |
706+
| `api.resolvePath(input)` | `(string) => string` | Resolve path relative to plugin root |
707707

708708
## Internal module convention
709709

0 commit comments

Comments
 (0)