Skip to content

Commit 1dcac5b

Browse files
authored
fix: open terminals no longer delay gateway updates (#121601)
* fix(gateway): allow updates with open terminals * fix(updater): support terminal policy upgrades * chore(plugin-sdk): refresh API baseline
1 parent b45ddf2 commit 1dcac5b

34 files changed

Lines changed: 506 additions & 53 deletions

‎.agents/skills/openclaw-live-updater/scripts/update-main.mjs‎

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,47 @@ function gatewayCliOperation(args) {
262262
return "gateway.cli";
263263
}
264264

265+
function isLegacyGatewaySuspendPrepareParamsError(error) {
266+
if (
267+
!(error instanceof UpdateCommandError) ||
268+
error.operation !== "gateway.suspend.prepare" ||
269+
error.status !== 1
270+
) {
271+
return false;
272+
}
273+
const cause = ownDataProperty(error, "cause");
274+
const stdout = ownDataProperty(cause, "stdout");
275+
if (typeof stdout !== "string" || !stdout.trim()) {
276+
return false;
277+
}
278+
let payload;
279+
try {
280+
payload = JSON.parse(stdout.trim());
281+
} catch {
282+
return false;
283+
}
284+
if (
285+
typeof payload !== "object" ||
286+
payload === null ||
287+
Array.isArray(payload) ||
288+
Object.keys(payload).length !== 2 ||
289+
payload.ok !== false
290+
) {
291+
return false;
292+
}
293+
const requestError = payload.error;
294+
return (
295+
typeof requestError === "object" &&
296+
requestError !== null &&
297+
!Array.isArray(requestError) &&
298+
Object.keys(requestError).length === 4 &&
299+
requestError.type === "gateway_request_error" &&
300+
requestError.code === "INVALID_REQUEST" &&
301+
requestError.message === "invalid gateway.suspend.prepare params" &&
302+
requestError.retryable === false
303+
);
304+
}
305+
265306
async function runUpdateCommand(runCommand, operation, command, args, checkout, options) {
266307
try {
267308
return await runCommand(command, args, checkout, options);
@@ -1845,20 +1886,29 @@ export function runBuiltGatewayCall(checkout, method, params, deployment) {
18451886

18461887
/**
18471888
* @param {string} checkout
1848-
* @param {(checkout: string, method: string, params: { requestId: string }, deployment: GatewayDeploymentRef | null) => string} [callGateway]
1849-
* @param {GatewayDeploymentRef | null} [deployment]
1889+
* @param {(checkout: string, method: string, params: { requestId: string, terminalPolicy?: "terminate" }, deployment: GatewayCliDeployment | null) => string} [callGateway]
1890+
* @param {GatewayCliDeployment | null} [deployment]
18501891
*/
18511892
export function prepareGatewaySuspension(
18521893
checkout,
18531894
callGateway = runBuiltGatewayCall,
18541895
deployment = null,
18551896
) {
18561897
const requestId = `openclaw-live-updater-${randomUUID()}`;
1898+
const callPrepare = (params) =>
1899+
JSON.parse(callGateway(checkout, "gateway.suspend.prepare", params, deployment));
18571900
let result;
18581901
try {
1859-
result = JSON.parse(
1860-
callGateway(checkout, "gateway.suspend.prepare", { requestId }, deployment),
1861-
);
1902+
try {
1903+
result = callPrepare({ requestId, terminalPolicy: "terminate" });
1904+
} catch (error) {
1905+
if (!isLegacyGatewaySuspendPrepareParamsError(error)) {
1906+
throw error;
1907+
}
1908+
// Older closed schemas reject the new field before acquiring a lease.
1909+
// Retry once with preserve semantics so mixed-version updates remain safe.
1910+
result = callPrepare({ requestId });
1911+
}
18621912
} catch (error) {
18631913
throw new UpdateInvariantError(
18641914
"gateway_suspend_prepare_failed",
@@ -2747,7 +2797,7 @@ function defaultSleep(ms) {
27472797
}
27482798

27492799
/**
2750-
* @param {(command: string, args: string[], checkout: string, options?: Record<string, unknown>) => unknown | Promise<unknown>} runCommand
2800+
* @param {(command: string, args: string[], checkout: string, options?: Record<string, unknown>) => void | Promise<void>} runCommand
27512801
* @param {string} checkout
27522802
* @param {string} expectedSha
27532803
* @param {(ms: number) => void | Promise<void>} [sleep]
@@ -2786,7 +2836,7 @@ export async function verifyGatewayReadiness(
27862836
for (let attempt = 1; attempt <= GATEWAY_READINESS_ATTEMPTS; attempt += 1) {
27872837
try {
27882838
if (deployment) {
2789-
markGatewayMilestones(timing, await probeMilestones(deployment), timestampAt(now));
2839+
markGatewayMilestones(timing, probeMilestones(deployment), timestampAt(now));
27902840
}
27912841
const deepRpcReadyAt = await verifyGatewayDeepRpc(
27922842
runCommand,
@@ -2799,7 +2849,7 @@ export async function verifyGatewayReadiness(
27992849
if (deployment) {
28002850
markGatewayMilestones(
28012851
timing,
2802-
await probeMilestones(deployment),
2852+
probeMilestones(deployment),
28032853
timestampAt(now),
28042854
deepRpcReadyAt,
28052855
);

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1645,15 +1645,19 @@ public struct GatewaySuspendBlocker: Codable, Sendable {
16451645

16461646
public struct GatewaySuspendPrepareParams: Codable, Sendable {
16471647
public let requestid: String
1648+
public let terminalpolicy: AnyCodable?
16481649

16491650
public init(
1650-
requestid: String)
1651+
requestid: String,
1652+
terminalpolicy: AnyCodable? = nil)
16511653
{
16521654
self.requestid = requestid
1655+
self.terminalpolicy = terminalpolicy
16531656
}
16541657

16551658
private enum CodingKeys: String, CodingKey {
16561659
case requestid = "requestId"
1660+
case terminalpolicy = "terminalPolicy"
16571661
}
16581662
}
16591663

‎docs/.generated/plugin-sdk-api-baseline/agent-harness-runtime.json‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/.generated/plugin-sdk-api-baseline/agent-harness.json‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/.generated/plugin-sdk-api-baseline/channel-core.json‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/.generated/plugin-sdk-api-baseline/channel-entry-contract.json‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/.generated/plugin-sdk-api-baseline/channel-message.json‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/.generated/plugin-sdk-api-baseline/channel-outbound.json‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/.generated/plugin-sdk-api-baseline/channel-plugin-common.json‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/.generated/plugin-sdk-api-baseline/core.json‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)