docs: document gateway utility policies · openclaw/openclaw@7e0ee6d
steipete
·
2026-06-05
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Active session shutdown tracker. |
| 2 | +// Remembers sessions needing `session_end` hooks during gateway shutdown/restart. |
1 | 3 | import type { OpenClawConfig } from "../config/types.openclaw.js"; |
2 | 4 | |
3 | 5 | // Module-level tracker of sessions that have received `session_start` but not |
@@ -39,6 +41,8 @@ export function forgetActiveSessionForShutdown(sessionId: string | undefined): v
|
39 | 41 | } |
40 | 42 | |
41 | 43 | export function listActiveSessionsForShutdown(): ActiveSessionForShutdown[] { |
| 44 | +// Return a snapshot, not the backing map, so shutdown drains can iterate while |
| 45 | +// lifecycle hooks concurrently forget finalized sessions. |
42 | 46 | return Array.from(trackedSessions.values()); |
43 | 47 | } |
44 | 48 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway assistant-event text extractor. |
| 2 | +// Normalizes provider stream event shapes into a display text delta. |
1 | 3 | import type { AgentEventPayload } from "../infra/agent-events.js"; |
2 | 4 | |
3 | 5 | // Agent stream events may carry assistant text as either incremental delta or |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway channel health policy. |
| 2 | +// Evaluates channel lifecycle snapshots for restart/readiness decisions. |
1 | 3 | import type { ChannelId } from "../channels/plugins/types.public.js"; |
2 | 4 | |
3 | 5 | type ChannelHealthSnapshot = { |
@@ -131,6 +133,8 @@ export function resolveChannelRestartReason(
|
131 | 133 | snapshot: ChannelHealthSnapshot, |
132 | 134 | evaluation: ChannelHealthEvaluation, |
133 | 135 | ): ChannelRestartReason { |
| 136 | +// Restart reasons are intentionally coarse: downstream logs/UI need stable |
| 137 | +// categories, while detailed channel state stays in the health snapshot. |
134 | 138 | if (evaluation.reason === "stale-socket") { |
135 | 139 | return "stale-socket"; |
136 | 140 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway chat display sanitizer. |
| 2 | +// Removes OpenClaw-only envelopes before messages are shown in UI/RPC results. |
1 | 3 | import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce"; |
2 | 4 | import { |
3 | 5 | stripInternalMetadataForDisplay, |
@@ -12,6 +14,8 @@ import { stripEnvelope } from "../shared/chat-envelope.js";
|
12 | 14 | export { stripEnvelope }; |
13 | 15 | |
14 | 16 | function extractMessageSenderLabel(entry: Record<string, unknown>): string | null { |
| 17 | +// Sender labels can be explicit fields or embedded in text/envelope content. |
| 18 | +// Preserve the first label found so user-origin rows keep human context. |
15 | 19 | if (typeof entry.senderLabel === "string" && entry.senderLabel.trim()) { |
16 | 20 | return entry.senderLabel.trim(); |
17 | 21 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Server-side gateway client readiness adapter. |
| 2 | +// Defers client start until the shared event-loop readiness probe succeeds. |
1 | 3 | import type { |
2 | 4 | GatewayClientStartable, |
3 | 5 | GatewayClientStartReadinessOptions, |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway method authorization scope resolver. |
| 2 | +// Maps static and plugin-defined gateway methods to operator scopes. |
1 | 3 | import { normalizeOptionalString as normalizeSessionActionParam } from "@openclaw/normalization-core/string-coerce"; |
2 | 4 | import { getPluginRegistryState } from "../plugins/runtime-state.js"; |
3 | 5 | import { resolveReservedGatewayMethodScope } from "../shared/gateway-method-policy.js"; |
@@ -107,6 +109,8 @@ function resolveSessionActionRegisteredScopes(params: unknown): OperatorScope[]
|
107 | 109 | return undefined; |
108 | 110 | } |
109 | 111 | const requiredScopes = registration.action.requiredScopes; |
| 112 | +// Registered session actions default to write scope when they omit a custom |
| 113 | +// requirement; this preserves the historical mutation boundary. |
110 | 114 | return requiredScopes && requiredScopes.length > 0 ? [...requiredScopes] : [WRITE_SCOPE]; |
111 | 115 | } |
112 | 116 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Plugin/channel activation config merge helpers. |
| 2 | +// Carries activation enablement into runtime config without copying stale state. |
1 | 3 | import type { OpenClawConfig } from "../config/types.openclaw.js"; |
2 | 4 | import { isRecord } from "../utils.js"; |
3 | 5 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway restart timing trace helpers. |
| 2 | +// Emits opt-in restart handoff diagnostics with bounded metric formatting. |
1 | 3 | import { performance } from "node:perf_hooks"; |
2 | 4 | import { isTruthyEnvValue } from "../infra/env.js"; |
3 | 5 | import { createSubsystemLogger } from "../logging/subsystem.js"; |
@@ -41,6 +43,8 @@ function normalizeMetricEntries(
|
41 | 43 | } |
42 | 44 | |
43 | 45 | function formatMetricKey(key: string): string { |
| 46 | +// Metric keys are log tokens, not structured JSON. Keep them compact and |
| 47 | +// shell-friendly so trace lines remain grepable. |
44 | 48 | const normalized = key.replace(/[^A-Za-z0-9]/gu, ""); |
45 | 49 | if (!normalized) { |
46 | 50 | return "metric"; |
@@ -261,6 +265,8 @@ function countActiveTimersFromHandles(activeHandles: readonly unknown[]): number
|
261 | 265 | } |
262 | 266 | |
263 | 267 | function normalizeRestartTraceHandoff(value: unknown): GatewayRestartTraceHandoff | null { |
| 268 | +// Handoff values come from another process. Reject stale/future values so a |
| 269 | +// reused shell environment cannot poison later restart measurements. |
264 | 270 | if (typeof value !== "object" || value === null || Array.isArray(value)) { |
265 | 271 | return null; |
266 | 272 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。