docs: document gateway session utilities · openclaw/openclaw@fba99cd
steipete
·
2026-06-05
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway run-id to session-key resolver. |
| 2 | +// Bridges live agent run context with persisted session stores. |
1 | 3 | import { |
2 | 4 | asDateTimestampMs, |
3 | 5 | resolveExpiresAtMsFromDurationMs, |
@@ -53,6 +55,8 @@ function setResolvedSessionKeyCache(
|
53 | 55 | } |
54 | 56 | let expiresAt: number | null = null; |
55 | 57 | if (sessionKey === null) { |
| 58 | +// Negative caching avoids repeated full-store scans while still allowing |
| 59 | +// a just-created run/session pair to appear shortly after the first lookup. |
56 | 60 | const missExpiresAt = resolveExpiresAtMsFromDurationMs(RUN_LOOKUP_MISS_TTL_MS); |
57 | 61 | if (missExpiresAt === undefined) { |
58 | 62 | return; |
@@ -122,6 +126,8 @@ export function resolveSessionKeyForRun(runId: string, opts: { agentId?: string
|
122 | 126 | ); |
123 | 127 | const storeKey = resolvePreferredSessionKeyForSessionIdMatches(matches, runId); |
124 | 128 | if (storeKey) { |
| 129 | +// Return caller-facing agent request keys, not raw store keys, because |
| 130 | +// HTTP/RPC clients reuse this value in later session operations. |
125 | 131 | const sessionKey = resolveRunSessionKeyForCaller(storeKey); |
126 | 132 | setResolvedSessionKeyCache(runId, cacheAgentId, sessionKey); |
127 | 133 | return sessionKey; |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway startup logging helpers. |
| 2 | +// Produces the compact ready banner with resolved model and safety state. |
1 | 3 | import { normalizeSortedUniqueStringEntries } from "@openclaw/normalization-core/string-normalization"; |
2 | 4 | import chalk from "chalk"; |
3 | 5 | import { resolveDefaultAgentId, resolveAgentConfig } from "../agents/agent-scope.js"; |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway startup session-store migration runner. |
| 2 | +// Keeps old orphaned session keys from surviving process upgrades. |
1 | 3 | import type { OpenClawConfig } from "../config/types.openclaw.js"; |
2 | 4 | import { migrateOrphanedSessionKeys } from "../infra/state-migrations.js"; |
3 | 5 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Session patch hook dispatcher. |
| 2 | +// Publishes internal mutation notifications after Gateway session patch calls. |
1 | 3 | import type { SessionsPatchParams } from "../../packages/gateway-protocol/src/index.js"; |
2 | 4 | import type { SessionEntry } from "../config/sessions.js"; |
3 | 5 | import type { OpenClawConfig } from "../config/types.openclaw.js"; |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway session reset/delete service. |
| 2 | +// Rotates transcripts and coordinates lifecycle cleanup across runtimes/hooks. |
1 | 3 | import { randomUUID } from "node:crypto"; |
2 | 4 | import fs from "node:fs"; |
3 | 5 | import path from "node:path"; |
@@ -80,6 +82,8 @@ function resolveResetSessionFile(params: {
|
80 | 82 | agentId: string; |
81 | 83 | }): string { |
82 | 84 | const currentEntry = params.currentEntry; |
| 85 | +// Preserve explicit session-file placement across reset while swapping the |
| 86 | +// embedded session id, so linked runtimes keep writing beside old transcripts. |
83 | 87 | const rewrittenSessionFile = currentEntry?.sessionId |
84 | 88 | ? rewriteSessionFileForNewSessionId({ |
85 | 89 | sessionFile: currentEntry.sessionFile, |
@@ -108,6 +112,8 @@ function stripRuntimeModelState(entry?: SessionEntry): SessionEntry | undefined
|
108 | 112 | } |
109 | 113 | return { |
110 | 114 | ...entry, |
| 115 | +// Reset should keep user selection preferences but drop per-run resolved |
| 116 | +// model state so the next turn rehydrates from current config. |
111 | 117 | model: undefined, |
112 | 118 | modelProvider: undefined, |
113 | 119 | contextTokens: undefined, |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Subagent session reactivation helper. |
| 2 | +// Replaces completed subagent run records when a user steers the child session. |
1 | 3 | import { getLatestSubagentRunByChildSessionKey } from "../agents/subagent-registry-read.js"; |
2 | 4 | |
3 | 5 | // Completed subagent sessions can be reactivated after a user steer by replacing |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Gateway session listing and projection helpers. |
| 2 | +// Normalizes persisted session stores into UI/RPC rows without mutating state. |
1 | 3 | import fs from "node:fs"; |
2 | 4 | import path from "node:path"; |
3 | 5 | import { |
@@ -173,6 +175,8 @@ function resolveIdentityAvatarUrl(
|
173 | 175 | return undefined; |
174 | 176 | } |
175 | 177 | try { |
| 178 | +// Avatars can be workspace-relative, but projection must keep the file |
| 179 | +// read inside the agent workspace and cap bytes before encoding. |
176 | 180 | const opened = openRootFileSync({ |
177 | 181 | absolutePath: resolvedCandidate, |
178 | 182 | rootPath: workspaceRoot, |
@@ -421,6 +425,8 @@ function shouldKeepStoreOnlyChildLink(entry: SessionEntry, now: number): boolean
|
421 | 425 | if (entry.status === "running" || isFinitePositiveTimestamp(entry.startedAt)) { |
422 | 426 | return true; |
423 | 427 | } |
| 428 | +// Store-only child links lack a live subagent registry entry. Keep recent |
| 429 | +// unknown-state rows visible briefly so reloads do not hide fresh children. |
424 | 430 | return ( |
425 | 431 | isFinitePositiveTimestamp(entry.updatedAt) && |
426 | 432 | now - entry.updatedAt <= STALE_STORE_ONLY_CHILD_LINK_MS |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Shared Gateway session projection types. |
| 2 | +// Keeps server methods and Control UI payloads aligned. |
1 | 3 | import type { ChatType } from "../channels/chat-type.js"; |
2 | 4 | import type { |
3 | 5 | SessionCompactionCheckpoint, |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Ordered Gateway startup task runner. |
| 2 | +// Used for best-effort side effects that should not abort the server. |
1 | 3 | import { formatErrorMessage } from "../infra/errors.js"; |
2 | 4 | |
3 | 5 | // Startup tasks run sequentially so logs and side effects stay ordered during |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。