




























@@ -10,6 +10,7 @@ import {
1010} from "../../../packages/gateway-protocol/src/client-info.js";
1111import type { OpenClawConfig } from "../../config/types.openclaw.js";
1212import { callGateway } from "../../gateway/call.js";
13+import { GatewayClientRequestError } from "../../gateway/client.js";
1314import { formatErrorMessage } from "../../infra/errors.js";
1415import {
1516listSpawnedSessionKeys,
@@ -233,24 +234,53 @@ function buildSessionIdResolveParams(params: {
233234sessionId: string;
234235requesterInternalKey?: string;
235236restrictToSpawned: boolean;
237+allowMissing?: boolean;
236238}) {
237239return {
238240sessionId: params.sessionId,
239241spawnedBy: params.restrictToSpawned ? params.requesterInternalKey : undefined,
240242includeGlobal: !params.restrictToSpawned,
241243includeUnknown: !params.restrictToSpawned,
244+ ...(params.allowMissing ? { allowMissing: true } : {}),
242245};
243246}
244247248+async function callGatewayResolveSession(
249+params: Record<string, unknown> & { allowMissing?: boolean },
250+) {
251+try {
252+return await sessionsResolutionDeps.callGateway({
253+method: "sessions.resolve",
254+ params,
255+});
256+} catch (error) {
257+const olderGatewayRejectedProbe =
258+params.allowMissing === true &&
259+error instanceof GatewayClientRequestError &&
260+error.gatewayCode === "INVALID_REQUEST" &&
261+error.message.includes("invalid sessions.resolve params") &&
262+error.message.includes("unexpected property 'allowMissing'");
263+if (!olderGatewayRejectedProbe) {
264+throw error;
265+}
266+// Protocol v4 gateways predating allowMissing reject the additive field.
267+// Retry without it for mixed-version correctness; remove at the next protocol break.
268+const legacyParams: Record<string, unknown> = { ...params };
269+delete legacyParams.allowMissing;
270+return await sessionsResolutionDeps.callGateway({
271+method: "sessions.resolve",
272+params: legacyParams,
273+});
274+}
275+}
276+245277async function callGatewayResolveSessionId(params: {
246278sessionId: string;
247279requesterInternalKey?: string;
248280restrictToSpawned: boolean;
281+allowMissing?: boolean;
249282}): Promise<string> {
250-const result = await sessionsResolutionDeps.callGateway({
251-method: "sessions.resolve",
252-params: buildSessionIdResolveParams(params),
253-});
283+const result = await callGatewayResolveSession(buildSessionIdResolveParams(params));
254284const key = normalizeOptionalString(result?.key) ?? "";
255285if (!key) {
256286throw new Error(
@@ -266,6 +296,7 @@ async function resolveSessionKeyFromSessionId(params: {
266296mainKey: string;
267297requesterInternalKey?: string;
268298restrictToSpawned: boolean;
299+allowMissing?: boolean;
269300}): Promise<SessionReferenceResolution> {
270301try {
271302// Resolve via gateway so we respect store routing and visibility rules.
@@ -301,15 +332,14 @@ async function resolveSessionKeyFromKey(params: {
301332mainKey: string;
302333requesterInternalKey?: string;
303334restrictToSpawned: boolean;
335+allowMissing?: boolean;
304336}): Promise<SessionReferenceResolution | null> {
305337try {
306338// Try key-based resolution first so non-standard keys keep working.
307-const result = await sessionsResolutionDeps.callGateway({
308-method: "sessions.resolve",
309-params: {
310-key: params.key,
311-spawnedBy: params.restrictToSpawned ? params.requesterInternalKey : undefined,
312-},
339+const result = await callGatewayResolveSession({
340+key: params.key,
341+spawnedBy: params.restrictToSpawned ? params.requesterInternalKey : undefined,
342+ ...(params.allowMissing ? { allowMissing: true } : {}),
313343});
314344const key = normalizeOptionalString(result?.key) ?? "";
315345if (!key) {
@@ -332,6 +362,7 @@ async function tryResolveSessionKeyFromSessionId(params: {
332362mainKey: string;
333363requesterInternalKey?: string;
334364restrictToSpawned: boolean;
365+allowMissing?: boolean;
335366}): Promise<Extract<SessionReferenceResolution, { ok: true }> | null> {
336367try {
337368const key = await callGatewayResolveSessionId(params);
@@ -353,6 +384,7 @@ async function resolveSessionReferenceByKeyOrSessionId(params: {
353384requesterInternalKey?: string;
354385restrictToSpawned: boolean;
355386allowUnresolvedSessionId: boolean;
387+allowMissing?: boolean;
356388skipKeyLookup?: boolean;
357389forceSessionIdLookup?: boolean;
358390}): Promise<SessionReferenceResolution | null> {
@@ -364,6 +396,7 @@ async function resolveSessionReferenceByKeyOrSessionId(params: {
364396mainKey: params.mainKey,
365397requesterInternalKey: params.requesterInternalKey,
366398restrictToSpawned: params.restrictToSpawned,
399+allowMissing: params.allowMissing,
367400});
368401if (resolvedByKey) {
369402return resolvedByKey;
@@ -379,6 +412,7 @@ async function resolveSessionReferenceByKeyOrSessionId(params: {
379412mainKey: params.mainKey,
380413requesterInternalKey: params.requesterInternalKey,
381414restrictToSpawned: params.restrictToSpawned,
415+allowMissing: params.allowMissing,
382416});
383417}
384418return await resolveSessionKeyFromSessionId({
@@ -387,6 +421,7 @@ async function resolveSessionReferenceByKeyOrSessionId(params: {
387421mainKey: params.mainKey,
388422requesterInternalKey: params.requesterInternalKey,
389423restrictToSpawned: params.restrictToSpawned,
424+allowMissing: params.allowMissing,
390425});
391426}
392427@@ -410,6 +445,7 @@ export async function resolveSessionReference(params: {
410445requesterInternalKey: params.requesterInternalKey,
411446restrictToSpawned: params.restrictToSpawned,
412447allowUnresolvedSessionId: true,
448+allowMissing: true,
413449skipKeyLookup: params.restrictToSpawned,
414450forceSessionIdLookup: true,
415451});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。