docs: document gateway reload helpers · openclaw/openclaw@c8ac4c8
steipete
·
2026-06-05
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway config reload planner. |
| 2 | +// Maps changed config paths to hot-reload actions, no-ops, or full restarts. |
1 | 3 | import { type ChannelId, listChannelPlugins } from "../channels/plugins/index.js"; |
2 | 4 | import { |
3 | 5 | getActivePluginChannelRegistryVersion, |
@@ -146,6 +148,8 @@ function listReloadRules(): ReloadRule[] {
|
146 | 148 | const registry = getActivePluginRegistry(); |
147 | 149 | const activeRegistryVersion = getActivePluginRegistryVersion(); |
148 | 150 | const channelRegistryVersion = getActivePluginChannelRegistryVersion(); |
| 151 | +// Plugin/channel reload rules are process-stable until the active registry |
| 152 | +// version changes; cache them to keep every config diff cheap. |
149 | 153 | if ( |
150 | 154 | registry !== cachedRegistry || |
151 | 155 | activeRegistryVersion !== cachedActiveRegistryVersion || |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway config hot-reload watcher. |
| 2 | +// Diffs config/plugin install snapshots and dispatches hot reload or restart plans. |
1 | 3 | import chokidar from "chokidar"; |
2 | 4 | import type { ConfigWriteNotification } from "../config/io.js"; |
3 | 5 | import { formatConfigIssueLines } from "../config/issue-format.js"; |
@@ -126,6 +128,8 @@ export function startGatewayConfigReloader(opts: {
|
126 | 128 | if (stopped) { |
127 | 129 | return; |
128 | 130 | } |
| 131 | +// Coalesce filesystem/write-listener bursts into one reload pass. Config |
| 132 | +// writes often touch temp and final paths in quick succession. |
129 | 133 | if (debounceTimer) { |
130 | 134 | clearTimeout(debounceTimer); |
131 | 135 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway credential planning helpers. |
| 2 | +// Classifies local/remote auth inputs before SecretRef resolution. |
1 | 3 | import { normalizeOptionalString } from "../../packages/normalization-core/src/string-coerce.js"; |
2 | 4 | import { containsEnvVarReference } from "../config/env-substitution.js"; |
3 | 5 | import type { OpenClawConfig } from "../config/types.openclaw.js"; |
@@ -145,6 +147,8 @@ export function createGatewayCredentialPlan(params: {
|
145 | 147 | const remoteUrlConfigured = Boolean(trimToUndefined(remote?.url)); |
146 | 148 | const tailscaleRemoteExposure = |
147 | 149 | gateway?.tailscale?.mode === "serve" || gateway?.tailscale?.mode === "funnel"; |
| 150 | +// Remote credential surfaces are considered active when the gateway is used |
| 151 | +// remotely or when local auth may be borrowed for a published Tailscale URL. |
148 | 152 | const remoteConfiguredSurface = remoteMode || remoteUrlConfigured || tailscaleRemoteExposure; |
149 | 153 | // Remote credentials may borrow local auth credentials only when the remote |
150 | 154 | // surface exists but no explicit remote/env candidate can satisfy the mode. |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway iOS exec-approval push delivery. |
| 2 | +// Sends APNs request/resolution wakes to paired operator devices. |
1 | 3 | import { normalizeOptionalLowercaseString } from "@openclaw/normalization-core/string-coerce"; |
2 | 4 | import { getRuntimeConfig } from "../config/io.js"; |
3 | 5 | import { |
@@ -149,6 +151,8 @@ async function resolveDeliveryPlan(params: {
|
149 | 151 | isTargetVisible?: (target: ApprovalPushTarget) => boolean; |
150 | 152 | log: GatewayLikeLogger; |
151 | 153 | }): Promise<DeliveryPlan> { |
| 154 | +// Request delivery requires current approval scope; resolution delivery may |
| 155 | +// target prior node ids so existing notification badges can be cleared. |
152 | 156 | const targets = params.explicitNodeIds?.length |
153 | 157 | ? await loadRegisteredTargets({ deviceIds: params.explicitNodeIds }) |
154 | 158 | : await resolvePairedTargets({ |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway exec approval manager. |
| 2 | +// Tracks pending operator decisions and short-lived resolved approval records. |
1 | 3 | import { randomUUID } from "node:crypto"; |
2 | 4 | import { resolveExpiresAtMsFromDurationMs } from "@openclaw/normalization-core/number-coercion"; |
3 | 5 | import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce"; |
@@ -18,6 +20,8 @@ function unrefTimer(timer: ReturnType<typeof setTimeout>): void {
|
18 | 20 | } |
19 | 21 | |
20 | 22 | function scheduleResolvedEntryCleanup(cleanup: () => void): void { |
| 23 | +// Resolved approvals stay visible briefly so node.invoke sanitizers can |
| 24 | +// consume a just-approved id after the UI decision races the command retry. |
21 | 25 | const timer = setTimeout(cleanup, RESOLVED_ENTRY_GRACE_MS); |
22 | 26 | unrefTimer(timer); |
23 | 27 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway model-pricing cache state. |
| 2 | +// Stores normalized pricing rows and source-health failures for runtime reads. |
1 | 3 | import { normalizeProviderId } from "@openclaw/model-catalog-core/provider-id"; |
2 | 4 | import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce"; |
3 | 5 | import { normalizeModelRef } from "../agents/model-selection.js"; |
@@ -42,6 +44,8 @@ const sourceFailures = new Map<
|
42 | 44 | >(); |
43 | 45 | |
44 | 46 | function modelPricingCacheKey(provider: string, model: string): string { |
| 47 | +// Keys accept both provider/model and provider-prefixed model ids so external |
| 48 | +// catalogs can be queried without double-prefixing. |
45 | 49 | const providerId = normalizeProviderId(provider); |
46 | 50 | const modelId = model.trim(); |
47 | 51 | if (!providerId || !modelId) { |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway model-pricing refresh and normalization. |
| 2 | +// Fetches, normalizes, and schedules cached pricing for model usage estimates. |
1 | 3 | import type { ModelCatalogCost } from "@openclaw/model-catalog-core/model-catalog-types"; |
| 4 | +import { |
| 5 | +normalizeOptionalString, |
| 6 | +resolvePrimaryStringValue, |
| 7 | +} from "../../packages/normalization-core/src/string-coerce.js"; |
2 | 8 | import { DEFAULT_PROVIDER } from "../agents/defaults.js"; |
3 | 9 | import { |
4 | 10 | buildModelAliasIndex, |
@@ -26,7 +32,6 @@ import {
|
26 | 32 | } from "../plugins/plugin-metadata-snapshot.js"; |
27 | 33 | import type { PluginMetadataRegistryView } from "../plugins/plugin-metadata-snapshot.types.js"; |
28 | 34 | import type { PluginRegistrySnapshot } from "../plugins/plugin-registry.js"; |
29 | | -import { normalizeOptionalString, resolvePrimaryStringValue } from "../../packages/normalization-core/src/string-coerce.js"; |
30 | 35 | import { |
31 | 36 | clearGatewayModelPricingCacheState, |
32 | 37 | clearGatewayModelPricingFailures, |
@@ -180,6 +185,8 @@ function isTimeoutError(error: unknown): boolean {
|
180 | 185 | } |
181 | 186 | |
182 | 187 | function createPricingFetchSignal(signal: AbortSignal | undefined): AbortSignal { |
| 188 | +// Pricing fetches are background refreshes; bound them so startup/reload |
| 189 | +// cannot leave an unbounded network request alive. |
183 | 190 | const timeoutSignal = AbortSignal.timeout(FETCH_TIMEOUT_MS); |
184 | 191 | return signal ? AbortSignal.any([signal, timeoutSignal]) : timeoutSignal; |
185 | 192 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway hot-reload handlers. |
| 2 | +// Applies config reload plans to hooks, cron, heartbeat, plugins, channels, and restarts. |
1 | 3 | import { disposeAllSessionMcpRuntimes } from "../agents/agent-bundle-mcp-tools.js"; |
2 | 4 | import { |
3 | 5 | getActiveEmbeddedRunCount, |
@@ -102,6 +104,8 @@ async function disposeMcpRuntimesWithTimeout(params: {
|
102 | 104 | onWarn: (message: string) => void; |
103 | 105 | label: string; |
104 | 106 | }) { |
| 107 | +// MCP runtime disposal may need async provider cleanup. Bound it so config |
| 108 | +// reload can proceed and report the stale runtime risk. |
105 | 109 | let timer: ReturnType<typeof setTimeout> | undefined; |
106 | 110 | const disposePromise = params.dispose().catch((error: unknown) => { |
107 | 111 | params.onWarn(`${params.label} failed: ${String(error)}`); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。